Search in sources :

Example 16 with SOAPFactory

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

the class SamplingService method setSoapHeaderBlock.

private void setSoapHeaderBlock(MessageContext synCtx) {
    // Send the SOAP Header Blocks to support WS-Addressing
    if (synCtx.getEnvelope().getHeader() != null) {
        Iterator iHeader = synCtx.getEnvelope().getHeader().getChildren();
        SOAPFactory fac;
        if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(synCtx.getEnvelope().getBody().getNamespace().getNamespaceURI())) {
            fac = OMAbstractFactory.getSOAP11Factory();
        } else {
            fac = OMAbstractFactory.getSOAP12Factory();
        }
        List<OMNode> newHeaderNodes = new ArrayList<OMNode>();
        while (iHeader.hasNext()) {
            try {
                Object element = iHeader.next();
                if (!(element instanceof SOAPHeaderBlock)) {
                    if (element instanceof OMElement) {
                        newHeaderNodes.add(ElementHelper.toSOAPHeaderBlock((OMElement) element, fac));
                    }
                    iHeader.remove();
                }
            } catch (OMException e) {
                log.error("Unable to convert to SoapHeader Block", e);
            } catch (Exception e) {
                log.error("Unable to convert to SoapHeader Block", e);
            }
        }
        for (OMNode newHeaderNode : newHeaderNodes) {
            synCtx.getEnvelope().getHeader().addChild(newHeaderNode);
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SynapseException(org.apache.synapse.SynapseException) OMException(org.apache.axiom.om.OMException)

Example 17 with SOAPFactory

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

the class MessageConverter method getSoapEnvelope.

private static SOAPEnvelope getSoapEnvelope(String soapEnvelpe) {
    OMElement response;
    try {
        response = AXIOMUtil.stringToOM(soapEnvelpe);
    } catch (Exception e) {
        logger.error("Cannot create SOAP Envelop. Error:" + e.getLocalizedMessage(), e);
        return null;
    }
    SOAPFactory soapFactory;
    String soapNamespace = response.getNamespace().getNamespaceURI();
    if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
        soapFactory = OMAbstractFactory.getSOAP12Factory();
    } else {
        soapFactory = OMAbstractFactory.getSOAP11Factory();
    }
    SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
    // Set the headers of the message
    if (response.getFirstElement().getLocalName().contains(HEADER_STRING)) {
        SOAPHeader header = soapEnvelope.getHeader();
        SOAPFactory fac = (SOAPFactory) soapEnvelope.getOMFactory();
        Iterator headers = response.getFirstElement().getChildElements();
        while (headers.hasNext()) {
            OMElement soapHeader = (OMElement) headers.next();
            SOAPHeaderBlock hb = header.addHeaderBlock(soapHeader.getLocalName(), fac.createOMNamespace(soapHeader.getNamespace().getNamespaceURI(), soapHeader.getNamespace().getPrefix()));
            hb.setText(soapHeader.getText());
            // Add the child elements of the header (if any)
            Iterator elements = soapHeader.getChildElements();
            while (elements.hasNext()) {
                hb.addChild((OMNode) elements.next());
            }
        }
        response.getFirstElement().detach();
    }
    if (response.getFirstElement().getFirstElement() != null) {
        soapEnvelope.getBody().addChild(response.getFirstElement().getFirstElement());
    }
    return soapEnvelope;
}
Also used : Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 18 with SOAPFactory

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

the class AXIOMUtils method getSOAPEnvFromOM.

/**
 * @param omElement OMElement which need to convert to SOAPEnvelope
 * @return SOAPEnvelope with contents of passed OMElement
 */
public static SOAPEnvelope getSOAPEnvFromOM(OMElement omElement) {
    SOAPFactory soapFactory;
    if (omElement.getQName().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
        soapFactory = OMAbstractFactory.getSOAP12Factory();
    } else {
        soapFactory = OMAbstractFactory.getSOAP11Factory();
    }
    StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(omElement.getXMLStreamReader(), soapFactory, omElement.getQName().getNamespaceURI());
    return builder.getSOAPEnvelope();
}
Also used : StAXSOAPModelBuilder(org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 19 with SOAPFactory

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

the class RelaySecuirtyMessageBuilderDispatchandler method build.

private void build(MessageContext messageContext) {
    try {
        RelayUtils.buildMessage(messageContext, false);
        if (messageContext.getEnvelope().getHeader() == null) {
            SOAPFactory fac = messageContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
            fac.createSOAPHeader(messageContext.getEnvelope());
        }
    } catch (Exception e) {
        log.error("Error while executing the message at relaySecurity handler", e);
    }
}
Also used : SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 20 with SOAPFactory

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

the class SourceTextRetrieverTest method testSOAPEnvelopeTextRetriever.

public void testSOAPEnvelopeTextRetriever() throws Exception {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    OMElement payload = AXIOMUtil.stringToOM(fac, "<getQuote id=\"attr\"><symbol>TEST</symbol><property>1</property>" + "<property>2</property></getQuote>");
    env.getBody().addChild(payload);
    MessageContext msgCtx = new MessageContext();
    msgCtx.setEnvelope(env);
    EvaluatorContext context = new EvaluatorContext(null, null);
    context.setMessageContext(msgCtx);
    SOAPEnvelopeTextRetriever txtRtvr = new SOAPEnvelopeTextRetriever("//symbol");
    assertEquals("TEST", txtRtvr.getSourceText(context));
    txtRtvr = new SOAPEnvelopeTextRetriever("//getQuote/@id");
    assertEquals("attr", txtRtvr.getSourceText(context));
    txtRtvr = new SOAPEnvelopeTextRetriever("//property[1]");
    assertEquals("1", txtRtvr.getSourceText(context));
    txtRtvr = new SOAPEnvelopeTextRetriever("//property[2]");
    assertEquals("2", txtRtvr.getSourceText(context));
}
Also used : EvaluatorContext(org.apache.synapse.commons.evaluators.EvaluatorContext) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.axis2.context.MessageContext) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

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