ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
try {
if (loader != null) {
Thread.currentThread().setContextClassLoader(loader);
}
InterceptorChain phaseChain = null;
if (m.getInterceptorChain() != null) {
phaseChain = m.getInterceptorChain();
// To make sure the phase chain is run by one thread once
synchronized (phaseChain) {
if (phaseChain.getState() == InterceptorChain.State.PAUSED
|| phaseChain.getState() == InterceptorChain.State.SUSPENDED) {
phaseChain.resume();
return;
}
}
}
Message message = getBinding().createMessage(m);
Exchange exchange = message.getExchange();
if (exchange == null) {
exchange = new ExchangeImpl();
m.setExchange(exchange);
}
exchange.setInMessage(message);
setExchangeProperties(exchange, message);
InterceptorProvider dbp = null;
if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) {
dbp = (InterceptorProvider)endpoint.getService().getDataBinding();
}
// setup chain
if (dbp == null) {
phaseChain = chainCache.get(bus.getExtension(PhaseManager.class).getInPhases(),
bus.getInInterceptors(),
endpoint.getService().getInInterceptors(),
endpoint.getInInterceptors(),
getBinding().getInInterceptors());
} else {
phaseChain = chainCache.get(bus.getExtension(PhaseManager.class).getInPhases(),
bus.getInInterceptors(),
endpoint.getService().getInInterceptors(),
endpoint.getInInterceptors(),
getBinding().getInInterceptors(),
dbp.getInInterceptors());
}
message.setInterceptorChain(phaseChain);
phaseChain.setFaultObserver(endpoint.getOutFaultObserver());
addToChain(phaseChain, message);
phaseChain.doIntercept(message);
} finally {
BusFactory.setThreadDefaultBus(origBus);
Thread.currentThread().setContextClassLoader(origLoader);
}