Search in sources :

Example 61 with SOAPFactory

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

the class SOAPConversionTest method getSOAP11Envelope.

private SOAPEnvelope getSOAP11Envelope() {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    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)

Example 62 with SOAPFactory

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

the class FIXUtils method setSOAPEnvelope.

/**
 * FIX messages are non-XML. So convert them into XML using the AXIOM API.
 * Put the FIX message into an Axis2 MessageContext.The basic format of the
 * generated SOAP envelope;
 * <p/>
 * <soapEnvelope>
 * <soapBody>
 * <message>
 * <header> ....</header>
 * <body> .... </body>
 * <trailer> .... </trailer>
 * </message>
 * </soapBody>
 * </soapEnvelope>
 *
 * @param message   the FIX message
 * @param counter   application level sequence number of the message
 * @param sessionID the incoming session
 * @param msgCtx    the Axis2 MessageContext to hold the FIX message
 * @throws AxisFault the exception thrown when invalid soap envelopes are set to the msgCtx
 */
public void setSOAPEnvelope(Message message, int counter, String sessionID, MessageContext msgCtx) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("Creating SOAP envelope for FIX message...");
    }
    SOAPFactory soapFactory = new SOAP11Factory();
    OMElement msg = soapFactory.createOMElement(FIXConstants.FIX_MESSAGE, null);
    msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_INCOMING_SESSION, null, sessionID));
    msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_COUNTER, null, String.valueOf(counter)));
    OMElement header = soapFactory.createOMElement(FIXConstants.FIX_HEADER, null);
    OMElement body = soapFactory.createOMElement(FIXConstants.FIX_BODY, null);
    OMElement trailer = soapFactory.createOMElement(FIXConstants.FIX_TRAILER, null);
    // process FIX header
    Iterator<Field<?>> iter = message.getHeader().iterator();
    if (iter != null) {
        while (iter.hasNext()) {
            Field<?> field = iter.next();
            OMElement msgField = soapFactory.createOMElement(FIXConstants.FIX_FIELD, null);
            msgField.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_FIELD_ID, null, String.valueOf(field.getTag())));
            Object value = field.getObject();
            if (value instanceof byte[]) {
                DataSource dataSource = new ByteArrayDataSource((byte[]) value);
                DataHandler dataHandler = new DataHandler(dataSource);
                String contentID = msgCtx.addAttachment(dataHandler);
                OMElement binaryData = soapFactory.createOMElement(FIXConstants.FIX_BINARY_FIELD, null);
                String binaryCID = "cid:" + contentID;
                binaryData.addAttribute(FIXConstants.FIX_MESSAGE_REFERENCE, binaryCID, null);
                msgField.addChild(binaryData);
            } else {
                createOMText(soapFactory, msgField, value.toString());
            }
            header.addChild(msgField);
        }
    }
    // process FIX body
    convertFIXBodyToXML(message, body, soapFactory, msgCtx);
    // process FIX trailer
    iter = message.getTrailer().iterator();
    if (iter != null) {
        while (iter.hasNext()) {
            Field<?> field = iter.next();
            OMElement msgField = soapFactory.createOMElement(FIXConstants.FIX_FIELD, null);
            msgField.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_FIELD_ID, null, String.valueOf(field.getTag())));
            Object value = field.getObject();
            if (value instanceof byte[]) {
                DataSource dataSource = new ByteArrayDataSource((byte[]) value);
                DataHandler dataHandler = new DataHandler(dataSource);
                String contentID = msgCtx.addAttachment(dataHandler);
                OMElement binaryData = soapFactory.createOMElement(FIXConstants.FIX_BINARY_FIELD, null);
                String binaryCID = "cid:" + contentID;
                binaryData.addAttribute(FIXConstants.FIX_MESSAGE_REFERENCE, binaryCID, null);
                msgField.addChild(binaryData);
            } else {
                createOMText(soapFactory, msgField, value.toString());
            }
            trailer.addChild(msgField);
        }
    }
    msg.addChild(header);
    msg.addChild(body);
    msg.addChild(trailer);
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    envelope.getBody().addChild(msg);
    msgCtx.setEnvelope(envelope);
}
Also used : SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource) SOAPFactory(org.apache.axiom.soap.SOAPFactory) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Example 63 with SOAPFactory

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

the class VFSTransportSenderTest method populateMessageContext.

/**
 * Function to populate message context
 * @param messageContext message context
 * @throws AxisFault
 */
private void populateMessageContext(MessageContext messageContext) throws AxisFault {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    OMElement payload = fac.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
    env.getBody().addChild(payload);
    messageContext.setEnvelope(env);
    AxisService axisService = new AxisService();
    messageContext.setAxisService(axisService);
}
Also used : AxisService(org.apache.axis2.description.AxisService) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 64 with SOAPFactory

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

