Search in sources :

Example 41 with SOAPFactory

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

the class ConvertLLOMToDOOMTest method testAddChild.

public void testAddChild() {
    SOAPFactory fac = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    fac.createOMElement(new QName("http://test.org", "Test"), env.getBody());
    env.build();
    SOAPFactory llomFac = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getSOAP11Factory();
    OMElement elem = llomFac.createOMElement("newDomElement", null);
    OMElement firstElement = env.getBody().getFirstElement();
    firstElement.addChild(elem);
    assertTrue("New DOM child missing", env.toString().indexOf("newDomElement") > 0);
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 42 with SOAPFactory

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

the class MTOMLogSample method test.

// END SNIPPET: variant2
public void test() throws XMLStreamException {
    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = factory.createDefaultSOAPMessage().getSOAPEnvelope();
    OMElement element = factory.createOMElement(new QName("urn:testService", "invokeMtom", "ns"), env.getBody());
    element.addChild(factory.createOMText(new DataHandler("test", "text/xml"), true));
    logMessage(env);
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) DataHandler(javax.activation.DataHandler) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 43 with SOAPFactory

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

the class SOAPElementTypeAdapterFactory method createAdapters.

@Override
public void createAdapters(SOAPElementType type, Adapters adapters) {
    if (type == SOAPElementType.ENVELOPE) {
        adapters.add(new SOAPElementTypeAdapter(SOAPEnvelope.class, null, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPEnvelope();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                throw new UnsupportedOperationException();
            }
        });
    } else if (type == SOAPElementType.HEADER) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPEnvelope) parent).getHeader();
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPHeader.class, getter, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPHeader();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPHeader((SOAPEnvelope) parent);
            }
        });
    } else if (type == SOAPElementType.BODY) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPEnvelope) parent).getBody();
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPBody.class, getter, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPBody();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPBody((SOAPEnvelope) parent);
            }
        });
    } else if (type == SOAPElementType.FAULT) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPBody) parent).getFault();
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFault.class, getter, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFault();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFault((SOAPBody) parent);
            }
        });
    } else if (type == SOAPFaultChild.CODE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getCode();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setCode((SOAPFaultCode) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultCode.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultCode();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultCode((SOAPFault) parent);
            }
        });
    } else if (type == SOAPElementType.VALUE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFaultClassifier) parent).getValue();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFaultClassifier) parent).setValue((SOAPFaultValue) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultValue.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultValue();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                if (parentType == SOAPFaultChild.CODE) {
                    return factory.createSOAPFaultValue((SOAPFaultCode) parent);
                } else {
                    return factory.createSOAPFaultValue((SOAPFaultSubCode) parent);
                }
            }
        });
    } else if (type == SOAPElementType.SUB_CODE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFaultClassifier) parent).getSubCode();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFaultClassifier) parent).setSubCode((SOAPFaultSubCode) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultSubCode.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultSubCode();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                if (parentType == SOAPFaultChild.CODE) {
                    return factory.createSOAPFaultSubCode((SOAPFaultCode) parent);
                } else {
                    return factory.createSOAPFaultSubCode((SOAPFaultSubCode) parent);
                }
            }
        });
    } else if (type == SOAPFaultChild.REASON) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getReason();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setReason((SOAPFaultReason) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultReason.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultReason();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultReason((SOAPFault) parent);
            }
        });
    } else if (type == SOAPElementType.TEXT) {
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultText.class, null, null) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultText();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultText((SOAPFaultReason) parent);
            }
        });
    } else if (type == SOAPFaultChild.NODE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getNode();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setNode((SOAPFaultNode) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultNode.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultNode();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultNode((SOAPFault) parent);
            }
        });
    } else if (type == SOAPFaultChild.ROLE) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getRole();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setRole((SOAPFaultRole) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultRole.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultRole();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultRole((SOAPFault) parent);
            }
        });
    } else if (type == SOAPFaultChild.DETAIL) {
        Getter getter = new Getter() {

            @Override
            public OMElement invoke(OMElement parent) {
                return ((SOAPFault) parent).getDetail();
            }
        };
        Setter setter = new Setter() {

            @Override
            public void invoke(OMElement parent, OMElement child) {
                ((SOAPFault) parent).setDetail((SOAPFaultDetail) child);
            }
        };
        adapters.add(new SOAPElementTypeAdapter(SOAPFaultDetail.class, getter, setter) {

            @Override
            public OMElement create(SOAPFactory factory) {
                return factory.createSOAPFaultDetail();
            }

            @Override
            public OMElement create(SOAPFactory factory, SOAPElementType parentType, OMElement parent) {
                return factory.createSOAPFaultDetail((SOAPFault) parent);
            }
        });
    }
}
Also used : SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) SOAPFaultRole(org.apache.axiom.soap.SOAPFaultRole) Getter(org.apache.axiom.ts.soap.SOAPElementTypeAdapter.Getter) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultValue(org.apache.axiom.soap.SOAPFaultValue) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFaultText(org.apache.axiom.soap.SOAPFaultText) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPFaultSubCode(org.apache.axiom.soap.SOAPFaultSubCode) SOAPBody(org.apache.axiom.soap.SOAPBody) Setter(org.apache.axiom.ts.soap.SOAPElementTypeAdapter.Setter) SOAPFaultClassifier(org.apache.axiom.soap.SOAPFaultClassifier) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPFaultNode(org.apache.axiom.soap.SOAPFaultNode)

