Search in sources :

Example 56 with SOAPEnvelope

use of org.apache.axiom.soap.SOAPEnvelope in project wso2-axis2-transports by wso2.

the class SimpleInOutMessageReceiver method invokeBusinessLogic.

public void invokeBusinessLogic(MessageContext inMessageContext, MessageContext outMessageContext) throws AxisFault {
    log.debug("Got The message to the MessageReceiver");
    String soapNamespace = inMessageContext.getEnvelope().getNamespace().getNamespaceURI();
    // creating a soap factory according the the soap namespce uri
    SOAPFactory soapFactory = null;
    if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
        soapFactory = OMAbstractFactory.getSOAP11Factory();
    } else if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
        soapFactory = OMAbstractFactory.getSOAP12Factory();
    } else {
        System.out.println("Unknow soap message");
    }
    SOAPEnvelope responseEnvelope = soapFactory.getDefaultEnvelope();
    // creating a body element
    OMFactory omFactory = OMAbstractFactory.getOMFactory();
    OMNamespace omNamespace = omFactory.createOMNamespace("http://sms.test", "ns1");
    OMElement omElement = omFactory.createOMElement("Response", omNamespace);
    omElement.setText("Sucess");
    responseEnvelope.getBody().addChild(omElement);
    outMessageContext.setEnvelope(responseEnvelope);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 57 with SOAPEnvelope

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

the class ParserInputStreamDataSourceTests method updatePedsDataWithMockInputStream.

private void updatePedsDataWithMockInputStream(ParserInputStreamDataSource peds) throws Exception {
    SOAPEnvelope env = getMockEnvelope();
    SOAPBody body = env.getBody();
    Iterator iter = body.getChildElements();
    InputStream mockInputStream = null;
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    while (iter.hasNext()) {
        OMElement om = (OMElement) iter.next();
        om.serialize(os);
        byte[] bArray = os.toByteArray();
        mockInputStream = new ByteArrayInputStream(bArray);
        break;
    }
    ((Data) peds.getObject()).setInputStream(mockInputStream);
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) Data(org.apache.axiom.om.ds.ParserInputStreamDataSource.Data) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 58 with SOAPEnvelope

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

the class TestWrongParent2 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope parent = soapFactory.createSOAPEnvelope();
    OMElement child1 = soapFactory.createSOAPHeader(parent);
    SOAPFault fault = soapFactory.createSOAPFault();
    try {
        child1.insertSiblingAfter(fault);
        fail("Expected SOAPProcessingException");
    } catch (SOAPProcessingException ex) {
    // Expected
    }
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) OMElement(org.apache.axiom.om.OMElement) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 59 with SOAPEnvelope

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

the class TestAddDetailEntry method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPBody body = soapFactory.createSOAPBody(envelope);
    SOAPFault fault = soapFactory.createSOAPFault(body);
    SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail(fault);
    OMNamespace omNamespace = soapFactory.createOMNamespace("http://www.test.org", "test");
    soapFaultDetail.addDetailEntry(soapFactory.createOMElement("DetailEntry1", omNamespace));
    soapFaultDetail.addDetailEntry(soapFactory.createOMElement("DetailEntry2", omNamespace));
    Iterator<OMElement> iterator = soapFaultDetail.getAllDetailEntries();
    OMElement detailEntry1 = iterator.next();
    assertNotNull("SOAP Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns empty iterator", detailEntry1);
    assertEquals("SOAP Fault Detail Test : - detailEntry1 local name mismatch", "DetailEntry1", detailEntry1.getLocalName());
    assertEquals("SOAP Fault Detail Test : - detailEntry1 namespace uri mismatch", "http://www.test.org", detailEntry1.getNamespace().getNamespaceURI());
    OMElement detailEntry2 = iterator.next();
    assertNotNull("SOAP Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns an iterator with only one object", detailEntry2);
    assertEquals("SOAP Fault Detail Test : - detailEntry2 local name mismatch", "DetailEntry2", detailEntry2.getLocalName());
    assertEquals("SOAP Fault Detail Test : - detailEntry2 namespace uri mismatch", "http://www.test.org", detailEntry2.getNamespace().getNamespaceURI());
    assertFalse("SOAP Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns an iterator with three objects", iterator.hasNext());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) SOAPFault(org.apache.axiom.soap.SOAPFault) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 60 with SOAPEnvelope

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

the class TestGetAllDetailEntries method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPBody body = soapFactory.createSOAPBody(envelope);
    SOAPFault fault = soapFactory.createSOAPFault(body);
    SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail(fault);
    OMNamespace omNamespace = soapFactory.createOMNamespace("http://www.test.org", "test");
    Iterator<OMElement> iterator = soapFaultDetail.getAllDetailEntries();
    assertFalse("SOAP Fault Detail Test : - After creating SOAP11FaultDetail element, it has DetailEntries", iterator.hasNext());
    soapFaultDetail.addDetailEntry(soapFactory.createOMElement("DetailEntry", omNamespace));
    iterator = soapFaultDetail.getAllDetailEntries();
    OMElement detailEntry = iterator.next();
    assertNotNull("SOAP Fault Detail Test : - After calling addDetailEntry method, getAllDetailEntries method returns empty iterator", detailEntry);
    assertEquals("SOAP Fault Detail Test : - detailEntry local name mismatch", "DetailEntry", detailEntry.getLocalName());
    assertEquals("SOAP Fault Detail Test : - detailEntry namespace uri mismatch", "http://www.test.org", detailEntry.getNamespace().getNamespaceURI());
    assertFalse("SOAP Fault Detail Test : - After calling addDetailEntry method once, getAllDetailEntries method returns an iterator with two objects", iterator.hasNext());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) SOAPFault(org.apache.axiom.soap.SOAPFault) 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