Exchange exchange,
Map<String, Object> invContext) {
//CHECKSTYLE:ON
Bus configuredBus = getConfiguration().getBus();
Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
ClassLoaderHolder origLoader = null;
try {
ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
URI uri = getCurrentURI();
Message m = createMessage(body, httpMethod, headers, uri, exchange,
invContext, false);
Map<String, Object> reqContext = getRequestContext(m);
reqContext.put(Message.HTTP_REQUEST_METHOD, httpMethod);
reqContext.put(REQUEST_CLASS, requestClass);
reqContext.put(REQUEST_TYPE, inGenericType);
reqContext.put(RESPONSE_CLASS, responseClass);
reqContext.put(RESPONSE_TYPE, outGenericType);
if (body != null) {
m.getInterceptorChain().add(new BodyWriter());
}
setPlainOperationNameProperty(m, httpMethod + ":" + uri.toString());
try {
m.getInterceptorChain().doIntercept(m);
} catch (Exception ex) {
m.setContent(Exception.class, ex);
}
try {
Object[] results = preProcessResult(m);
if (results != null && results.length == 1) {
// this can happen if a connection exception has occurred and
// failover feature used this client to invoke on a different address
return (Response)results[0];
}
} catch (Exception ex) {
throw ex instanceof ServerWebApplicationException
? (ServerWebApplicationException)ex
: ex instanceof ClientWebApplicationException
? new ClientWebApplicationException(ex) : new RuntimeException(ex);
}
Response response = null;
Object entity = null;
try {
response = handleResponse(m, responseClass, outGenericType);
entity = response.getEntity();
return response;
} catch (RuntimeException ex) {
entity = ex;
throw ex;
} finally {
completeExchange(entity, m.getExchange(), false);
}
} finally {
if (origLoader != null) {
origLoader.reset();
}
if (origBus != configuredBus) {
BusFactory.setThreadDefaultBus(origBus);
}
}