@Test public void addingInboundAttachmentsRespectOrder() { InternalMessage message = InternalMessage.builder() .payload(TypedValue.of("test")) .mediaType(TEXT) .addInboundAttachment("another", new DataHandler(new ByteArrayDataSource("no".getBytes(), TEXT, "another"))) .addInboundAttachment("field1", new DataHandler(new ByteArrayDataSource("yes".getBytes(), TEXT, "field1"))) .exceptionPayload(new DefaultExceptionPayload(new NullPointerException("error"))) .build(); validateAttachments(message.getInboundAttachmentNames()); }
@Test public void addingOutboundAttachmentsRespectOrder() { InternalMessage message = InternalMessage.builder() .payload(TypedValue.of("test")) .mediaType(TEXT) .addOutboundAttachment("another", new DataHandler(new ByteArrayDataSource("no".getBytes(), TEXT, "another"))) .addOutboundAttachment("field1", new DataHandler(new ByteArrayDataSource("yes".getBytes(), TEXT, "field1"))) .exceptionPayload(new DefaultExceptionPayload(new NullPointerException("error"))) .build(); validateAttachments(message.getOutboundAttachmentNames()); }
@Override public void run() { try { Exception exception = new Exception(); event = PrivilegedEvent.builder(event) .message(InternalMessage.builder(event.getMessage()).exceptionPayload(new DefaultExceptionPayload(exception)).build()) .error(createErrorMock(exception)).build(); setCurrentEvent(event); success.set(true); } catch (RuntimeException e) { LOGGER.error("error in thread", e); } } }
@Test public void compatibilityToString() { Message message = InternalMessage.builder() .payload(TypedValue.of("test")) .attributes(new TypedValue<>("{}", JSON_STRING)) .mediaType(TEXT) .addInboundProperty("bar", "in") .addOutboundProperty(FOO_PROPERTY, "out") .exceptionPayload(new DefaultExceptionPayload(new NullPointerException("error"))) .build(); assertThat(message.toString(), is(equalToIgnoringLineBreaks("\n" + "org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation\n" + "{\n" + " payload=test\n" + " mediaType=text/plain\n" + " attributes={}\n" + " attributesMediaType=application/json\n" + " exceptionPayload:\n" + " message=error\n" + " exception=java.lang.NullPointerException: error\n" + " Message properties:\n" + " INBOUND scoped properties:\n" + " bar=in\n" + " OUTBOUND scoped properties:\n" + " foo=out\n" + "}"))); }
@Test public void inboundAttachmentsRespectOrder() { InternalMessage message = InternalMessage.builder() .payload(TypedValue.of("test")) .mediaType(TEXT) .inboundAttachments(getAttachments()) .exceptionPayload(new DefaultExceptionPayload(new NullPointerException("error"))) .build(); validateAttachments(message.getInboundAttachmentNames()); }
@Test public void outboundAttachmentsRespectOrder() { InternalMessage message = InternalMessage.builder() .payload(TypedValue.of("test")) .mediaType(TEXT) .outboundAttachments(getAttachments()) .exceptionPayload(new DefaultExceptionPayload(new NullPointerException("error"))) .build(); validateAttachments(message.getOutboundAttachmentNames()); }
@Override public CoreEvent process(CoreEvent event) throws MuleException { try { Message msg; Error error = null; String payload = ((InternalEvent) event).getMessageAsString(muleContext); if (payload.indexOf(rejectIfMatches) >= 0) { throw new DefaultMuleException("Saw " + rejectIfMatches); } else if (payload.toLowerCase().indexOf(rejectIfMatches) >= 0) { Exception exception = new Exception(); error = createErrorMock(exception); msg = InternalMessage.builder().nullValue().exceptionPayload(new DefaultExceptionPayload(exception)).build(); } else { msg = of("No " + rejectIfMatches); } CoreEvent muleEvent = eventBuilder(muleContext).message(msg).error(error).build(); return muleEvent; } catch (Exception e) { throw new DefaultMuleException(e); } } }
protected Function<CoreEvent, Publisher<CoreEvent>> route(Exception exception) { return event -> { if (getMessageProcessors().isEmpty()) { return just(event); } else { event = CoreEvent.builder(event) .message(InternalMessage.builder(event.getMessage()).exceptionPayload(new DefaultExceptionPayload(exception)).build()) .build(); } return from(processWithChildContext(event, configuredMessageProcessors, ofNullable(getLocation()), NullExceptionHandler.getInstance())); }; }
private CoreEvent addExceptionPayload(Exception exception, CoreEvent event) { return CoreEvent.builder(event) .message(InternalMessage.builder(event.getMessage()).exceptionPayload(new DefaultExceptionPayload(exception)).build()) .build(); }
@Override public void run() { try { Exception exception = new Exception(); event = PrivilegedEvent.builder(event) .message(InternalMessage.builder(event.getMessage()).exceptionPayload(new DefaultExceptionPayload(exception)).build()) .error(createErrorMock(exception)).build(); setCurrentEvent(event); success.set(true); } catch (RuntimeException e) { LOGGER.error("error in thread", e); } } }
@Override public void handleException(Exception ex, RollbackSourceCallback rollbackMethod) { fireNotification(ex, getCurrentEvent()); resolveAndLogException(ex); logger.debug("Rolling back transaction"); rollback(ex, rollbackMethod); ExceptionPayload exceptionPayload = new DefaultExceptionPayload(ex); if (getCurrentEvent() != null) { PrivilegedEvent currentEvent = getCurrentEvent(); currentEvent = PrivilegedEvent.builder(currentEvent) .message(InternalMessage.builder(currentEvent.getMessage()).exceptionPayload(exceptionPayload).build()).build(); setCurrentEvent(currentEvent); } if (ex instanceof ConnectException) { ((ConnectException) ex).handleReconnection(retryScheduler); } }
@Override public CoreEvent process(CoreEvent event) throws MuleException { try { Message msg; Error error = null; String payload = ((InternalEvent) event).getMessageAsString(muleContext); if (payload.indexOf(rejectIfMatches) >= 0) { throw new DefaultMuleException("Saw " + rejectIfMatches); } else if (payload.toLowerCase().indexOf(rejectIfMatches) >= 0) { Exception exception = new Exception(); error = createErrorMock(exception); msg = InternalMessage.builder().nullValue().exceptionPayload(new DefaultExceptionPayload(exception)).build(); } else { msg = of("No " + rejectIfMatches); } CoreEvent muleEvent = eventBuilder(muleContext).message(msg).error(error).build(); return muleEvent; } catch (Exception e) { throw new DefaultMuleException(e); } } }