use of org.springframework.integration.transformer.MessageTransformationException in project spring-integration by spring-projects.
the class HeaderEnricherTests method errorChannel.
@Test
public void errorChannel() {
PollableChannel errorChannel = context.getBean("testErrorChannel", PollableChannel.class);
MessageChannel inputChannel = context.getBean("errorChannelInput", MessageChannel.class);
inputChannel.send(new GenericMessage<String>("test"));
Message<?> errorMessage = errorChannel.receive(1000);
assertNotNull(errorMessage);
Object errorPayload = errorMessage.getPayload();
assertEquals(MessageTransformationException.class, errorPayload.getClass());
Message<?> failedMessage = ((MessageTransformationException) errorPayload).getFailedMessage();
assertEquals("test", failedMessage.getPayload());
assertEquals(errorChannel, failedMessage.getHeaders().getErrorChannel());
}
use of org.springframework.integration.transformer.MessageTransformationException in project spring-integration by spring-projects.
the class AbstractMailMessageTransformer method transform.
@Override
public Message<?> transform(Message<?> message) {
Object payload = message.getPayload();
if (!(payload instanceof javax.mail.Message)) {
throw new MessageTransformationException(message, this.getClass().getSimpleName() + " requires a javax.mail.Message payload");
}
javax.mail.Message mailMessage = (javax.mail.Message) payload;
AbstractIntegrationMessageBuilder<T> builder = null;
try {
builder = this.doTransform(mailMessage);
} catch (Exception e) {
throw new MessageTransformationException(message, "failed to transform mail message", e);
}
if (builder == null) {
throw new MessageTransformationException(message, "failed to transform mail message");
}
builder.copyHeaders(this.extractHeaderMapFromMailMessage(mailMessage));
return builder.build();
}
use of org.springframework.integration.transformer.MessageTransformationException in project faf-java-server by FAForever.
the class IntegrationConfig method requestExceptionTransformer.
/**
* Transformer that transforms a {@link MessageHandlingException} into and {@link ErrorResponse}.
*/
private AbstractTransformer requestExceptionTransformer() {
return new AbstractTransformer() {
@Override
protected Object doTransform(Message<?> message) throws Exception {
MessagingException messageException = (MessagingException) message.getPayload();
Message<?> failedMessage = messageException.getFailedMessage();
// TODO try to make more intuitive? Meanwhile, look at requestExceptionFilter() to understand.
RequestException requestException;
if (messageException instanceof MessageTransformationException) {
requestException = (RequestException) messageException.getCause().getCause();
} else {
requestException = (RequestException) messageException.getCause();
}
MessageBuilder<ErrorResponse> builder = MessageBuilder.withPayload(new ErrorResponse(requestException.getErrorCode(), requestException.getRequestId(), requestException.getArgs())).copyHeaders(message.getHeaders());
builder.setHeader(CLIENT_CONNECTION, failedMessage.getHeaders().get(CLIENT_CONNECTION, ClientConnection.class));
return builder.build();
}
};
}
Aggregations