Search in sources :

Example 36 with ClassLoaderHolder

use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project tomee 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;
        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();
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) PhaseManager(org.apache.cxf.phase.PhaseManager) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) InterceptorProvider(org.apache.cxf.interceptor.InterceptorProvider) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)36 Bus (org.apache.cxf.Bus)24 Message (org.apache.cxf.message.Message)15 IOException (java.io.IOException)7 Exchange (org.apache.cxf.message.Exchange)6 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)6 ServerImpl (org.apache.cxf.endpoint.ServerImpl)5 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)5 Endpoint (org.apache.cxf.endpoint.Endpoint)4 URISyntaxException (java.net.URISyntaxException)3 List (java.util.List)3 Application (javax.ws.rs.core.Application)3 Fault (org.apache.cxf.interceptor.Fault)3 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)3 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)3 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 URI (java.net.URI)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2