Search in sources :

Example 31 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class SOAPSampleAdapter method getSOAPEnvelope.

public SOAPEnvelope getSOAPEnvelope(OMMetaFactory metaFactory) {
    SOAPEnvelope envelope = getBuilder(metaFactory).getSOAPEnvelope();
    // TODO: this is not the right place to assert this
    Assert.assertSame(sample.getSOAPSpec().getEnvelopeNamespaceURI(), ((SOAPFactory) envelope.getOMFactory()).getSoapVersionURI());
    return envelope;
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 32 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class TestRegisterCustomBuilderForPayload method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPModelBuilder builder = message.getAdapter(SOAPSampleAdapter.class).getBuilder(metaFactory);
    ((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    OMElement payload = envelope.getBody().getFirstElement();
    if (message.getPayload() == null) {
        assertThat(payload).isNull();
    } else if (message.getPayload().getLocalName().equals("Fault")) {
        assertThat(payload).isInstanceOf(SOAPFault.class);
    } else {
        assertThat(payload).isInstanceOf(OMSourcedElement.class);
        BlobOMDataSource.Data data = (BlobOMDataSource.Data) ((OMSourcedElement) payload).getObject(BlobOMDataSource.class);
        assertThat(data).isNotNull();
        InputSource is = new InputSource(data.getBlob().getInputStream());
        is.setEncoding(data.getEncoding());
        assertAbout(xml()).that(is).ignoringNamespaceDeclarations().hasSameContentAs(message.getPayloadInputSource());
    }
    // We need to ignore redundant namespace declarations because the custom builder needs
    // to preserve the namespace context when serializing to the blob.
    assertAbout(xml()).that(envelope.getXMLStreamReader(false)).ignoringPrologAndEpilog().ignoringRedundantNamespaceDeclarations().hasSameContentAs(message.getInputStream());
    if (payload instanceof OMSourcedElement) {
        assertThat(((OMSourcedElement) payload).isExpanded()).isFalse();
    }
}
Also used : InputSource(org.xml.sax.InputSource) BlobOMDataSource(org.apache.axiom.om.ds.BlobOMDataSource) SOAPSampleAdapter(org.apache.axiom.ts.soap.SOAPSampleAdapter) CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) BlobOMDataSourceCustomBuilder(org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 33 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class TestAddElementAfterBody method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope env = soapFactory.createSOAPEnvelope();
    if (header) {
        soapFactory.createSOAPHeader(env);
    }
    soapFactory.createSOAPBody(env);
    OMElement elem = env.getOMFactory().createOMElement(new QName("foo"));
    if (spec.isAllowsElementsAfterBody()) {
        env.addChild(elem);
    } else {
        try {
            env.addChild(elem);
            fail("Expected SOAPProcessingException");
        } catch (SOAPProcessingException ex) {
        // expected
        }
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 34 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class TestCloneWithSourcedElement1 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope sourceEnv = soapFactory.getDefaultEnvelope();
    SOAPBody body = sourceEnv.getBody();
    // Create a payload
    OMDataSource bads = new StringOMDataSource("<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>");
    OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
    OMSourcedElement omse = body.getOMFactory().createOMElement(bads, "payload", ns);
    body.addChild(omse);
    copyAndCheck(sourceEnv);
    assertFalse(omse.isExpanded());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 35 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project webservices-axiom by apache.

the class TestGetSOAPBodyFirstElementLocalNameAndNS method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    OMElement bodyElement = soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix());
    envelope.getBody().addChild(bodyElement);
    assertEquals(qname.getLocalPart(), envelope.getSOAPBodyFirstElementLocalName());
    OMNamespace ns = envelope.getSOAPBodyFirstElementNS();
    if (qname.getNamespaceURI().length() == 0) {
        assertNull(ns);
    } else {
        assertEquals(qname.getNamespaceURI(), ns.getNamespaceURI());
        assertEquals(qname.getPrefix(), ns.getPrefix());
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Aggregations

SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)105 OMElement (org.apache.axiom.om.OMElement)32 SOAPBody (org.apache.axiom.soap.SOAPBody)24 OMNamespace (org.apache.axiom.om.OMNamespace)22 SOAPHeader (org.apache.axiom.soap.SOAPHeader)20 SOAPFactory (org.apache.axiom.soap.SOAPFactory)18 QName (javax.xml.namespace.QName)16 SOAPFault (org.apache.axiom.soap.SOAPFault)14 ByteArrayInputStream (java.io.ByteArrayInputStream)12 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)12 OMNode (org.apache.axiom.om.OMNode)11 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)11 MessageContext (org.apache.axis2.context.MessageContext)10 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)8 InputStream (java.io.InputStream)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 StringReader (java.io.StringReader)6 DataHandler (javax.activation.DataHandler)6 OMException (org.apache.axiom.om.OMException)6