Search code examples
responsegatewayoutbound

how to get response body during 400 error in http oubound gateway


i have

gateway -> chain -> http:outbound-gateway -> transformer

for the gateway i have error-channel to handle 400 responses from outbound-gateway.

the payload I get in the error channel is the MessageHandlingException. It does not have a way retrieve the response body.

Is there a way i can get response body as payload instead of exception. Or is there a way if i can get hold of response body?

My 400 response has a body.


Solution

  • It isn't spelled out in the docs, but it is available. The MessageHandlingException has a nested exception of HttpClientErrorException. That has captured the response body among other bits of useful information. To extract the response body, call payload.getCause().getResponseBodyAsString()