Search in sources :

Example 96 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class SoapOutInterceptor method writeSoapEnvelopeStart.

private void writeSoapEnvelopeStart(final SoapMessage message) {
    final SoapVersion soapVersion = message.getVersion();
    try {
        XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
        String soapPrefix = xtw.getPrefix(soapVersion.getNamespace());
        if (StringUtils.isEmpty(soapPrefix)) {
            soapPrefix = "soap";
        }
        if (message.hasAdditionalEnvNs()) {
            Map<String, String> nsMap = message.getEnvelopeNs();
            for (Map.Entry<String, String> entry : nsMap.entrySet()) {
                if (soapVersion.getNamespace().equals(entry.getValue())) {
                    soapPrefix = entry.getKey();
                }
            }
            xtw.setPrefix(soapPrefix, soapVersion.getNamespace());
            xtw.writeStartElement(soapPrefix, soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace());
            xtw.writeNamespace(soapPrefix, soapVersion.getNamespace());
            for (Map.Entry<String, String> entry : nsMap.entrySet()) {
                if (!soapVersion.getNamespace().equals(entry.getValue())) {
                    xtw.writeNamespace(entry.getKey(), entry.getValue());
                }
            }
        } else {
            xtw.setPrefix(soapPrefix, soapVersion.getNamespace());
            xtw.writeStartElement(soapPrefix, soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace());
            String s2 = xtw.getPrefix(soapVersion.getNamespace());
            if (StringUtils.isEmpty(s2) || soapPrefix.equals(s2)) {
                xtw.writeNamespace(soapPrefix, soapVersion.getNamespace());
            } else {
                soapPrefix = s2;
            }
        }
        boolean preexistingHeaders = message.hasHeaders();
        if (preexistingHeaders) {
            xtw.writeStartElement(soapPrefix, soapVersion.getHeader().getLocalPart(), soapVersion.getNamespace());
            List<Header> hdrList = message.getHeaders();
            for (Header header : hdrList) {
                XMLStreamWriter writer = xtw;
                if (xtw instanceof W3CDOMStreamWriter) {
                    Element nd = ((W3CDOMStreamWriter) xtw).getCurrentNode();
                    if (header.getObject() instanceof Element && nd.isSameNode(((Element) header.getObject()).getParentNode())) {
                        continue;
                    }
                }
                if (header instanceof SoapHeader) {
                    SoapHeader soapHeader = (SoapHeader) header;
                    writer = new SOAPHeaderWriter(xtw, soapHeader, soapVersion, soapPrefix);
                }
                DataBinding b = header.getDataBinding();
                if (b == null) {
                    HeaderProcessor hp = bus.getExtension(HeaderManager.class).getHeaderProcessor(header.getName().getNamespaceURI());
                    if (hp != null) {
                        b = hp.getDataBinding();
                    }
                }
                if (b != null) {
                    MessagePartInfo part = new MessagePartInfo(header.getName(), null);
                    part.setConcreteName(header.getName());
                    b.createWriter(XMLStreamWriter.class).write(header.getObject(), part, writer);
                } else {
                    Element node = (Element) header.getObject();
                    StaxUtils.copy(node, writer);
                }
            }
        }
        boolean endedHeader = handleHeaderPart(preexistingHeaders, message, soapPrefix);
        if (preexistingHeaders && !endedHeader) {
            xtw.writeEndElement();
        }
        xtw.writeStartElement(soapPrefix, soapVersion.getBody().getLocalPart(), soapVersion.getNamespace());
    // Interceptors followed such as Wrapped/RPC/Doc Interceptor will write SOAP body
    } catch (XMLStreamException e) {
        throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
    }
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) SoapFault(org.apache.cxf.binding.soap.SoapFault) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) HeaderProcessor(org.apache.cxf.headers.HeaderProcessor) Element(org.w3c.dom.Element) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) HeaderManager(org.apache.cxf.headers.HeaderManager) SoapVersion(org.apache.cxf.binding.soap.SoapVersion) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Header(org.apache.cxf.headers.Header) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) DelegatingXMLStreamWriter(org.apache.cxf.staxutils.DelegatingXMLStreamWriter) DataBinding(org.apache.cxf.databinding.DataBinding) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Map(java.util.Map)

