Search in sources :

Example 1 with HolderInInterceptor

use of org.apache.cxf.jaxws.interceptors.HolderInInterceptor in project tomee by apache.

the class EjbInterceptor method intercept.

@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;
    }
}
Also used : Binding(javax.xml.ws.Binding) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) HolderInInterceptor(org.apache.cxf.jaxws.interceptors.HolderInInterceptor) SOAPHandlerInterceptor(org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) Service(org.apache.cxf.service.Service) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Endpoint(org.apache.cxf.endpoint.Endpoint) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) ServiceInvokerInterceptor(org.apache.cxf.interceptor.ServiceInvokerInterceptor) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) WrapperClassInInterceptor(org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

AroundInvoke (javax.interceptor.AroundInvoke)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 Binding (javax.xml.ws.Binding)1 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 MustUnderstandInterceptor (org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)1 ServiceInvokerInterceptor (org.apache.cxf.interceptor.ServiceInvokerInterceptor)1 LogicalHandlerInInterceptor (org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor)1 SOAPHandlerInterceptor (org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor)1 HolderInInterceptor (org.apache.cxf.jaxws.interceptors.HolderInInterceptor)1 WrapperClassInInterceptor (org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor)1 JaxWsEndpointImpl (org.apache.cxf.jaxws.support.JaxWsEndpointImpl)1 Message (org.apache.cxf.message.Message)1 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)1 Service (org.apache.cxf.service.Service)1 ServerRuntimeException (org.apache.openejb.server.ServerRuntimeException)1