@SuppressWarnings("unchecked") @Override public void process(Exchange exchange) { Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); if (!(t instanceof HttpOperationFailedException)) return; HttpOperationFailedException httpException = (HttpOperationFailedException) t; String responseBody = httpException.getResponseBody(); Map<String, String> responseHeaders = httpException.getResponseHeaders(); exchange.getIn().setBody(responseBody); exchange.getIn().getHeaders().putAll(responseHeaders); exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpException.getStatusCode()); StringBuilder builder = new StringBuilder(); for (String key : responseHeaders.keySet()) { builder.append(key).append(":").append(responseHeaders.get(key)).append(","); } logger.debug("Received error response from endpoint: {}, body: {}, headers: {}", new String[]{(exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown"), responseBody, builder.toString()}); } }
@Override public void process(Exchange exchange) throws Exception { final HttpOperationFailedException exception = exchange.getProperty( Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class); if (null != exception && null != exception.getResponseHeaders().get( ExceptionMappingConstants.EXCEPTION_BODY_HEADER)) { final String body = exception.getResponseHeaders().get( ExceptionMappingConstants.EXCEPTION_BODY_HEADER); LOG.info("Catched error in route: " + body); final SAXBuilder sxb = new SAXBuilder(); final Document doc = sxb.build(new StringReader(body)); exchange.getIn().setBody( doc.getRootElement() .getChild(ExceptionMappingConstants.EXCEPTION_MESSAGE).getText()); } }
@Override public void process(Exchange exchange) throws Exception { final HttpOperationFailedException exception = exchange.getProperty( Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class); if (null != exception && null != exception.getResponseHeaders().get( ExceptionMappingConstants.EXCEPTION_BODY_HEADER)) { final String body = exception.getResponseHeaders().get( ExceptionMappingConstants.EXCEPTION_BODY_HEADER); LOG.info("Catched error in route: " + body); final SAXBuilder sxb = new SAXBuilder(); final Document doc = sxb.build(new StringReader(body)); exchange.getIn().setBody( doc.getRootElement() .getChild(ExceptionMappingConstants.EXCEPTION_MESSAGE).getText()); } }