use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class ChainInitiationObserver method onMessage.
public void onMessage(Message m) {
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(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 {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class MultipleEndpointObserver method onMessage.
public void onMessage(Message message) {
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Exchange exchange = message.getExchange();
if (exchange == null) {
exchange = new ExchangeImpl();
exchange.setInMessage(message);
message.setExchange(exchange);
}
message = createMessage(message);
message.setExchange(exchange);
exchange.setInMessage(message);
setExchangeProperties(exchange, message);
// setup chain
PhaseInterceptorChain chain = createChain();
message.setInterceptorChain(chain);
chain.add(bus.getInInterceptors());
if (bindingInterceptors != null) {
chain.add(bindingInterceptors);
}
if (routingInterceptors != null) {
chain.add(routingInterceptors);
}
if (endpoints != null) {
exchange.put(ENDPOINTS, endpoints);
}
chain.doIntercept(message);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class JAXRSServerFactoryBean method create.
/**
* Creates the JAX-RS Server instance
* @return the server
*/
public Server create() {
ClassLoaderHolder origLoader = null;
try {
Bus bus = getBus();
ClassLoader loader = bus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
serviceFactory.setBus(bus);
checkResources(true);
if (serviceFactory.getService() == null) {
serviceFactory.create();
}
Endpoint ep = createEndpoint();
getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE, server);
server = new ServerImpl(getBus(), ep, getDestinationFactory(), getBindingFactory());
Invoker invoker = serviceFactory.getInvoker();
if (invoker == null) {
ep.getService().setInvoker(createInvoker());
} else {
ep.getService().setInvoker(invoker);
}
ServerProviderFactory factory = setupFactory(ep);
ep.put(Application.class.getName(), appProvider);
factory.setRequestPreprocessor(new RequestPreprocessor(languageMappings, extensionMappings));
ep.put(Bus.class.getName(), getBus());
if (documentLocation != null) {
ep.put(JAXRSUtils.DOC_LOCATION, documentLocation);
}
if (rc != null) {
ep.put("org.apache.cxf.jaxrs.comparator", rc);
}
checkPrivateEndpoint(ep);
applyBusFeatures(getBus());
applyFeatures();
updateClassResourceProviders(ep);
injectContexts(factory);
factory.applyDynamicFeatures(getServiceFactory().getClassResourceInfo());
getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED, server, null, null);
if (start) {
try {
server.start();
} catch (RuntimeException re) {
// prevent resource leak
server.destroy();
throw re;
}
}
} catch (EndpointException e) {
throw new ServiceConstructionException(e);
} catch (BusException e) {
throw new ServiceConstructionException(e);
} catch (IOException e) {
throw new ServiceConstructionException(e);
} catch (Exception e) {
throw new ServiceConstructionException(e);
} finally {
if (origLoader != null) {
origLoader.reset();
}
}
return server;
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class NettyHttpDestination method doService.
protected void doService(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (context == null) {
context = servletContext;
}
if (getServer().isSetRedirectURL()) {
resp.sendRedirect(getServer().getRedirectURL());
resp.flushBuffer();
return;
}
// REVISIT: service on executor if associated with endpoint
ClassLoaderHolder origLoader = null;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
invoke(null, context, req, resp);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class UndertowHTTPDestination method doService.
protected void doService(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (context == null) {
context = servletContext;
}
HTTPServerPolicy sp = getServer();
if (sp.isSetRedirectURL()) {
resp.sendRedirect(sp.getRedirectURL());
resp.flushBuffer();
return;
}
ClassLoaderHolder origLoader = null;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
invoke(null, context, req, resp);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
Aggregations