Search in sources :

Example 1 with SoapBodyInfo

use of org.apache.cxf.binding.soap.model.SoapBodyInfo in project cxf by apache.

the class SoapBindingFactoryTest method testFactory.

@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());
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) Test(org.junit.Test)

Example 2 with SoapBodyInfo

use of org.apache.cxf.binding.soap.model.SoapBodyInfo in project cxf by apache.

the class SwAInInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
    if (bop == null) {
        return;
    }
    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }
    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
    if (bmi == null) {
        return;
    }
    SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);
    if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
        return;
    }
    Set<Integer> foundAtts = new HashSet<>();
    MessageContentsList inObjects = MessageContentsList.getContentsList(message);
    for (MessagePartInfo mpi : sbi.getAttachments()) {
        String partName = mpi.getConcreteName().getLocalPart();
        String start = partName + "=";
        boolean found = false;
        if (foundAtts.contains(mpi.getIndex())) {
            continue;
        }
        foundAtts.add(mpi.getIndex());
        for (Attachment a : message.getAttachments()) {
            if (a.getId().startsWith(start)) {
                DataHandler dh = a.getDataHandler();
                String ct = dh.getContentType();
                final Object o;
                Class<?> typeClass = mpi.getTypeClass();
                if (DataHandler.class.isAssignableFrom(typeClass)) {
                    o = dh;
                } else if (String.class.isAssignableFrom(typeClass)) {
                    try {
                        // o = IOUtils.readBytesFromStream(dh.getInputStream());
                        o = dh.getContent();
                    } catch (IOException e) {
                        throw new Fault(e);
                    }
                } else if (byte[].class.isAssignableFrom(typeClass)) {
                    try {
                        o = IOUtils.readBytesFromStream(dh.getInputStream());
                    } catch (IOException e) {
                        throw new Fault(e);
                    }
                } else if (ct.startsWith("image/")) {
                    try {
                        o = ImageIO.read(dh.getInputStream());
                    } catch (IOException e) {
                        throw new Fault(e);
                    }
                } else if (ct.startsWith("text/xml") || ct.startsWith("application/xml")) {
                    try {
                        o = new StreamSource(dh.getInputStream());
                    } catch (IOException e) {
                        throw new Fault(e);
                    }
                } else {
                    o = dh;
                }
                inObjects.put(mpi, o);
                found = true;
                break;
            }
        }
        if (!found) {
            inObjects.put(mpi, null);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) StreamSource(javax.xml.transform.stream.StreamSource) Attachment(org.apache.cxf.message.Attachment) Fault(org.apache.cxf.interceptor.Fault) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) HashSet(java.util.HashSet)

Example 3 with SoapBodyInfo

use of org.apache.cxf.binding.soap.model.SoapBodyInfo in project cxf by apache.

the class SoapBindingFactory method initializeMessage.

private void initializeMessage(SoapBindingInfo bi, BindingOperationInfo boi, BindingMessageInfo bmsg) {
    MessageInfo msg = bmsg.getMessageInfo();
    List<MessagePartInfo> messageParts = new ArrayList<>();
    messageParts.addAll(msg.getMessageParts());
    List<SoapHeader> headers = SOAPBindingUtil.getSoapHeaders(bmsg.getExtensors(ExtensibilityElement.class));
    if (headers != null) {
        for (SoapHeader header : headers) {
            SoapHeaderInfo headerInfo = new SoapHeaderInfo();
            headerInfo.setUse(header.getUse());
            if (StringUtils.isEmpty(header.getPart())) {
                throw new RuntimeException("Problem with WSDL: soap:header element in operation " + boi.getName().getLocalPart() + " does not specify a part.");
            }
            MessagePartInfo part = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), header.getPart()));
            if (part != null && header.getMessage() != null && !part.getMessageInfo().getName().equals(header.getMessage())) {
                part = null;
                // out of band, let's find it
                for (MessagePartInfo mpi : msg.getOutOfBandParts()) {
                    if (mpi.getName().getLocalPart().equals(header.getPart()) && mpi.getMessageInfo().getName().equals(header.getMessage())) {
                        part = mpi;
                    }
                }
            }
            if (part != null) {
                headerInfo.setPart(part);
                messageParts.remove(part);
                bmsg.addExtensor(headerInfo);
            }
        }
        // Exclude the header parts from the message part list.
        bmsg.setMessageParts(messageParts);
    }
    SoapBodyInfo bodyInfo = new SoapBodyInfo();
    SoapBody soapBody = SOAPBindingUtil.getSoapBody(bmsg.getExtensors(ExtensibilityElement.class));
    List<?> parts = null;
    if (soapBody == null) {
        MIMEMultipartRelated mmr = bmsg.getExtensor(MIMEMultipartRelated.class);
        if (mmr != null) {
            parts = mmr.getMIMEParts();
        }
    } else {
        bmsg.addExtensor(soapBody);
        bodyInfo.setUse(soapBody.getUse());
        parts = soapBody.getParts();
    }
    // Initialize the body parts.
    List<MessagePartInfo> attParts = null;
    if (parts != null) {
        List<MessagePartInfo> bodyParts = new ArrayList<>();
        for (Iterator<?> itr = parts.iterator(); itr.hasNext(); ) {
            Object part = itr.next();
            if (part instanceof MIMEPart) {
                MIMEPart mpart = (MIMEPart) part;
                attParts = handleMimePart(mpart, attParts, msg, bmsg, bodyParts, messageParts);
            } else {
                addSoapBodyPart(msg, bodyParts, (String) part);
            }
        }
        bodyInfo.setParts(bodyParts);
        bodyInfo.setAttachments(attParts);
    } else {
        bodyInfo.setParts(messageParts);
    }
    bmsg.addExtensor(bodyInfo);
}
Also used : SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) QName(javax.xml.namespace.QName) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) ArrayList(java.util.ArrayList) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) MIMEMultipartRelated(javax.wsdl.extensions.mime.MIMEMultipartRelated) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) MIMEPart(javax.wsdl.extensions.mime.MIMEPart)

Example 4 with SoapBodyInfo

use of org.apache.cxf.binding.soap.model.SoapBodyInfo in project cxf by apache.

the class SoapBindingFactoryTest method testNoBodyParts.

@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());
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) Test(org.junit.Test)

Example 5 with SoapBodyInfo

use of org.apache.cxf.binding.soap.model.SoapBodyInfo in project cxf by apache.

the class SoapBindingFactoryTest method testSoap12Factory.

@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);
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) Test(org.junit.Test)

Aggregations

SoapBodyInfo (org.apache.cxf.binding.soap.model.SoapBodyInfo)6 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)6 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)5 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)5 QName (javax.xml.namespace.QName)4 Definition (javax.wsdl.Definition)3 Bus (org.apache.cxf.Bus)3 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)3 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)3 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)3 BindingInfo (org.apache.cxf.service.model.BindingInfo)3 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)3 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)3 WSDLServiceBuilder (org.apache.cxf.wsdl11.WSDLServiceBuilder)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DataHandler (javax.activation.DataHandler)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1