Java Code Examples for org.apache.cxf.phase.PhaseInterceptorChain#setFaultObserver()

The following examples show how to use org.apache.cxf.phase.PhaseInterceptorChain#setFaultObserver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColocUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static PhaseInterceptorChain setupInInterceptorChain(ClientConfiguration cfg) {
    PhaseManager pm = cfg.getBus().getExtension(PhaseManager.class);
    List<Interceptor<? extends Message>> i1 = cfg.getBus().getInInterceptors();
    List<Interceptor<? extends Message>> i2 = cfg.getInInterceptors();
    List<Interceptor<? extends Message>> i3 = cfg.getConduitSelector().getEndpoint().getInInterceptors();
    PhaseInterceptorChain chain = new PhaseChainCache().get(pm.getInPhases(), i1, i2, i3);
    chain.add(new ClientResponseFilterInterceptor());
    chain.setFaultObserver(setupInFaultObserver(cfg));
    return chain;
}
 
Example 3
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: AbstractClient.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected Message createMessage(Object body,
                                String httpMethod,
                                MultivaluedMap<String, String> headers,
                                URI currentURI,
                                Exchange exchange,
                                Map<String, Object> invocationContext,
                                boolean proxy) {
    checkClosed();
    Message m = cfg.getConduitSelector().getEndpoint().getBinding().createMessage();
    m.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    m.put(Message.INBOUND_MESSAGE, Boolean.FALSE);

    setRequestMethod(m, httpMethod);
    m.put(Message.PROTOCOL_HEADERS, headers);
    if (currentURI.isAbsolute() && currentURI.getScheme().startsWith(HTTP_SCHEME)) {
        m.put(Message.ENDPOINT_ADDRESS, currentURI.toString());
    } else {
        m.put(Message.ENDPOINT_ADDRESS, state.getBaseURI().toString());
    }

    Object requestURIProperty = cfg.getRequestContext().get(Message.REQUEST_URI);
    if (requestURIProperty == null) {
        m.put(Message.REQUEST_URI, currentURI.toString());
    } else {
        m.put(Message.REQUEST_URI, requestURIProperty.toString());
    }

    String ct = headers.getFirst(HttpHeaders.CONTENT_TYPE);
    m.put(Message.CONTENT_TYPE, ct);

    body = checkIfBodyEmpty(body, ct);
    setEmptyRequestPropertyIfNeeded(m, body);

    m.setContent(List.class, getContentsList(body));

    m.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates());

    PhaseInterceptorChain chain = setupOutInterceptorChain(cfg);
    chain.setFaultObserver(setupInFaultObserver(cfg));
    m.setInterceptorChain(chain);

    exchange = createExchange(m, exchange);
    exchange.put(Message.REST_MESSAGE, Boolean.TRUE);
    exchange.setOneWay("true".equals(headers.getFirst(Message.ONE_WAY_REQUEST)));
    exchange.put(Retryable.class, new RetryableImpl());

    // context
    setContexts(m, exchange, invocationContext, proxy);

    //setup conduit selector
    prepareConduitSelector(m, currentURI, proxy);

    return m;
}
 
Example 5
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 6
Source File: EjbInterceptor.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Endpoint endpoint = this.exchange.get(Endpoint.class);
    Service service = endpoint.getService();
    Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();

    this.exchange.put(InvocationContext.class, context);

    if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
        // no handlers so let's just directly invoke the bean
        log.debug("No handlers found.");

        EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
        return invoker.directEjbInvoke(this.exchange, this.method, this.params);

    } else {
        // have handlers so have to run handlers now and redo data binding
        // as handlers can change the soap message
        log.debug("Handlers found.");

        Message inMessage = exchange.getInMessage();
        PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());

        chain.setFaultObserver(endpoint.getOutFaultObserver());

        /*
         * Since we have to re-do data binding and the XMLStreamReader
         * contents are already consumed by prior data binding step
         * we have to reinitialize the XMLStreamReader from the SOAPMessage
         * created by SAAJInInterceptor.
         */
        if (inMessage instanceof SoapMessage) {
            try {
                reserialize((SoapMessage) inMessage);
            } catch (Exception e) {
                throw new ServerRuntimeException("Failed to reserialize soap message", e);
            }
        } else {
            // TODO: how to handle XML/HTTP binding?
        }

        this.exchange.setOutMessage(null);

        // install default interceptors
        chain.add(new ServiceInvokerInterceptor());
        //chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!

        // See http://cwiki.apache.org/CXF20DOC/interceptors.html
        // install Holder and Wrapper interceptors
        chain.add(new WrapperClassInInterceptor());
        chain.add(new HolderInInterceptor());

        // install interceptors for handler processing
        chain.add(new MustUnderstandInterceptor());
        chain.add(new LogicalHandlerInInterceptor(binding));
        chain.add(new SOAPHandlerInterceptor(binding));

        // install data binding interceptors - todo: check we need it
        copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());

        InterceptorChain oldChain = inMessage.getInterceptorChain();
        inMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(inMessage);
        } finally {
            inMessage.setInterceptorChain(oldChain);
        }

        // TODO: the result should be deserialized from SOAPMessage
        Object result = getResult();

        return result;
    }
}