Example 44 with SOAPFactory

use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.

the class LoadbalanceFailoverClient method buildSoapEnvelope.

private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);
    OMNamespace synNamespace = soapFactory.createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);
    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);
    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);
    return envelope;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPBody(org.apache.axiom.soap.SOAPBody) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 45 with SOAPFactory

use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.

the class MTOMSwAClient method sendUsingSwA.

public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException {
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingSwA");
    options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
    ServiceClient sender = createServiceClient();
    sender.setOptions(options);
    OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);
    MessageContext mc = new MessageContext();
    System.out.println("Sending file : " + fileName + " as SwA");
    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    String attachmentID = mc.addAttachment(dataHandler);
    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = factory.getDefaultEnvelope();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement imageId = factory.createOMElement("imageId", ns);
    imageId.setText(attachmentID);
    request.addChild(imageId);
    payload.addChild(request);
    env.getBody().addChild(payload);
    mc.setEnvelope(env);
    mepClient.addMessageContext(mc);
    mepClient.execute(true);
    MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    SOAPBody body = response.getEnvelope().getBody();
    String imageContentId = body.getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")).getFirstChildWithName(new QName("http://services.samples", "response")).getFirstChildWithName(new QName("http://services.samples", "imageId")).getText();
    Attachments attachment = response.getAttachmentMap();
    dataHandler = attachment.getDataHandler(imageContentId);
    File tempFile = File.createTempFile("swa-", ".gif");
    FileOutputStream fos = new FileOutputStream(tempFile);
    dataHandler.writeTo(fos);
    fos.flush();
    fos.close();
    System.out.println("Saved response to file : " + tempFile.getAbsolutePath());
    return response;
}
Also used : Options(org.apache.axis2.client.Options) OperationClient(org.apache.axis2.client.OperationClient) QName(javax.xml.namespace.QName) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Attachments(org.apache.axiom.attachments.Attachments) SOAPFactory(org.apache.axiom.soap.SOAPFactory) EndpointReference(org.apache.axis2.addressing.EndpointReference) SOAPBody(org.apache.axiom.soap.SOAPBody) ServiceClient(org.apache.axis2.client.ServiceClient) FileDataSource(javax.activation.FileDataSource) MessageContext(org.apache.axis2.context.MessageContext)

Aggregations

SOAPFactory (org.apache.axiom.soap.SOAPFactory)69 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)49 OMElement (org.apache.axiom.om.OMElement)38 QName (javax.xml.namespace.QName)16 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)14 SOAPBody (org.apache.axiom.soap.SOAPBody)12 MessageContext (org.apache.axis2.context.MessageContext)11 DataHandler (javax.activation.DataHandler)10 AxisFault (org.apache.axis2.AxisFault)10 OMNamespace (org.apache.axiom.om.OMNamespace)9 SOAPHeader (org.apache.axiom.soap.SOAPHeader)9 SynapseException (org.apache.synapse.SynapseException)8 Iterator (java.util.Iterator)7 OMNode (org.apache.axiom.om.OMNode)7 SOAPFault (org.apache.axiom.soap.SOAPFault)7 EndpointReference (org.apache.axis2.addressing.EndpointReference)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 OMAttribute (org.apache.axiom.om.OMAttribute)4