Search in sources :

Example 1 with MustUnderstandInterceptor

use of org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor in project cxf by apache.

the class MustUnderstandInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    Bus bus = BusFactory.getDefaultBus();
    rhi = new ReadHeadersInterceptor(bus, "phase1");
    chain.add(rhi);
    sbi = new StartBodyInterceptor("phase1.5");
    chain.add(sbi);
    mui = new MustUnderstandInterceptor("phase2");
    chain.add(mui);
    dsi = new DummySoapInterceptor("phase3");
    chain.add(dsi);
}
Also used : ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) Bus(org.apache.cxf.Bus) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) StartBodyInterceptor(org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor) Before(org.junit.Before)

Example 2 with MustUnderstandInterceptor

use of org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor in project cxf by apache.

the class SoapBindingFactory method createBinding.

public Binding createBinding(BindingInfo binding) {
    // The default style should be doc-lit wrapped.
    String parameterStyle = SoapBindingConstants.PARAMETER_STYLE_WRAPPED;
    String bindingStyle = SoapBindingConstants.BINDING_STYLE_DOC;
    boolean hasWrapped = false;
    final org.apache.cxf.binding.soap.SoapBinding sb;
    final SoapVersion version;
    if (binding instanceof SoapBindingInfo) {
        SoapBindingInfo sbi = (SoapBindingInfo) binding;
        version = sbi.getSoapVersion();
        sb = new org.apache.cxf.binding.soap.SoapBinding(binding, version);
        // Service wide style
        if (!StringUtils.isEmpty(sbi.getStyle())) {
            bindingStyle = sbi.getStyle();
        }
        boolean hasRPC = false;
        boolean hasDoc = false;
        // Operation wide style, what to do with the mixed style/use?
        for (BindingOperationInfo boi : sbi.getOperations()) {
            String st = sbi.getStyle(boi.getOperationInfo());
            if (st != null) {
                bindingStyle = st;
                if (SoapBindingConstants.BINDING_STYLE_RPC.equalsIgnoreCase(st)) {
                    hasRPC = true;
                } else {
                    hasDoc = true;
                }
            }
            if (boi.getUnwrappedOperation() == null) {
                parameterStyle = SoapBindingConstants.PARAMETER_STYLE_BARE;
            } else {
                hasWrapped = true;
            }
        }
        if (Boolean.TRUE.equals(binding.getService().getProperty("soap.force.doclit.bare"))) {
            hasDoc = true;
            hasRPC = false;
            parameterStyle = SoapBindingConstants.PARAMETER_STYLE_BARE;
            bindingStyle = SoapBindingConstants.BINDING_STYLE_DOC;
        }
        if (hasRPC && hasDoc) {
            throw new RuntimeException("WSI-BP prohibits RPC and Document style " + "operations in same service.");
        }
        // jms
        if (sbi.getTransportURI().equals(SoapJMSConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID)) {
            sb.getInInterceptors().add(new SoapJMSInInterceptor());
        }
    } else {
        throw new RuntimeException("Can not initialize SoapBinding, BindingInfo is not SoapBindingInfo");
    }
    sb.getOutFaultInterceptors().add(new StaxOutInterceptor());
    sb.getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(new AttachmentOutInterceptor());
    sb.getInInterceptors().add(new AttachmentInInterceptor());
    sb.getInInterceptors().add(new StaxInInterceptor());
    sb.getInInterceptors().add(new SoapActionInInterceptor());
    sb.getOutInterceptors().add(new AttachmentOutInterceptor());
    sb.getOutInterceptors().add(new StaxOutInterceptor());
    sb.getOutInterceptors().add(SoapHeaderOutFilterInterceptor.INSTANCE);
    if (SoapBindingConstants.BINDING_STYLE_RPC.equalsIgnoreCase(bindingStyle)) {
        sb.getInInterceptors().add(new RPCInInterceptor());
        sb.getOutInterceptors().add(new RPCOutInterceptor());
    } else if (SoapBindingConstants.BINDING_STYLE_DOC.equalsIgnoreCase(bindingStyle) && SoapBindingConstants.PARAMETER_STYLE_BARE.equalsIgnoreCase(parameterStyle)) {
        // sb.getInInterceptors().add(new BareInInterceptor());
        sb.getInInterceptors().add(new DocLiteralInInterceptor());
        if (hasWrapped) {
            sb.getOutInterceptors().add(new WrappedOutInterceptor());
        }
        sb.getOutInterceptors().add(new BareOutInterceptor());
    } else {
        // sb.getInInterceptors().add(new WrappedInInterceptor());
        sb.getInInterceptors().add(new DocLiteralInInterceptor());
        sb.getOutInterceptors().add(new WrappedOutInterceptor());
        sb.getOutInterceptors().add(new BareOutInterceptor());
    }
    sb.getInInterceptors().add(new SoapHeaderInterceptor());
    sb.getInInterceptors().add(new ReadHeadersInterceptor(getBus(), version));
    sb.getInInterceptors().add(new StartBodyInterceptor());
    sb.getInInterceptors().add(new CheckFaultInterceptor());
    sb.getInInterceptors().add(new MustUnderstandInterceptor());
    sb.getOutInterceptors().add(new SoapPreProtocolOutInterceptor());
    sb.getOutInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(SoapHeaderOutFilterInterceptor.INSTANCE);
    if (version.getVersion() == 1.1) {
        sb.getInFaultInterceptors().add(new Soap11FaultInInterceptor());
        sb.getOutFaultInterceptors().add(new Soap11FaultOutInterceptor());
    } else if (version.getVersion() == 1.2) {
        sb.getInFaultInterceptors().add(new Soap12FaultInInterceptor());
        sb.getOutFaultInterceptors().add(new Soap12FaultOutInterceptor());
    }
    if (binding.getService() != null) {
        for (EndpointInfo ei : binding.getService().getEndpoints()) {
            if (ei.getAddress() != null && ei.getAddress().startsWith("soap.udp")) {
                setupUDP(sb, ei);
            }
        }
    }
    return sb;
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) CheckFaultInterceptor(org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor) StaxOutInterceptor(org.apache.cxf.interceptor.StaxOutInterceptor) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapHeaderInterceptor(org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor) RPCOutInterceptor(org.apache.cxf.binding.soap.interceptor.RPCOutInterceptor) Soap12FaultInInterceptor(org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor) WrappedOutInterceptor(org.apache.cxf.wsdl.interceptors.WrappedOutInterceptor) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AttachmentInInterceptor(org.apache.cxf.interceptor.AttachmentInInterceptor) SoapJMSInInterceptor(org.apache.cxf.binding.soap.jms.interceptor.SoapJMSInInterceptor) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) RPCInInterceptor(org.apache.cxf.binding.soap.interceptor.RPCInInterceptor) Soap11FaultInInterceptor(org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor) SoapOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor) SoapPreProtocolOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor) StaxInInterceptor(org.apache.cxf.interceptor.StaxInInterceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) Soap12FaultOutInterceptor(org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor) StartBodyInterceptor(org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor) Soap11FaultOutInterceptor(org.apache.cxf.binding.soap.interceptor.Soap11FaultOutInterceptor) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapActionInInterceptor(org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor) AttachmentOutInterceptor(org.apache.cxf.interceptor.AttachmentOutInterceptor)

