Search in sources :

Example 26 with SOAPBody

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

the class FirstElementNameWithParserTestCase method runTest.

@Override
protected final void runTest() throws Throwable {
    SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
    orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
    SOAPBody body = builder.getSOAPEnvelope().getBody();
    runTest(body);
    if (supportsOptimization) {
        // The expectation is that even after looking at the payload element name, registering
        // a custom builder still transforms the element.
        ((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {

            @Override
            public OMDataSource create(OMElement element) throws OMException {
                try {
                    element.getXMLStreamReaderWithoutCaching().close();
                } catch (XMLStreamException ex) {
                    throw new OMException(ex);
                }
                return new AbstractPushOMDataSource() {

                    @Override
                    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
                        xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
                    }

                    @Override
                    public boolean isDestructiveWrite() {
                        return false;
                    }
                };
            }
        });
        assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
    }
}
Also used : OMDataSource(org.apache.axiom.om.OMDataSource) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) SOAPBody(org.apache.axiom.soap.SOAPBody) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StringReader(java.io.StringReader) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) OMException(org.apache.axiom.om.OMException)

Example 27 with SOAPBody

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

the class TestAddFault1 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPBody body = soapFactory.createSOAPBody(envelope);
    body.addFault(new Exception("This an exception for testing"));
    assertTrue("Body Test:- After calling addFault method, SOAP body has no fault", body.hasFault());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 28 with SOAPBody

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

the class TestHasFaultWithParser method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    SOAPBody body = envelope.getBody();
    assertTrue("Body Test With parser :- hasFault method returns false", body.hasFault());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody)

Example 29 with SOAPBody

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

the class TestGetFault method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPBody body = soapFactory.createSOAPBody(envelope);
    assertNull("Body Test:- After creating a soap body it has a fault", body.getFault());
    body.addFault(new Exception("This an exception for testing"));
    assertNotNull("Body Test:- After calling addFault method, getFault method returns null", body.getFault());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 30 with SOAPBody

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

the class TestCloneOMElement method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    SOAPBody body = envelope.getBody();
    OMElement firstClonedBodyElement = body.cloneOMElement();
    OMElement secondClonedBodyElement = body.cloneOMElement();
    // cloneOMElement creates plain OMElements
    assertFalse(firstClonedBodyElement instanceof SOAPBody);
    assertFalse(secondClonedBodyElement instanceof SOAPBody);
    // first check whether both have the same information
    assertAbout(xml()).that(xml(OMElement.class, firstClonedBodyElement)).ignoringNamespaceDeclarations().hasSameContentAs(xml(OMElement.class, body));
    assertAbout(xml()).that(xml(OMElement.class, secondClonedBodyElement)).ignoringNamespaceDeclarations().hasSameContentAs(xml(OMElement.class, body));
    assertAbout(xml()).that(xml(OMElement.class, secondClonedBodyElement)).hasSameContentAs(xml(OMElement.class, firstClonedBodyElement));
    // The clone is expected to be orphaned
    assertNull(firstClonedBodyElement.getParent());
    assertNull(secondClonedBodyElement.getParent());
    envelope.close(false);
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMElement(org.apache.axiom.om.OMElement)

Aggregations

SOAPBody (org.apache.axiom.soap.SOAPBody)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)24 OMElement (org.apache.axiom.om.OMElement)13 SOAPFault (org.apache.axiom.soap.SOAPFault)7 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)7 OMNamespace (org.apache.axiom.om.OMNamespace)6 QName (javax.xml.namespace.QName)5 SOAPHeader (org.apache.axiom.soap.SOAPHeader)5 StringReader (java.io.StringReader)4 OMNode (org.apache.axiom.om.OMNode)4 SOAPFactory (org.apache.axiom.soap.SOAPFactory)4 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)4 OMDataSource (org.apache.axiom.om.OMDataSource)3 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)3 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)3 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)3 SOAPFaultReason (org.apache.axiom.soap.SOAPFaultReason)3 SOAPFaultRole (org.apache.axiom.soap.SOAPFaultRole)3 StringWriter (java.io.StringWriter)2 Iterator (java.util.Iterator)2