Search in sources :

Example 66 with SOAPEnvelope

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

the class TestGetSOAPBodyFirstElementLocalNameAndNSWithParser method runTest.

@Override
protected void runTest() throws Throwable {
    // Prepare the message. Note that we do this programmatically to make sure that the message
    // doesn't contain any unwanted whitespace.
    SOAPEnvelope orgEnvelope = soapFactory.createDefaultSOAPMessage().getSOAPEnvelope();
    orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
    String message = orgEnvelope.toString();
    SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(message)).getSOAPEnvelope();
    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 request an XMLStreamReader. The LLOM implementation triggers some special processing
    // in this case (because the getSOAPBodyFirstElementXXX calls put the builder in lookahead
    // mode). This is a regression test for r631687 (AXIOM-282).
    XMLStreamReader reader = envelope.getXMLStreamReader(false);
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals("Envelope", reader.getLocalName());
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals("Body", reader.getLocalName());
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals(qname.getLocalPart(), reader.getLocalName());
    if (qname.getNamespaceURI().length() == 0) {
        assertNull(reader.getNamespaceURI());
    } else {
        assertEquals(qname.getNamespaceURI(), reader.getNamespaceURI());
    }
    String readerPrefix = reader.getPrefix();
    if (qname.getPrefix().length() == 0) {
        assertTrue(readerPrefix == null || readerPrefix.isEmpty());
    } else {
        assertEquals(qname.getPrefix(), readerPrefix);
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 67 with SOAPEnvelope

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

the class TestHasFault method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    assertFalse(envelope.hasFault());
    SOAPBody body = soapFactory.createSOAPBody(envelope);
    assertFalse(envelope.hasFault());
    body.addFault(new Exception("This an exception for testing"));
    assertTrue(envelope.hasFault());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 68 with SOAPEnvelope

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

the class TestGetDefaultFaultEnvelope method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.getDefaultFaultEnvelope();
    assertNotNull("Default FaultEnvelope must have a SOAPFault in it", envelope.getBody().getFault());
    assertNotNull("Default FaultEnvelope must have a SOAPFaultCode in it", envelope.getBody().getFault().getCode());
    if (spec == SOAPSpec.SOAP12) {
        assertNotNull("Default FaultEnvelope must have a SOAPFaultCodeValue in it", envelope.getBody().getFault().getCode().getValue());
    }
    assertNotNull("Default FaultEnvelope must have a SOAPFaultReason in it", envelope.getBody().getFault().getReason());
    if (spec == SOAPSpec.SOAP12) {
        assertNotNull("Default FaultEnvelope must have a SOAPFaultText in it", envelope.getBody().getFault().getReason().getFirstSOAPText());
    }
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 69 with SOAPEnvelope

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

the class TestAddHeaderBlockWithoutNamespace1 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPHeader header = soapFactory.createSOAPHeader(envelope);
    try {
        header.addHeaderBlock("test", null);
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMException(org.apache.axiom.om.OMException) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 70 with SOAPEnvelope

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

the class CloneTestCase method copyAndCheck.

/**
     * Make a copy of the source envelope and validate the target tree
     * @param sourceEnv
     * @throws Exception
     */
protected void copyAndCheck(SOAPEnvelope sourceEnv) throws Exception {
    SOAPCloneOptions options = new SOAPCloneOptions();
    options.setFetchDataHandlers(true);
    options.setPreserveModel(true);
    options.setCopyOMDataSources(true);
    SOAPEnvelope targetEnv = (SOAPEnvelope) sourceEnv.clone(options);
    identityCheck(sourceEnv, targetEnv, "");
    assertAbout(xml()).that(targetEnv.toString()).hasSameContentAs(sourceEnv.toString());
    sourceEnv.close(false);
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPCloneOptions(org.apache.axiom.soap.SOAPCloneOptions)

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