Search in sources :

Example 1 with AbstractTransformer

use of org.springframework.integration.transformer.AbstractTransformer 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

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 AbstractTransformer (org.springframework.integration.transformer.AbstractTransformer)1 MessageTransformationException (org.springframework.integration.transformer.MessageTransformationException)1 Message (org.springframework.messaging.Message)1 MessagingException (org.springframework.messaging.MessagingException)1