Search in sources :

Example 21 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 22 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 23 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 24 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 25 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)86 OMElement (org.apache.axiom.om.OMElement)28 SOAPBody (org.apache.axiom.soap.SOAPBody)23 OMNamespace (org.apache.axiom.om.OMNamespace)20 SOAPHeader (org.apache.axiom.soap.SOAPHeader)20 SOAPFault (org.apache.axiom.soap.SOAPFault)14 QName (javax.xml.namespace.QName)12 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)12 OMNode (org.apache.axiom.om.OMNode)11 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)11 SOAPFactory (org.apache.axiom.soap.SOAPFactory)10 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)8 StringReader (java.io.StringReader)7 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataHandler (javax.activation.DataHandler)6 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 MultipartBody (org.apache.axiom.mime.MultipartBody)5 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)5