Search in sources :

Example 56 with SOAPFactory

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

the class BinaryRelayBuilder method processDocument.

public OMElement processDocument(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
    try {
        // Fix for https://wso2.org/jira/browse/CARBON-7256
        messageContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
        // We will create a SOAP message, which holds the input message as a blob
        SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
        SOAPEnvelope env = factory.getDefaultEnvelope();
        if (inputStream != null) {
            OMNamespace ns = factory.createOMNamespace(RelayConstants.BINARY_CONTENT_QNAME.getNamespaceURI(), "ns");
            OMElement omEle = factory.createOMElement(RelayConstants.BINARY_CONTENT_QNAME.getLocalPart(), ns);
            StreamingOnRequestDataSource ds = new StreamingOnRequestDataSource(inputStream);
            DataHandler dataHandler = new DataHandler(ds);
            // create an OMText node with the above DataHandler and set optimized to true
            OMText textData = factory.createOMText(dataHandler, true);
            omEle.addChild(textData);
            env.getBody().addChild(omEle);
        }
        return env;
    } catch (SOAPProcessingException e) {
        throw AxisFault.makeFault(e);
    } catch (OMException e) {
        throw AxisFault.makeFault(e);
    }
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) DataHandler(javax.activation.DataHandler) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 57 with SOAPFactory

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

the class CalloutMediator 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();
                /* Convert only OMElements. Skip SOAPHeaderBlock elements*/
                if (!(element instanceof SOAPHeaderBlock)) {
                    if (element instanceof OMElement) {
                        newHeaderNodes.add(ElementHelper.toSOAPHeaderBlock((OMElement) element, fac).cloneOMElement());
                    }
                    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) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) SOAPFactory(org.apache.axiom.soap.SOAPFactory) JaxenException(org.jaxen.JaxenException) NamingException(javax.naming.NamingException) SynapseException(org.apache.synapse.SynapseException) OMException(org.apache.axiom.om.OMException)

Example 58 with SOAPFactory

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

the class CommonScriptMessageContext method addHeader.

/**
 * Add a new SOAP header to the message.
 *
 * @param mustUnderstand the value for the <code>soapenv:mustUnderstand</code> attribute
 * @param content the XML for the new header
 * @throws ScriptException if an error occurs when converting the XML to OM
 */
@Override
public void addHeader(boolean mustUnderstand, Object content) throws ScriptException {
    SOAPEnvelope envelope = mc.getEnvelope();
    SOAPFactory factory = (SOAPFactory) envelope.getOMFactory();
    SOAPHeader header = envelope.getHeader();
    if (header == null) {
        header = factory.createSOAPHeader(envelope);
    }
    OMElement element = xmlHelper.toOMElement(content);
    // We can't add the element directly to the SOAPHeader. Instead, we need to copy the
    // information over to a SOAPHeaderBlock.
    SOAPHeaderBlock headerBlock = header.addHeaderBlock(element.getLocalName(), element.getNamespace());
    for (Iterator it = element.getAllAttributes(); it.hasNext(); ) {
        headerBlock.addAttribute((OMAttribute) it.next());
    }
    headerBlock.setMustUnderstand(mustUnderstand);
    OMNode child = element.getFirstOMChild();
    while (child != null) {
        // Get the next child before addChild will detach the node from its original place.
        OMNode next = child.getNextOMSibling();
        headerBlock.addChild(child);
        child = next;
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 59 with SOAPFactory

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

the class HessianTestHelper method addSoapFaultToMessageContext.

public void addSoapFaultToMessageContext(MessageContext msgContext, String faultCode, String faultReason, String faultDetail) throws AxisFault {
    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
    SOAPFault soapFault = faultEnvelope.getBody().getFault();
    SOAPFaultCode soapFaultCode = factory.createSOAPFaultCode();
    soapFaultCode.setText(faultCode);
    soapFault.setCode(soapFaultCode);
    SOAPFaultReason soapFaultReason = factory.createSOAPFaultReason();
    soapFaultReason.setText(faultReason);
    soapFault.setReason(soapFaultReason);
    SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
    soapFaultDetail.setText(faultDetail);
    soapFault.setDetail(soapFaultDetail);
    msgContext.setEnvelope(faultEnvelope);
}
Also used : SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 60 with SOAPFactory

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

the class SOAPConversionTest method getSOAP12Envelope.

private SOAPEnvelope getSOAP12Envelope() {
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope envelope = fac.getDefaultEnvelope();
    envelope.getBody().addChild(createPayload(fac));
    populateHeader(envelope, fac);
    return envelope;
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Aggregations

SOAPFactory (org.apache.axiom.soap.SOAPFactory)70 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)50 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 AxisFault (org.apache.axis2.AxisFault)11 MessageContext (org.apache.axis2.context.MessageContext)11 DataHandler (javax.activation.DataHandler)10 OMNamespace (org.apache.axiom.om.OMNamespace)9 SOAPHeader (org.apache.axiom.soap.SOAPHeader)9 SynapseException (org.apache.synapse.SynapseException)9 Iterator (java.util.Iterator)8 OMNode (org.apache.axiom.om.OMNode)7 SOAPFault (org.apache.axiom.soap.SOAPFault)7 IOException (java.io.IOException)6 EndpointReference (org.apache.axis2.addressing.EndpointReference)6 ArrayList (java.util.ArrayList)5 XMLStreamException (javax.xml.stream.XMLStreamException)4 OMAttribute (org.apache.axiom.om.OMAttribute)4