Search in sources :

Example 1 with DocLiteralInInterceptor

use of org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor in project cxf by apache.

the class XMLBindingFactory method createBinding.

public Binding createBinding(BindingInfo binding) {
    XMLBinding xb = new XMLBinding(binding);
    xb.getInInterceptors().add(new AttachmentInInterceptor());
    xb.getInInterceptors().add(new StaxInInterceptor());
    xb.getInInterceptors().add(new DocLiteralInInterceptor());
    xb.getInInterceptors().add(new XMLMessageInInterceptor());
    xb.getOutInterceptors().add(new AttachmentOutInterceptor());
    xb.getOutInterceptors().add(new StaxOutInterceptor());
    xb.getOutInterceptors().add(new WrappedOutInterceptor());
    xb.getOutInterceptors().add(new XMLMessageOutInterceptor());
    xb.getInFaultInterceptors().add(new XMLFaultInInterceptor());
    xb.getOutFaultInterceptors().add(new StaxOutInterceptor());
    xb.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
    return xb;
}
Also used : WrappedOutInterceptor(org.apache.cxf.wsdl.interceptors.WrappedOutInterceptor) StaxOutInterceptor(org.apache.cxf.interceptor.StaxOutInterceptor) XMLMessageInInterceptor(org.apache.cxf.binding.xml.interceptor.XMLMessageInInterceptor) XMLFaultOutInterceptor(org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor) AttachmentInInterceptor(org.apache.cxf.interceptor.AttachmentInInterceptor) StaxInInterceptor(org.apache.cxf.interceptor.StaxInInterceptor) XMLFaultInInterceptor(org.apache.cxf.binding.xml.interceptor.XMLFaultInInterceptor) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) XMLMessageOutInterceptor(org.apache.cxf.binding.xml.interceptor.XMLMessageOutInterceptor) AttachmentOutInterceptor(org.apache.cxf.interceptor.AttachmentOutInterceptor)

Example 2 with DocLiteralInInterceptor

use of org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor in project cxf by apache.

the class DocLiteralInInterceptorTest method testInterceptorInboundBareNoParameter.

@Test
public void testInterceptorInboundBareNoParameter() throws Exception {
    setUpUsingDocLit();
    DocLiteralInInterceptor interceptor = new DocLiteralInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/bareNoParamDocLitBareReq.xml")));
    XMLStreamReader reader = message.getContent(XMLStreamReader.class);
    // skip the start element of soap body, so that we can serve an empty request to
    // interceptor
    StaxUtils.skipToStartOfElement(reader);
    StaxUtils.nextEvent(reader);
    message.put(Message.INBOUND_MESSAGE, Message.INBOUND_MESSAGE);
    interceptor.handleMessage(message);
    assertNull(message.getContent(Exception.class));
    List<?> parameters = message.getContent(List.class);
    assertNull(parameters);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) Test(org.junit.Test)

Example 3 with DocLiteralInInterceptor

use of org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor in project cxf by apache.

the class DocLiteralInInterceptorTest method testInterceptorInboundWrapped.

@Test
public void testInterceptorInboundWrapped() throws Exception {
    setUpUsingHelloWorld();
    // WrappedInInterceptor interceptor = new WrappedInInterceptor();
    DocLiteralInInterceptor interceptor = new DocLiteralInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/GreetMeDocLiteralReq.xml")));
    XMLStreamReader reader = message.getContent(XMLStreamReader.class);
    // skip the start element of soap body
    StaxUtils.skipToStartOfElement(reader);
    message.put(Message.INBOUND_MESSAGE, Message.INBOUND_MESSAGE);
    interceptor.handleMessage(message);
    assertNull(message.getContent(Exception.class));
    List<?> parameters = message.getContent(List.class);
    assertEquals(1, parameters.size());
    Object obj = parameters.get(0);
    assertTrue(obj instanceof GreetMe);
    GreetMe greet = (GreetMe) obj;
    assertEquals("TestSOAPInputPMessage", greet.getRequestType());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) XMLStreamReader(javax.xml.stream.XMLStreamReader) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) Test(org.junit.Test)

Example 4 with DocLiteralInInterceptor

use of org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor 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 5 with DocLiteralInInterceptor

use of org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor in project cxf by apache.

the class DocLiteralInInterceptorTest method testInterceptorInboundBare.

@Test
public void testInterceptorInboundBare() throws Exception {
    setUpUsingDocLit();
    DocLiteralInInterceptor interceptor = new DocLiteralInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/sayHiDocLitBareReq.xml")));
    XMLStreamReader reader = message.getContent(XMLStreamReader.class);
    // skip the start element of soap body
    StaxUtils.skipToStartOfElement(reader);
    message.put(Message.INBOUND_MESSAGE, Message.INBOUND_MESSAGE);
    interceptor.handleMessage(message);
    assertNull(message.getContent(Exception.class));
    List<?> parameters = message.getContent(List.class);
    assertEquals(1, parameters.size());
    Object obj = parameters.get(0);
    assertTrue(obj instanceof TradePriceData);
    TradePriceData greet = (TradePriceData) obj;
    assertTrue(1.0 == greet.getTickerPrice());
    assertEquals("CXF", greet.getTickerSymbol());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) Test(org.junit.Test)

Aggregations

DocLiteralInInterceptor (org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor)5 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 Test (org.junit.Test)3 AttachmentInInterceptor (org.apache.cxf.interceptor.AttachmentInInterceptor)2 AttachmentOutInterceptor (org.apache.cxf.interceptor.AttachmentOutInterceptor)2 StaxInInterceptor (org.apache.cxf.interceptor.StaxInInterceptor)2 StaxOutInterceptor (org.apache.cxf.interceptor.StaxOutInterceptor)2 WrappedOutInterceptor (org.apache.cxf.wsdl.interceptors.WrappedOutInterceptor)2 CheckFaultInterceptor (org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor)1 MustUnderstandInterceptor (org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor)1 RPCInInterceptor (org.apache.cxf.binding.soap.interceptor.RPCInInterceptor)1 RPCOutInterceptor (org.apache.cxf.binding.soap.interceptor.RPCOutInterceptor)1 ReadHeadersInterceptor (org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor)1 Soap11FaultInInterceptor (org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor)1 Soap11FaultOutInterceptor (org.apache.cxf.binding.soap.interceptor.Soap11FaultOutInterceptor)1 Soap12FaultInInterceptor (org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor)1 Soap12FaultOutInterceptor (org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor)1 SoapActionInInterceptor (org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor)1 SoapHeaderInterceptor (org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor)1 SoapOutInterceptor (org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor)1