@Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { if (responseContext.getStatus() != Response.Status.OK.getStatusCode() && responseContext.hasEntity()) { try { final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); final Error error = (Error) unmarshaller.unmarshal(responseContext.getEntityStream()); final Response.ResponseBuilder builder = Response.status(responseContext.getStatusInfo()); builder.entity(error); // copy response headers for (Map.Entry<String, List<String>> header : responseContext.getHeaders().entrySet()) { builder.header(header.getKey(), header.getValue()); } throw new LinkedInException(error, builder.build()); } catch (JAXBException e) { // log and ignore LOG.warn("Unable to parse LinkedIn error: {}", e.getMessage(), e); } } } }
@Override protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException { try { return super.doInvokeMethod(method, properties); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { final WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }
@Override protected Object doInvokeMethod(Map<String, Object> args) { try { return super.doInvokeMethod(args); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }
@Override protected Object doInvokeMethod(Map<String, Object> args) { try { return super.doInvokeMethod(args); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }
@Override protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException { try { return super.doInvokeMethod(method, properties); } catch (RuntimeCamelException e) { if (e.getCause() instanceof WebApplicationException) { final WebApplicationException cause = (WebApplicationException) e.getCause(); final Response response = cause.getResponse(); if (response.hasEntity()) { // try and convert it to LinkedInException final org.apache.camel.component.linkedin.api.model.Error error = response.readEntity(Error.class); throw new RuntimeCamelException( String.format("Error invoking %s: %s", method.getName(), error.getMessage()), new LinkedInException(error, response)); } } throw e; } } }