Example 3 with MustUnderstandInterceptor

use of org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor in project cxf by apache.

the class CryptoCoverageCheckerTest method testOrder.

@Test
public void testOrder() throws Exception {
    // make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    List<Interceptor<? extends Message>> lst = new ArrayList<>();
    lst.add(new MustUnderstandInterceptor());
    lst.add(new WSS4JInInterceptor());
    lst.add(new SAAJInInterceptor());
    lst.add(new CryptoCoverageChecker());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, " + "WSS4JInInterceptor, CryptoCoverageChecker"));
}
Also used : PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) ArrayList(java.util.ArrayList) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) TreeSet(java.util.TreeSet) Interceptor(org.apache.cxf.interceptor.Interceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Test(org.junit.Test)

Example 4 with MustUnderstandInterceptor

use of org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor 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)

Example 5 with MustUnderstandInterceptor

use of org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor in project cxf by apache.

the class WSS4JInOutTest method testOrder.

@Test
public void testOrder() throws Exception {
    // make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    List<Interceptor<? extends Message>> lst = new ArrayList<>();
    lst.add(new MustUnderstandInterceptor());
    lst.add(new WSS4JInInterceptor());
    lst.add(new SAAJInInterceptor());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) TreeSet(java.util.TreeSet) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) ArrayList(java.util.ArrayList) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) Test(org.junit.Test)

Aggregations

MustUnderstandInterceptor (org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor)5 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)3 Message (org.apache.cxf.message.Message)3 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 ReadHeadersInterceptor (org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor)2 StartBodyInterceptor (org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor)2 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2 Phase (org.apache.cxf.phase.Phase)2 PhaseInterceptor (org.apache.cxf.phase.PhaseInterceptor)2 Test (org.junit.Test)2 AroundInvoke (javax.interceptor.AroundInvoke)1 Binding (javax.xml.ws.Binding)1 Bus (org.apache.cxf.Bus)1 CheckFaultInterceptor (org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor)1 RPCInInterceptor (org.apache.cxf.binding.soap.interceptor.RPCInInterceptor)1 RPCOutInterceptor (org.apache.cxf.binding.soap.interceptor.RPCOutInterceptor)1