Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to carry over header info to errorChannel?

In my application, my gateway is receiving request identifier in header, whenever error happens, error channel receives the exception. But it seems like, errorChannel don't take the headers from gateway.

Is it possible to carry over the header information to error channel as well?

Sample example: sysout in sampleErrorChannel does not has the header which i have passed.

https://github.com/manojp1988/spring-integration/blob/master/javadsl/src/main/java/ErrorChannel/ErrorChannelExample.java

like image 710
Manoj Avatar asked Aug 03 '15 02:08

Manoj


1 Answers

The message on the error channel is an ErrorMessage, it has a payload of MessagingException which has two properties, the cause (exception) and failedMessage.

You can access the failed message headers that way.

e.g. payload.failedMessage.headers['foo'] when using SpEL.

If using a POJO service activator on the error flow, you can use

public void failure(MessagingException failure) {
    MyHeader mh = failure.getFailedMessage().getHeader("mh");
}
like image 70
Gary Russell Avatar answered Sep 24 '22 15:09

Gary Russell