BindingOperationInfo oi,
Object[] params,
Map<String, Object> context,
Exchange exchange) throws Exception {
Bus origBus = BusFactory.getThreadDefaultBus(false);
ClassLoaderHolder origLoader = null;
try {
BusFactory.setThreadDefaultBus(bus);
ClassLoader loader = bus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
if (exchange == null) {
exchange = new ExchangeImpl();
}
exchange.setSynchronous(callback == null);
Endpoint endpoint = getEndpoint();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Invoke, operation info: " + oi + ", params: " + Arrays.toString(params));
}
Message message = endpoint.getBinding().createMessage();
// Make sure INVOCATION CONTEXT, REQUEST_CONTEXT and RESPONSE_CONTEXT are present
// on message
Map<String, Object> reqContext = null;
Map<String, Object> resContext = null;
if (context == null) {
context = new HashMap<String, Object>();
}
reqContext = CastUtils.cast((Map)context.get(REQUEST_CONTEXT));
resContext = CastUtils.cast((Map)context.get(RESPONSE_CONTEXT));
if (reqContext == null) {
reqContext = new HashMap<String, Object>(getRequestContext());
context.put(REQUEST_CONTEXT, reqContext);
}
if (resContext == null) {
resContext = new HashMap<String, Object>();
context.put(RESPONSE_CONTEXT, resContext);
}
message.put(Message.INVOCATION_CONTEXT, context);
setContext(reqContext, message);
if (null != reqContext) {
exchange.putAll(reqContext);
}
setParameters(params, message);
if (null != oi) {
exchange.setOneWay(oi.getOutput() == null);
}
exchange.setOutMessage(message);
exchange.put(ClientCallback.class, callback);
setOutMessageProperties(message, oi);
setExchangeProperties(exchange, endpoint, oi);
PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
message.setInterceptorChain(chain);
chain.setFaultObserver(outFaultObserver);
prepareConduitSelector(message);
// add additional interceptors and such
modifyChain(chain, message, false);
try {
chain.doIntercept(message);
} catch (Fault fault) {
enrichFault(fault);
throw fault;
}
if (callback != null) {
return null;
} else {
return processResult(message, exchange, oi, resContext);
}
} finally {
if (origLoader != null) {
origLoader.reset();
}
BusFactory.setThreadDefaultBus(origBus);
}
}