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();
}
};
}
Aggregations