Java Code Examples for org.apache.cxf.service.model.BindingMessageInfo#getExtensor()

The following examples show how to use org.apache.cxf.service.model.BindingMessageInfo#getExtensor() . 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: SoapApiModelParser.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static DataShape getDataShape(BindingMessageInfo messageInfo) throws ParserException {

        // message is missing or doesn't have any headers and body parts,
        // probably only faults for output messages
        // TODO handle operation faults instead of letting CXF throw them as Exceptions
        if (messageInfo == null ||
            (messageInfo.getExtensor(SoapBodyInfo.class) == null && messageInfo.getExtensor(SoapHeaderInfo.class) == null)) {
            return new DataShape.Builder().kind(DataShapeKinds.NONE).build();
        }

        final BindingHelper bindingHelper;
        try {
            bindingHelper = new BindingHelper(messageInfo);
        } catch (ParserConfigurationException e) {
            throw new ParserException("Error creating XML Document parser: " + e.getMessage(), e);
        }

        return new DataShape.Builder()
                .kind(DataShapeKinds.XML_SCHEMA)
                .name(messageInfo.getMessageInfo().getName().getLocalPart())
                .description(getMessageDescription(messageInfo))
                .specification(bindingHelper.getSpecification())
                .build();
    }
 
Example 2
Source File: BindingHelper.java    From syndesis with Apache License 2.0 5 votes vote down vote up
BindingHelper(BindingMessageInfo bindingMessageInfo) throws ParserException, ParserConfigurationException {

        this.bindingMessageInfo = bindingMessageInfo;
        this.bindingOperation = bindingMessageInfo.getBindingOperation();
        this.schemaCollection = bindingMessageInfo.getBindingOperation().getBinding().getService().getXmlSchemaCollection();

        SoapOperationInfo soapOperationInfo = bindingOperation.getExtensor(SoapOperationInfo.class);
        SoapBindingInfo soapBindingInfo = (SoapBindingInfo) bindingOperation.getBinding();

        soapVersion = soapBindingInfo.getSoapVersion();

        // get binding style
        if (soapOperationInfo.getStyle() != null) {
            style = Style.valueOf(soapOperationInfo.getStyle().toUpperCase(Locale.US));
        } else if (soapBindingInfo.getStyle() != null) {
            style = Style.valueOf(soapBindingInfo.getStyle().toUpperCase(Locale.US));
        } else {
            style = Style.DOCUMENT;
        }

        // get body binding
        SoapBodyInfo soapBodyInfo = bindingMessageInfo.getExtensor(SoapBodyInfo.class);
        List<SoapHeaderInfo> soapHeaders = bindingMessageInfo.getExtensors(SoapHeaderInfo.class);
        bodyParts = soapBodyInfo.getParts();

        // get any headers as MessagePartInfos
        hasHeaders = soapHeaders != null && !soapHeaders.isEmpty();
        headerParts = hasHeaders ?
            soapHeaders.stream().map(SoapHeaderInfo::getPart).collect(Collectors.toList()) : null;

        // get required body use
        Use use = Use.valueOf(soapBodyInfo.getUse().toUpperCase(Locale.US));
        if (ENCODED.equals(use)) {
            // TODO could we add support for RPC/encoded messages by setting schema type to any??
            throw new ParserException("Messages with use='encoded' are not supported");
        }

        // Document builder for create schemaset
        this.documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    }
 
Example 3
Source File: SwAOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    if (bop == null) {
        return;
    }

    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }

    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getInput() : bop.getOutput();

    if (bmi == null) {
        return;
    }

    SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);

    if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
        Service s = ex.getService();
        DataBinding db = s.getDataBinding();
        if (db instanceof JAXBDataBinding
            && hasSwaRef((JAXBDataBinding) db)) {
            setupAttachmentOutput(message);
        }
        return;
    }
    processAttachments(message, sbi);
}
 
Example 4
Source File: ServiceModelPolicyProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Policy getEffectivePolicy(BindingMessageInfo bmi, Message m) {
    return bmi.getExtensor(Policy.class);
}
 
Example 5
Source File: XMLMessageOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    MessageInfo mi;
    BindingMessageInfo bmi;
    if (isRequestor(message)) {
        mi = boi.getOperationInfo().getInput();
        bmi = boi.getInput();
    } else {
        mi = boi.getOperationInfo().getOutput();
        bmi = boi.getOutput();
    }
    XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
    QName rootInModel = null;
    if (xmf != null) {
        rootInModel = xmf.getRootNode();
    }
    final int mpn = mi.getMessagePartsNumber();
    if (boi.isUnwrapped()
        || mpn == 1) {
        // wrapper out interceptor created the wrapper
        // or if bare-one-param
        new BareOutInterceptor().handleMessage(message);
    } else {
        if (rootInModel == null) {
            rootInModel = boi.getName();
        }
        if (mpn == 0 && !boi.isUnwrapped()) {
            // write empty operation qname
            writeMessage(message, rootInModel, false);
        } else {
            // multi param, bare mode, needs write root node
            writeMessage(message, rootInModel, true);
        }
    }
    // in the end we do flush ;)
    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    try {
        writer.flush();
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
    }
}
 
Example 6
Source File: XMLMessageInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean hasRootNode(BindingMessageInfo bmi, QName elName) {
    XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
    return bmi.getMessageParts().size() != 1 && xmf != null && xmf.getRootNode().equals(elName);
}
 
Example 7
Source File: SoapBindingFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoBodyParts() throws Exception {
    Definition d = createDefinition("/wsdl_soap/no_body_parts.wsdl");
    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("urn:org:apache:cxf:no_body_parts/wsdl",
                                    "NoBodyParts"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);

    BindingOperationInfo boi = sbi.getOperation(new QName("urn:org:apache:cxf:no_body_parts/wsdl",
                                                          "operation1"));

    assertNotNull(boi);
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertNull(sboi.getStyle());
    assertEquals("", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertNull(bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(0, parts.size());
}
 
Example 8
Source File: SoapBindingFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testFactory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world.wsdl");

    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("http://apache.org/hello_world_soap_http", "SOAPService"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);

    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap_http",
                                                          "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());
}
 
Example 9
Source File: SoapBindingFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testSoap12Factory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world_soap12.wsdl");

    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP12, bus);

    expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm);

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("http://apache.org/hello_world_soap12_http", "SOAPService"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertEquals(WSDLConstants.NS_SOAP_HTTP_TRANSPORT, sbi.getTransportURI());
    assertTrue(sbi.getSoapVersion() instanceof Soap12);

    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http",
                                                          "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("sayHiAction", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());

    boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "pingMe"));
    sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());
    Collection<BindingFaultInfo> faults = boi.getFaults();
    assertEquals(1, faults.size());
    BindingFaultInfo faultInfo = boi.getFault(new QName("http://apache.org/hello_world_soap12_http",
                                                        "pingMeFault"));
    assertNotNull(faultInfo);
}