Search in sources :

Example 21 with PhaseInterceptorChain

use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.

the class ColocUtil method getOutInterceptorChain.

public static InterceptorChain getOutInterceptorChain(Exchange ex, SortedSet<Phase> phases) {
    Bus bus = ex.getBus();
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    Endpoint ep = ex.getEndpoint();
    List<Interceptor<? extends Message>> il = ep.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + il);
    }
    chain.add(il);
    il = ep.getService().getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + il);
    }
    chain.add(il);
    il = bus.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + il);
    }
    chain.add(il);
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider) ep.getService().getDataBinding()).getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + il);
        }
        chain.add(il);
    }
    modifyChain(chain, ex, false);
    return chain;
}
Also used : Bus(org.apache.cxf.Bus) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) InterceptorProvider(org.apache.cxf.interceptor.InterceptorProvider) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 22 with PhaseInterceptorChain

use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.

the class AbstractClient method setupOutInterceptorChain.

protected static PhaseInterceptorChain setupOutInterceptorChain(ClientConfiguration cfg) {
    PhaseManager pm = cfg.getBus().getExtension(PhaseManager.class);
    List<Interceptor<? extends Message>> i1 = cfg.getBus().getOutInterceptors();
    List<Interceptor<? extends Message>> i2 = cfg.getOutInterceptors();
    List<Interceptor<? extends Message>> i3 = cfg.getConduitSelector().getEndpoint().getOutInterceptors();
    PhaseInterceptorChain chain = new PhaseChainCache().get(pm.getOutPhases(), i1, i2, i3);
    chain.add(new ClientRequestFilterInterceptor());
    return chain;
}
Also used : PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) PhaseManager(org.apache.cxf.phase.PhaseManager) Message(org.apache.cxf.message.Message) ClientRequestFilterInterceptor(org.apache.cxf.jaxrs.client.spec.ClientRequestFilterInterceptor) StaxInEndingInterceptor(org.apache.cxf.interceptor.StaxInEndingInterceptor) ClientRequestFilterInterceptor(org.apache.cxf.jaxrs.client.spec.ClientRequestFilterInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) ClientResponseFilterInterceptor(org.apache.cxf.jaxrs.client.spec.ClientResponseFilterInterceptor) AbstractOutDatabindingInterceptor(org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) PhaseChainCache(org.apache.cxf.phase.PhaseChainCache)

Example 23 with PhaseInterceptorChain

use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.

the class OutgoingChainInterceptor method getOutInterceptorChain.

public static InterceptorChain getOutInterceptorChain(Exchange ex) {
    Bus bus = ex.getBus();
    Binding binding = ex.getBinding();
    PhaseManager pm = bus.getExtension(PhaseManager.class);
    PhaseInterceptorChain chain = new PhaseInterceptorChain(pm.getOutPhases());
    Endpoint ep = ex.getEndpoint();
    List<Interceptor<? extends Message>> il = ep.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + il);
    }
    chain.add(il);
    il = ep.getService().getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + il);
    }
    chain.add(il);
    il = bus.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + il);
    }
    chain.add(il);
    if (binding != null) {
        il = binding.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by binding: " + il);
        }
        chain.add(il);
    }
    modifyChain(chain, ex);
    chain.setFaultObserver(ep.getOutFaultObserver());
    return chain;
}
Also used : Binding(org.apache.cxf.binding.Binding) Bus(org.apache.cxf.Bus) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) PhaseManager(org.apache.cxf.phase.PhaseManager) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor)

Example 24 with PhaseInterceptorChain

use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.

the class OutgoingChainInterceptor method getChain.

private static PhaseInterceptorChain getChain(Exchange ex, PhaseChainCache chainCache) {
    Bus bus = ex.getBus();
    Binding binding = ex.getBinding();
    Endpoint ep = ex.getEndpoint();
    List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + i1);
    }
    List<Interceptor<? extends Message>> i2 = ep.getService().getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + i2);
    }
    List<Interceptor<? extends Message>> i3 = ep.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + i3);
    }
    List<Interceptor<? extends Message>> i4 = null;
    if (binding != null) {
        i4 = binding.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by binding: " + i4);
        }
    }
    List<Interceptor<? extends Message>> i5 = null;
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        i5 = ((InterceptorProvider) ep.getService().getDataBinding()).getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + i5);
        }
        if (i4 == null) {
            i4 = i5;
            i5 = null;
        }
    }
    PhaseInterceptorChain chain;
    if (i5 != null) {
        chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(), i1, i2, i3, i4, i5);
    } else if (i4 != null) {
        chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(), i1, i2, i3, i4);
    } else {
        chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(), i1, i2, i3);
    }
    modifyChain(chain, ex);
    chain.setFaultObserver(ep.getOutFaultObserver());
    return chain;
}
Also used : Binding(org.apache.cxf.binding.Binding) Bus(org.apache.cxf.Bus) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) PhaseManager(org.apache.cxf.phase.PhaseManager) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor)

