Search in sources :

Example 11 with SOAPEnvelope

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

the class TestGetHeadersToProcessWithNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPHeader header = soapFactory.createSOAPHeader(envelope);
    OMNamespace ns1 = soapFactory.createOMNamespace("urn:ns1", "ns1");
    OMNamespace ns2 = soapFactory.createOMNamespace("urn:ns2", "ns2");
    String myRole = "urn:myRole";
    String otherRole = "urn:otherRole";
    SOAPHeaderBlock headerBlock1 = header.addHeaderBlock("header1", ns1);
    headerBlock1.setRole(myRole);
    SOAPHeaderBlock headerBlock2 = header.addHeaderBlock("header2", ns2);
    headerBlock2.setRole(myRole);
    SOAPHeaderBlock headerBlock3 = header.addHeaderBlock("header3", ns1);
    headerBlock3.setRole(myRole);
    SOAPHeaderBlock headerBlock4 = header.addHeaderBlock("header4", ns1);
    headerBlock4.setRole(otherRole);
    Iterator<SOAPHeaderBlock> it = header.getHeadersToProcess(new MyRolePlayer(false, new String[] { myRole }), ns1.getNamespaceURI());
    assertTrue(it.hasNext());
    assertSame(headerBlock1, it.next());
    assertTrue(it.hasNext());
    assertSame(headerBlock3, it.next());
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 12 with SOAPEnvelope

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

the class TestBlobOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
    SOAPHeader soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
    String localName = "myPayload";
    String encoding = "utf-8";
    String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
    OMNamespace ns = soapFactory.createOMNamespace("urn://test", "tns");
    BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
    // Set an empty MustUnderstand property on the data source
    ds.setProperty(SOAPHeaderBlock.MUST_UNDERSTAND_PROPERTY, null);
    OMSourcedElement omse = soapFactory.createSOAPHeaderBlock(localName, ns, ds);
    soapHeader.addChild(omse);
    OMNode firstChild = soapHeader.getFirstOMChild();
    assertTrue("Expected OMSourcedElement child", firstChild instanceof SOAPHeaderBlock);
    SOAPHeaderBlock child = (SOAPHeaderBlock) firstChild;
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isSameAs(ds);
    // Make sure that getting the MustUnderstand property does not cause expansion.
    assertTrue(!child.getMustUnderstand());
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isSameAs(ds);
    // A BlobOMDataSource does not consume the backing object when read.
    // Thus getting the XMLStreamReader of the BlobOMDataSource should not 
    // cause expansion of the OMSourcedElement.
    XMLStreamReader reader = child.getXMLStreamReader();
    reader.next();
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    // Likewise, a BlobOMDataSource does not consume the backing object when 
    // written.  Thus serializing the OMSourcedElement should not cause the expansion
    // of the OMSourcedElement.
    assertTrue("The payload was not present in the output", soapHeader.toString().indexOf(payload) > 0);
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isSameAs(ds);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMNamespace(org.apache.axiom.om.OMNamespace) XMLStreamReader(javax.xml.stream.XMLStreamReader) BlobOMDataSource(org.apache.axiom.om.ds.BlobOMDataSource) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 13 with SOAPEnvelope

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

the class TestSerializeAsChild method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createDefaultSOAPMessage().getSOAPEnvelope();
    soapFactory.createOMElement("echo", soapFactory.createOMNamespace("urn:test", "p"), envelope.getBody());
    OMElement log = soapFactory.createOMElement("log", null);
    OMElement entry = soapFactory.createOMElement("entry", null, log);
    entry.addChild(envelope);
    MemoryBlob blob = Blobs.createMemoryBlob();
    OutputStream out = blob.getOutputStream();
    envelope.serialize(out);
    out.close();
    assertAbout(xml()).that(blob.getInputStream()).hasSameContentAs(xml(OMElement.class, envelope));
}
Also used : MemoryBlob(org.apache.axiom.blob.MemoryBlob) OutputStream(java.io.OutputStream) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 14 with SOAPEnvelope

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

the class TestCreateDefaultSOAPMessage method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = soapFactory.createDefaultSOAPMessage();
    SOAPEnvelope env = message.getSOAPEnvelope();
    assertNotNull(env);
    assertSame(env, message.getFirstOMChild());
    assertNull(env.getNextOMSibling());
    // Check correct SOAP version
    assertEquals(spec.getEnvelopeNamespaceURI(), env.getNamespaceURI());
    // Check the children
    Iterator<OMNode> it = env.getChildren();
    assertTrue(it.hasNext());
    OMNode child = it.next();
    assertTrue(child instanceof SOAPBody);
    assertNull(((SOAPBody) child).getFirstOMChild());
    assertFalse(it.hasNext());
}
Also used : OMNode(org.apache.axiom.om.OMNode) SOAPBody(org.apache.axiom.soap.SOAPBody) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPMessage(org.apache.axiom.soap.SOAPMessage)

Example 15 with SOAPEnvelope

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

the class TestCreateSOAPEnvelopeWithCustomPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    String prefix = "my-soap";
    OMNamespace ns = soapFactory.createOMNamespace(spec.getEnvelopeNamespaceURI(), prefix);
    SOAPEnvelope env = soapFactory.createSOAPEnvelope(ns);
    assertEquals(prefix, env.getNamespace().getPrefix());
    assertEquals(spec.getEnvelopeNamespaceURI(), env.getNamespace().getNamespaceURI());
    assertEquals(SOAPConstants.SOAPENVELOPE_LOCAL_NAME, env.getLocalName());
    Iterator<OMNamespace> it = env.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
    assertEquals(ns, it.next());
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) 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