Search in sources :

Example 1 with MessageTransformationException

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());
}
Also used : MessageTransformationException(org.springframework.integration.transformer.MessageTransformationException) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 2 with MessageTransformationException

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();
}
Also used : MessageTransformationException(org.springframework.integration.transformer.MessageTransformationException) Message(org.springframework.messaging.Message) MessageTransformationException(org.springframework.integration.transformer.MessageTransformationException)

Example 3 with MessageTransformationException

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();
        }
    };
}
Also used : AbstractTransformer(org.springframework.integration.transformer.AbstractTransformer) MessageTransformationException(org.springframework.integration.transformer.MessageTransformationException) IceMessage(com.faforever.server.ice.IceMessage) Message(org.springframework.messaging.Message) MessagingException(org.springframework.messaging.MessagingException) ClientConnection(com.faforever.server.client.ClientConnection) RequestException(com.faforever.server.error.RequestException) ErrorResponse(com.faforever.server.error.ErrorResponse)

Aggregations

MessageTransformationException (org.springframework.integration.transformer.MessageTransformationException)3 Message (org.springframework.messaging.Message)2 ClientConnection (com.faforever.server.client.ClientConnection)1 ErrorResponse (com.faforever.server.error.ErrorResponse)1 RequestException (com.faforever.server.error.RequestException)1 IceMessage (com.faforever.server.ice.IceMessage)1 Test (org.junit.Test)1 AbstractTransformer (org.springframework.integration.transformer.AbstractTransformer)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessagingException (org.springframework.messaging.MessagingException)1 PollableChannel (org.springframework.messaging.PollableChannel)1