the class MessageHelper method cloneSOAPFault.

/**
 * Clones the SOAPFault, fault cloning is not the same as cloning the OMElement because if the
 * Fault is accessed through the SOAPEnvelope.getBody().getFault() method it will lead to a
 * class cast because the cloned element is just an OMElement but not a Fault.
 *
 * @param fault that needs to be cloned
 * @return the cloned fault
 */
public static SOAPFault cloneSOAPFault(SOAPFault fault) {
    SOAPFactory fac;
    int soapVersion;
    final int SOAP_11 = 1;
    final int SOAP_12 = 2;
    if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(fault.getNamespace().getNamespaceURI())) {
        fac = OMAbstractFactory.getSOAP11Factory();
        soapVersion = SOAP_11;
    } else {
        fac = OMAbstractFactory.getSOAP12Factory();
        soapVersion = SOAP_12;
    }
    SOAPFault newFault = fac.createSOAPFault();
    SOAPFaultCode code = fac.createSOAPFaultCode();
    SOAPFaultReason reason = fac.createSOAPFaultReason();
    switch(soapVersion) {
        case SOAP_11:
            code.setText(fault.getCode().getTextAsQName());
            reason.setText(fault.getReason().getText());
            break;
        case SOAP_12:
            SOAPFaultValue value = fac.createSOAPFaultValue(code);
            value.setText(fault.getCode().getTextAsQName());
            for (Object obj : fault.getReason().getAllSoapTexts()) {
                SOAPFaultText text = fac.createSOAPFaultText();
                text.setText(((SOAPFaultText) obj).getText());
                reason.addSOAPText(text);
            }
            break;
    }
    newFault.setCode(code);
    newFault.setReason(reason);
    if (fault.getNode() != null) {
        SOAPFaultNode soapfaultNode = fac.createSOAPFaultNode();
        soapfaultNode.setNodeValue(fault.getNode().getNodeValue());
        newFault.setNode(soapfaultNode);
    }
    if (fault.getRole() != null) {
        SOAPFaultRole soapFaultRole = fac.createSOAPFaultRole();
        soapFaultRole.setRoleValue(fault.getRole().getRoleValue());
        newFault.setRole(soapFaultRole);
    }
    if (fault.getDetail() != null) {
        SOAPFaultDetail soapFaultDetail = fac.createSOAPFaultDetail();
        for (Iterator itr = fault.getDetail().getAllDetailEntries(); itr.hasNext(); ) {
            Object element = itr.next();
            if (element instanceof OMElement) {
                soapFaultDetail.addDetailEntry(((OMElement) element).cloneOMElement());
            }
        }
        newFault.setDetail(soapFaultDetail);
    }
    return newFault;
}
Also used : SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) SOAPFaultRole(org.apache.axiom.soap.SOAPFaultRole) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultValue(org.apache.axiom.soap.SOAPFaultValue) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) OMElement(org.apache.axiom.om.OMElement) SOAPFaultText(org.apache.axiom.soap.SOAPFaultText) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SynapseMediationFlowPoint(org.apache.synapse.debug.constructs.SynapseMediationFlowPoint) Iterator(java.util.Iterator) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPFaultNode(org.apache.axiom.soap.SOAPFaultNode)

Example 65 with SOAPFactory

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

the class MessageHelper method cloneArrayList.

/*
     * This method will deep clone array list by creating a new ArrayList and cloning and adding each element in it
     * */
public static ArrayList<Object> cloneArrayList(ArrayList<Object> arrayList) {
    ArrayList<Object> newArrayList = null;
    if (arrayList != null) {
        newArrayList = new ArrayList<Object>();
        for (Object obj : arrayList) {
            if (obj instanceof SOAPHeaderBlock) {
                SOAPFactory fac = (SOAPFactory) ((SOAPHeaderBlock) obj).getOMFactory();
                obj = ((SOAPHeaderBlock) obj).cloneOMElement();
                try {
                    obj = ElementHelper.toSOAPHeaderBlock((OMElement) obj, fac);
                } catch (Exception e) {
                    handleException(e);
                }
            } else if (obj instanceof SOAPEnvelope) {
                SOAPEnvelope enve = (SOAPEnvelope) obj;
                obj = MessageHelper.cloneSOAPEnvelope(enve);
            } else if (obj instanceof OMElement) {
                obj = ((OMElement) obj).cloneOMElement();
            } else {
                if (log.isDebugEnabled()) {
                    log.error("Array List deep clone not implemented for Class type : " + obj.getClass().getName());
                }
            }
            newArrayList.add(obj);
        }
    }
    return newArrayList;
}
Also used : SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException)

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