Search in sources :

Example 1 with Error

use of org.apache.camel.component.linkedin.api.model.Error in project camel by apache.

the class LinkedInExceptionResponseFilter method filter.

@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);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) JAXBException(javax.xml.bind.JAXBException) Error(org.apache.camel.component.linkedin.api.model.Error) List(java.util.List) Unmarshaller(javax.xml.bind.Unmarshaller) Map(java.util.Map)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Error (org.apache.camel.component.linkedin.api.model.Error)1