Search in sources :

Example 1 with ReadHeadersInterceptor

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

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

the class ReadHeaderInterceptorTest method testBadSOAPEnvelopeName.

@Test
public void testBadSOAPEnvelopeName() throws Exception {
    soapMessage = TestUtil.createEmptySoapMessage(Soap12.getInstance(), chain);
    InputStream in = getClass().getResourceAsStream("test-bad-envname.xml");
    assertNotNull(in);
    ByteArrayDataSource bads = new ByteArrayDataSource(in, "test/xml");
    soapMessage.setContent(InputStream.class, bads.getInputStream());
    ReadHeadersInterceptor r = new ReadHeadersInterceptor(BusFactory.getDefaultBus());
    try {
        r.handleMessage(soapMessage);
        fail("Did not throw exception");
    } catch (SoapFault f) {
        assertEquals(Soap11.getInstance().getSender(), f.getFaultCode());
    }
}
Also used : ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) InputStream(java.io.InputStream) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Example 3 with ReadHeadersInterceptor

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

the class ReadHeaderInterceptorTest method setUp.

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

Example 4 with ReadHeadersInterceptor

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

the class SoapBindingFactory method addListener.

@Override
public synchronized void addListener(Destination d, Endpoint e) {
    synchronized (d) {
        MessageObserver mo = d.getMessageObserver();
        if (d.getAddress() != null && d.getAddress().getAddress() != null && d.getAddress().getAddress().getValue() != null && d.getAddress().getAddress().getValue().startsWith("soap.udp")) {
            // soap.udp REQUIRES usage of WS-Addressing... we need to turn this on
            setupUDP(e, e.getEndpointInfo());
        }
        if (mo == null) {
            super.addListener(d, e);
            return;
        }
        if (mo instanceof ChainInitiationObserver) {
            ChainInitiationObserver cio = (ChainInitiationObserver) mo;
            Binding b = e.getBinding();
            Binding b2 = cio.getEndpoint().getBinding();
            if (b == b2) {
                // re-registering the same endpoint?
                return;
            }
            Object o = cio.getEndpoint().get("allow-multiplex-endpoint");
            if (o instanceof String) {
                o = Boolean.parseBoolean((String) o);
            } else if (o == null) {
                o = Boolean.FALSE;
            }
            if (b instanceof org.apache.cxf.binding.soap.SoapBinding && b2 instanceof org.apache.cxf.binding.soap.SoapBinding && ((org.apache.cxf.binding.soap.SoapBinding) b).getSoapVersion().equals(((org.apache.cxf.binding.soap.SoapBinding) b2).getSoapVersion()) && Boolean.FALSE.equals(o)) {
                throw new RuntimeException("Soap " + ((org.apache.cxf.binding.soap.SoapBinding) b).getSoapVersion().getVersion() + " endpoint already registered on address " + e.getEndpointInfo().getAddress());
            }
            MultipleEndpointObserver newMO = new MultipleEndpointObserver(getBus()) {

                @Override
                protected Message createMessage(Message message) {
                    return new SoapMessage(message);
                }
            };
            newMO.getBindingInterceptors().add(new AttachmentInInterceptor());
            newMO.getBindingInterceptors().add(new StaxInInterceptor());
            // This will not work if one of the endpoints disables message
            // processing. But, if you've disabled message processing, you
            // probably aren't going to use this feature.
            newMO.getBindingInterceptors().add(new ReadHeadersInterceptor(getBus(), (SoapVersion) null));
            newMO.getBindingInterceptors().add(new StartBodyInterceptor());
            newMO.getBindingInterceptors().add(new CheckFaultInterceptor());
            // Add in a default selection interceptor
            newMO.getRoutingInterceptors().add(new EndpointSelectionInterceptor());
            newMO.getEndpoints().add(cio.getEndpoint());
            mo = newMO;
        }
        if (mo instanceof MultipleEndpointObserver) {
            MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
            meo.getEndpoints().add(e);
        }
        d.setMessageObserver(mo);
    }
}
Also used : SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) Binding(org.apache.cxf.binding.Binding) ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) CheckFaultInterceptor(org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) StaxInInterceptor(org.apache.cxf.interceptor.StaxInInterceptor) EndpointSelectionInterceptor(org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor) StartBodyInterceptor(org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor) ChainInitiationObserver(org.apache.cxf.transport.ChainInitiationObserver) MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) AttachmentInInterceptor(org.apache.cxf.interceptor.AttachmentInInterceptor)

Example 5 with ReadHeadersInterceptor

use of org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor 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;
    org.apache.cxf.binding.soap.SoapBinding sb = null;
    SoapVersion version = null;
    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)

Aggregations

ReadHeadersInterceptor (org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor)10 StartBodyInterceptor (org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor)7 CheckFaultInterceptor (org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor)4 Before (org.junit.Before)4 InputStream (java.io.InputStream)3 StaxInInterceptor (org.apache.cxf.interceptor.StaxInInterceptor)3 Test (org.junit.Test)3 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)2 MustUnderstandInterceptor (org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor)2 SoapOutInterceptor (org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor)2 AttachmentInInterceptor (org.apache.cxf.interceptor.AttachmentInInterceptor)2 Message (org.apache.cxf.message.Message)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Bus (org.apache.cxf.Bus)1 Binding (org.apache.cxf.binding.Binding)1 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 EndpointSelectionInterceptor (org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor)1 RPCInInterceptor (org.apache.cxf.binding.soap.interceptor.RPCInInterceptor)1 RPCOutInterceptor (org.apache.cxf.binding.soap.interceptor.RPCOutInterceptor)1 Soap11FaultInInterceptor (org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor)1