How can I handle exceptions in an http outbound gateway? When i receive status code 500 or 400..., an exception is shown. So What should I do to handle http error using spr
If the response status code is in the HTTP series CLIENT_ERROR or SERVER_ERROR, HttpClientErrorException or HttpServerErrorException are thrown respectively. Hence the response doesn't go to reply channel
Refer DefaultResponseErrorHandler
Methods: hasError and handleError
To Handle these exceptions, create your own CustomResponseErrorHandler and override contents of hasError and handlerError methods.
public class CustomResponseErrorHandler extends DefaultResponseErrorHandler {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return hasError(getHttpStatusCode(response));
}
protected boolean hasError(HttpStatus statusCode) {
return /*Status Code to be considered as Error*/ ;
}
@Override
public void handleError(ClientHttpResponse response) throws IOException { /* Handle Exceptions */
}
}
And add error-handler to your http-outbound-gateway