Example 97 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class ServiceModelUtilTest method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    BindingInfo bindingInfo = null;
    bindingInfo = serviceInfo.getBindings().iterator().next();
    QName name = new QName(serviceInfo.getName().getNamespaceURI(), "inHeader");
    BindingOperationInfo inHeader = bindingInfo.getOperation(name);
    BindingMessageInfo input = inHeader.getInput();
    assertNotNull(input);
    assertEquals(input.getMessageInfo().getName().getLocalPart(), "inHeaderRequest");
    assertEquals(input.getMessageInfo().getName().getNamespaceURI(), "http://org.apache.cxf/headers");
    assertEquals(input.getMessageInfo().getMessageParts().size(), 2);
    assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
    assertEquals(input.getMessageInfo().getMessageParts().get(0).getElementQName().getLocalPart(), "inHeader");
    assertEquals(input.getMessageInfo().getMessageParts().get(0).getElementQName().getNamespaceURI(), "http://org.apache.cxf/headers");
    assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
    assertEquals(input.getMessageInfo().getMessageParts().get(1).getElementQName().getLocalPart(), "passenger");
    assertEquals(input.getMessageInfo().getMessageParts().get(1).getElementQName().getNamespaceURI(), "http://mycompany.example.com/employees");
    assertTrue(input.getMessageInfo().getMessageParts().get(1).isElement());
    MessagePartInfo messagePartInfo = input.getMessageInfo().getMessageParts().get(0);
    SchemaInfo schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
    assertEquals(schemaInfo.getNamespaceURI(), "http://org.apache.cxf/headers");
    messagePartInfo = input.getMessageInfo().getMessageParts().get(1);
    schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
    assertEquals(schemaInfo.getNamespaceURI(), "http://mycompany.example.com/employees");
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) QName(javax.xml.namespace.QName) BindingInfo(org.apache.cxf.service.model.BindingInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) Test(org.junit.Test)

Example 98 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo 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)

Example 99 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo 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 100 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class XMLMessageInInterceptor method getBindingOperationInfo.

private BindingOperationInfo getBindingOperationInfo(boolean isRequestor, QName startQName, BindingInfo bi, XMLStreamReader xsr) {
    for (BindingOperationInfo boi : bi.getOperations()) {
        BindingMessageInfo bmi;
        if (!isRequestor) {
            bmi = boi.getInput();
        } else {
            bmi = boi.getOutput();
        }
        if (hasRootNode(bmi, startQName)) {
            // Consume The rootNode tag
            try {
                xsr.nextTag();
            } catch (XMLStreamException xse) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", LOG));
            }
            return boi;
        }
        Collection<MessagePartInfo> bodyParts = bmi.getMessageParts();
        if (bodyParts.size() == 1) {
            MessagePartInfo p = bodyParts.iterator().next();
            if (p.getConcreteName().equals(startQName)) {
                return boi;
            }
        }
    }
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (startQName.equals(boi.getName())) {
            // Consume The rootNode tag
            try {
                xsr.nextTag();
            } catch (XMLStreamException xse) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", LOG));
            }
            return boi;
        }
    }
    return null;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) Message(org.apache.cxf.message.Message) XMLFault(org.apache.cxf.binding.xml.XMLFault) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)157 QName (javax.xml.namespace.QName)97 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)44 Test (org.junit.Test)38 MessageInfo (org.apache.cxf.service.model.MessageInfo)36 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)27 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 Fault (org.apache.cxf.interceptor.Fault)20 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)18 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)12 FaultInfo (org.apache.cxf.service.model.FaultInfo)11