Skip to content

Revise creation of ErrorMessage in the framework copying failed message headers #3984

Closed as not planned
@artembilan

Description

@artembilan

There is a patterns when we would like to produce an ErrorMessage and do something called compensation reply in the error handling sub-flow.
To fulfill request-reply pattern requirements, we have to have a replyChannel header to be able to reply correctly after error handling.
Right now this leads into some extra transformation step to carry out headers from the failed message of the handled ErrorMessage into our reply Message:


        @Transformer(inputChannel = "errorHandlerChannel")
        Message<String> errorHandler(Message<MessagingException> errorMessage) {
            return MessageBuilder.withPayload("Request failed for: " + errorMessage.getPayload().getFailedMessage().getPayload())
                    .copyHeaders(errorMessage.getPayload().getFailedMessage().getHeaders())
                    .build();
        }

See an example on StackOverflow: https://stackoverflow.com/questions/74658669/error-handling-issue-with-http-responseentity-using-expressionevaluatingrequesth

If we would copy failed (request) message headers into an ErrorMessage, we would not need extra message building code in that error handler to produce compensation reply correctly:

        @Transformer(inputChannel = "errorHandlerChannel")
        String errorHandler(MessagingException payload) {
            return "Request failed for: " + payload.getFailedMessage().getPayload();
        }

Metadata

Metadata

Assignees

Labels

status: declinedThere won't be a fix for some reason

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions