Search in sources :

Example 1 with InterceptorProvider

use of org.apache.cxf.interceptor.InterceptorProvider in project cxf by apache.

the class ClientImpl method onMessage.

public void onMessage(Message message) {
    if (bus == null) {
        throw new IllegalStateException("Message received on a Client that has been closed or destroyed.");
    }
    Endpoint endpoint = message.getExchange().getEndpoint();
    if (endpoint == null) {
        // in this case correlation will occur outside the transport,
        // however there's a possibility that the endpoint may have been
        // rebased in the meantime, so that the response will be mediated
        // via a set of in interceptors provided by a *different* endpoint
        // 
        endpoint = getConduitSelector().getEndpoint();
        message.getExchange().put(Endpoint.class, endpoint);
    }
    message = endpoint.getBinding().createMessage(message);
    message.getExchange().setInMessage(message);
    message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    message.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
    PhaseManager pm = bus.getExtension(PhaseManager.class);
    List<Interceptor<? extends Message>> i1 = bus.getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + i1);
    }
    List<Interceptor<? extends Message>> i2 = getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by client: " + i2);
    }
    List<Interceptor<? extends Message>> i3 = endpoint.getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + i3);
    }
    List<Interceptor<? extends Message>> i4 = endpoint.getBinding().getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by binding: " + i4);
    }
    PhaseInterceptorChain chain;
    if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) {
        InterceptorProvider p = (InterceptorProvider) endpoint.getService().getDataBinding();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + p.getInInterceptors());
        }
        chain = inboundChainCache.get(pm.getInPhases(), i1, i2, i3, i4, p.getInInterceptors());
    } else {
        chain = inboundChainCache.get(pm.getInPhases(), i1, i2, i3, i4);
    }
    message.setInterceptorChain(chain);
    chain.setFaultObserver(outFaultObserver);
    modifyChain(chain, message, true);
    modifyChain(chain, message.getExchange().getOutMessage(), true);
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    // execute chain
    ClientCallback callback = message.getExchange().get(ClientCallback.class);
    try {
        if (callback != null) {
            if (callback.isCancelled()) {
                completeExchange(message.getExchange());
                return;
            }
            callback.start(message);
        }
        String startingAfterInterceptorID = (String) message.get(InterceptorChain.STARTING_AFTER_INTERCEPTOR_ID);
        String startingInterceptorID = (String) message.get(InterceptorChain.STARTING_AT_INTERCEPTOR_ID);
        if (startingAfterInterceptorID != null) {
            chain.doInterceptStartingAfter(message, startingAfterInterceptorID);
        } else if (startingInterceptorID != null) {
            chain.doInterceptStartingAt(message, startingInterceptorID);
        } else if (message.getContent(Exception.class) != null) {
            outFaultObserver.onMessage(message);
        } else {
            callback = message.getExchange().get(ClientCallback.class);
            if (callback != null && !isPartialResponse(message)) {
                try {
                    chain.doIntercept(message);
                } catch (Throwable error) {
                    // so that asyn callback handler get chance to
                    // handle non-runtime exceptions
                    message.getExchange().setInMessage(message);
                    Map<String, Object> resCtx = CastUtils.cast((Map<?, ?>) message.getExchange().getOutMessage().get(Message.INVOCATION_CONTEXT));
                    resCtx = CastUtils.cast((Map<?, ?>) resCtx.get(RESPONSE_CONTEXT));
                    if (resCtx != null) {
                        responseContext.put(Thread.currentThread(), resCtx);
                    }
                    // remove callback so that it won't be invoked twice
                    callback = message.getExchange().remove(ClientCallback.class);
                    if (callback != null) {
                        callback.handleException(resCtx, error);
                    }
                }
            } else {
                chain.doIntercept(message);
            }
        }
        callback = message.getExchange().get(ClientCallback.class);
        if (callback == null || isPartialResponse(message)) {
            return;
        }
        // remove callback so that it won't be invoked twice
        callback = message.getExchange().remove(ClientCallback.class);
        if (callback != null) {
            message.getExchange().setInMessage(message);
            Map<String, Object> resCtx = CastUtils.cast((Map<?, ?>) message.getExchange().getOutMessage().get(Message.INVOCATION_CONTEXT));
            resCtx = CastUtils.cast((Map<?, ?>) resCtx.get(RESPONSE_CONTEXT));
            if (resCtx != null && responseContext != null) {
                responseContext.put(Thread.currentThread(), resCtx);
            }
            try {
                Object[] obj = processResult(message, message.getExchange(), null, resCtx);
                callback.handleResponse(resCtx, obj);
            } catch (Throwable ex) {
                callback.handleException(resCtx, ex);
            }
        }
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        synchronized (message.getExchange()) {
            if (!isPartialResponse(message) || message.getContent(Exception.class) != null) {
                message.getExchange().put(FINISHED, Boolean.TRUE);
                message.getExchange().setInMessage(message);
                message.getExchange().notifyAll();
            }
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) PhaseManager(org.apache.cxf.phase.PhaseManager) Message(org.apache.cxf.message.Message) InterceptorProvider(org.apache.cxf.interceptor.InterceptorProvider) AbstractBasicInterceptorProvider(org.apache.cxf.interceptor.AbstractBasicInterceptorProvider) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UncheckedException(org.apache.cxf.common.i18n.UncheckedException) Interceptor(org.apache.cxf.interceptor.Interceptor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 2 with InterceptorProvider

use of org.apache.cxf.interceptor.InterceptorProvider in project cxf by apache.

the class RedeliveryQueueImpl method getRedeliveryInterceptorChain.

private static InterceptorChain getRedeliveryInterceptorChain(Message m, String phase) {
    Exchange exchange = m.getExchange();
    Endpoint ep = exchange.getEndpoint();
    Bus bus = exchange.getBus();
    PhaseManager pm = bus.getExtension(PhaseManager.class);
    SortedSet<Phase> phases = new TreeSet<Phase>(pm.getInPhases());
    for (Iterator<Phase> it = phases.iterator(); it.hasNext(); ) {
        Phase p = it.next();
        if (phase.equals(p.getName())) {
            break;
        }
        it.remove();
    }
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    List<Interceptor<? extends Message>> il = ep.getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getService().getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getBinding().getInInterceptors();
    addInterceptors(chain, il);
    il = bus.getInInterceptors();
    addInterceptors(chain, il);
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider) ep.getService().getDataBinding()).getInInterceptors();
        addInterceptors(chain, il);
    }
    return chain;
}
Also used : Bus(org.apache.cxf.Bus) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Phase(org.apache.cxf.phase.Phase) PhaseManager(org.apache.cxf.phase.PhaseManager) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) InterceptorProvider(org.apache.cxf.interceptor.InterceptorProvider) Exchange(org.apache.cxf.message.Exchange) Endpoint(org.apache.cxf.endpoint.Endpoint) TreeSet(java.util.TreeSet) RMCaptureInInterceptor(org.apache.cxf.ws.rm.RMCaptureInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 3 with InterceptorProvider

use of org.apache.cxf.interceptor.InterceptorProvider in project cxf by apache.

the class ColocUtil method getInInterceptorChain.

public static InterceptorChain getInInterceptorChain(Exchange ex, SortedSet<Phase> phases) {
    Bus bus = ex.getBus();
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    Endpoint ep = ex.getEndpoint();
    List<Interceptor<? extends Message>> il = ep.getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + il);
    }
    chain.add(il);
    il = ep.getService().getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + il);
    }
    chain.add(il);
    il = bus.getInInterceptors();
    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()).getInInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + il);
        }
        chain.add(il);
    }
    chain.setFaultObserver(new ColocOutFaultObserver(bus));
    modifyChain(chain, ex, true);
    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 4 with InterceptorProvider

use of org.apache.cxf.interceptor.InterceptorProvider 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 5 with InterceptorProvider

use of org.apache.cxf.interceptor.InterceptorProvider in project cxf by apache.

the class ColocUtil method modifyChain.

private static void modifyChain(PhaseInterceptorChain chain, Message m, boolean in) {
    if (m == null) {
        return;
    }
    Collection<InterceptorProvider> providers = CastUtils.cast((Collection<?>) m.get(Message.INTERCEPTOR_PROVIDERS));
    if (providers != null) {
        for (InterceptorProvider p : providers) {
            if (in) {
                chain.add(p.getInInterceptors());
            } else {
                chain.add(p.getOutInterceptors());
            }
        }
    }
    String key = in ? Message.IN_INTERCEPTORS : Message.OUT_INTERCEPTORS;
    Collection<Interceptor<? extends Message>> is = CastUtils.cast((Collection<?>) m.get(key));
    if (is != null) {
        chain.add(is);
    }
}
Also used : Message(org.apache.cxf.message.Message) InterceptorProvider(org.apache.cxf.interceptor.InterceptorProvider) Interceptor(org.apache.cxf.interceptor.Interceptor)

Aggregations

InterceptorProvider (org.apache.cxf.interceptor.InterceptorProvider)10 Message (org.apache.cxf.message.Message)9 Interceptor (org.apache.cxf.interceptor.Interceptor)8 Bus (org.apache.cxf.Bus)6 Endpoint (org.apache.cxf.endpoint.Endpoint)4 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)4 PhaseManager (org.apache.cxf.phase.PhaseManager)4 AbstractBasicInterceptorProvider (org.apache.cxf.interceptor.AbstractBasicInterceptorProvider)3 Exchange (org.apache.cxf.message.Exchange)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 WeakHashMap (java.util.WeakHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)1 UncheckedException (org.apache.cxf.common.i18n.UncheckedException)1 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)1