1
votes

If I add a custom error-handler to an int-http:outbound-gateway, the response body is not unmarshalled according to the expected-response-type, instead I only get a ResponseEntity returned. My custom error handler is pretty simple:

public class MyResponseErrorHandler extends DefaultResponseErrorHandler {

private static final Logger log = LoggerFactory.getLogger(AlmaGetUserResponseErrorHandler.class);

@Override
public boolean hasError(final ClientHttpResponse response) throws IOException {
    // stop http 400 from returning true to error here.
    log.debug("Request has returned error code {}", response.getStatusCode());
    if (response.getBody() != null) {
        String returnBody = IOUtils.toString(response.getBody(), "UTF-8");
        log.debug("Checking error from response, code {}, body {}", response.getStatusCode(), returnBody);
    }

    return false;
}

}

As soon as I remove the error-handler, it unmarshalls the XML response into my POJO correctly.

1
Sorry, my fault. I was streaming the body result out of the response for debug and hence the body was null.Phil Smart
Well, that's great you have found the solution yourself. So, feel free to delete the question or form the proper answer to gain some reputationArtem Bilan

1 Answers

1
votes

The issue above was that the MyResponseErrorHandler class was streaming out the body content before it was being passed to the marshaller for expected-response-type. Hence the body was null and a plain ResponseEntity was returned.