Example 25 with PhaseInterceptorChain

use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.

the class ServiceInvokerInterceptor method handleMessage.

public void handleMessage(final Message message) {
    final Exchange exchange = message.getExchange();
    final Endpoint endpoint = exchange.getEndpoint();
    final Service service = endpoint.getService();
    final Invoker invoker = service.getInvoker();
    Runnable invocation = new Runnable() {

        public void run() {
            Exchange runableEx = message.getExchange();
            Object result = invoker.invoke(runableEx, getInvokee(message));
            if (!exchange.isOneWay()) {
                Endpoint ep = exchange.getEndpoint();
                Message outMessage = runableEx.getOutMessage();
                if (outMessage == null) {
                    outMessage = new MessageImpl();
                    outMessage.setExchange(exchange);
                    outMessage = ep.getBinding().createMessage(outMessage);
                    exchange.setOutMessage(outMessage);
                }
                copyJaxwsProperties(message, outMessage);
                if (result != null) {
                    MessageContentsList resList = null;
                    if (result instanceof MessageContentsList) {
                        resList = (MessageContentsList) result;
                    } else if (result instanceof List) {
                        resList = new MessageContentsList((List<?>) result);
                    } else if (result.getClass().isArray()) {
                        resList = new MessageContentsList((Object[]) result);
                    } else {
                        outMessage.setContent(Object.class, result);
                    }
                    if (resList != null) {
                        outMessage.setContent(List.class, resList);
                    }
                }
            }
        }
    };
    Executor executor = getExecutor(endpoint);
    Executor executor2 = exchange.get(Executor.class);
    if (executor2 == executor || executor == null || !(message.getInterceptorChain() instanceof PhaseInterceptorChain)) {
        // already executing on the appropriate executor
        invocation.run();
    } else {
        exchange.put(Executor.class, executor);
        // The current thread holds the lock on PhaseInterceptorChain.
        // In order to avoid the executor threads deadlocking on any of
        // synchronized PhaseInterceptorChain methods the current thread
        // needs to release the chain lock and re-acquire it after the
        // executor thread is done
        final PhaseInterceptorChain chain = (PhaseInterceptorChain) message.getInterceptorChain();
        final AtomicBoolean contextSwitched = new AtomicBoolean();
        final FutureTask<Object> o = new FutureTask<Object>(invocation, null) {

            @Override
            protected void done() {
                super.done();
                if (contextSwitched.get()) {
                    PhaseInterceptorChain.setCurrentMessage(chain, null);
                    message.remove(Message.THREAD_CONTEXT_SWITCHED);
                }
                chain.releaseChain();
            }

            @Override
            public void run() {
                if (PhaseInterceptorChain.setCurrentMessage(chain, message)) {
                    contextSwitched.set(true);
                    message.put(Message.THREAD_CONTEXT_SWITCHED, true);
                }
                synchronized (chain) {
                    super.run();
                }
            }
        };
        synchronized (chain) {
            executor.execute(o);
            // the task will already be done if the executor uses the current thread
            // but the chain lock status still needs to be re-set
            chain.releaseAndAcquireChain();
        }
        try {
            o.get();
        } catch (InterruptedException e) {
            throw new Fault(e);
        } catch (ExecutionException e) {
            if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            }
            throw new Fault(e.getCause());
        }
    }
}
Also used : PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) Service(org.apache.cxf.service.Service) Exchange(org.apache.cxf.message.Exchange) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Executor(java.util.concurrent.Executor) Endpoint(org.apache.cxf.endpoint.Endpoint) Invoker(org.apache.cxf.service.invoker.Invoker) FutureTask(java.util.concurrent.FutureTask) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) MessageImpl(org.apache.cxf.message.MessageImpl)

Aggregations

PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)32 Message (org.apache.cxf.message.Message)24 Bus (org.apache.cxf.Bus)14 Interceptor (org.apache.cxf.interceptor.Interceptor)12 Endpoint (org.apache.cxf.endpoint.Endpoint)10 Exchange (org.apache.cxf.message.Exchange)10 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)9 IOException (java.io.IOException)8 PhaseManager (org.apache.cxf.phase.PhaseManager)8 TreeSet (java.util.TreeSet)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)6 Phase (org.apache.cxf.phase.Phase)6 Test (org.junit.Test)6 Fault (org.apache.cxf.interceptor.Fault)5 InterceptorProvider (org.apache.cxf.interceptor.InterceptorProvider)5 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)5 SOAPMessage (javax.xml.soap.SOAPMessage)4 MessageContentsList (org.apache.cxf.message.MessageContentsList)4 URISyntaxException (java.net.URISyntaxException)3