Search in sources :

Example 21 with SOAPFactory

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

the class MessageHelperTest method testCloneSoapEnvelope.

public void testCloneSoapEnvelope() {
    SOAPFactory soapFactory;
    SOAPHeaderBlock header;
    OMFactory omFactory = OMAbstractFactory.getOMFactory();
    // Creating a namespace for the header
    OMNamespace ns = omFactory.createOMNamespace("http://ws.apache.org/axis2", "hns");
    OMElement childNode = omFactory.createOMElement("Child", ns);
    // testing SOAP 1.1
    soapFactory = OMAbstractFactory.getSOAP11Factory();
    // creating a SOAP header block
    header = new SOAP11HeaderBlockImpl("CustomHeader", ns, soapFactory);
    performTestForCloneEnvelope(soapFactory, header, childNode);
    // testing SOAP 1.1
    soapFactory = OMAbstractFactory.getSOAP12Factory();
    header = new SOAP12HeaderBlockImpl("CustomHeader", ns, soapFactory);
    performTestForCloneEnvelope(soapFactory, header, childNode);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) SOAP12HeaderBlockImpl(org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderBlockImpl) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) SOAP11HeaderBlockImpl(org.apache.axiom.soap.impl.llom.soap11.SOAP11HeaderBlockImpl) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 22 with SOAPFactory

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

the class NashornJavaScriptMessageContext 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
 */
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 23 with SOAPFactory

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

the class FIXMessageBuilder method processDocument.

public OMElement processDocument(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
    Reader reader = null;
    StringBuilder messageString = new StringBuilder();
    quickfix.Message message = null;
    try {
        String charSetEncoding = (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
        if (charSetEncoding == null) {
            charSetEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
        }
        reader = new InputStreamReader(inputStream, charSetEncoding);
        try {
            int data = reader.read();
            while (data != -1) {
                char dataChar = (char) data;
                data = reader.read();
                messageString.append(dataChar);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            log.error("Error In creating FIX SOAP envelope ...", e);
            throw new AxisFault(e.getMessage());
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.error("Error In creating FIX SOAP envelope ...", e);
        throw new AxisFault(e.getMessage());
    }
    try {
        DefaultDataDictionaryProvider dataDictionary = new DefaultDataDictionaryProvider();
        String beginString = MessageUtils.getStringField(messageString.toString(), BeginString.FIELD);
        DataDictionary dataDic = dataDictionary.getSessionDataDictionary(beginString);
        message = new quickfix.Message(messageString.toString(), null, false);
    } catch (InvalidMessage e) {
        // TODO Auto-generated catch block
        log.error("Error In creating FIX SOAP envelope ...", e);
        throw new AxisFault(e.getMessage());
    }
    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, ""));
    msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_COUNTER, null, String.valueOf("-1")));
    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<quickfix.Field<?>> iter = message.getHeader().iterator();
    if (iter != null) {
        while (iter.hasNext()) {
            quickfix.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 = messageContext.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 {
                soapFactory.createOMText(msgField, value.toString(), OMElement.CDATA_SECTION_NODE);
            }
            header.addChild(msgField);
        }
    }
    // process FIX body
    convertFIXBodyToXML(message, body, soapFactory, messageContext);
    // process FIX trailer
    iter = message.getTrailer().iterator();
    if (iter != null) {
        while (iter.hasNext()) {
            quickfix.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 = messageContext.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 {
                soapFactory.createOMText(msgField, value.toString(), OMElement.CDATA_SECTION_NODE);
            }
            trailer.addChild(msgField);
        }
    }
    msg.addChild(header);
    msg.addChild(body);
    msg.addChild(trailer);
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    envelope.getBody().addChild(msg);
    messageContext.setEnvelope(envelope);
    return msg;
}
Also used : AxisFault(org.apache.axis2.AxisFault) InputStreamReader(java.io.InputStreamReader) DefaultDataDictionaryProvider(quickfix.DefaultDataDictionaryProvider) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) OMElement(org.apache.axiom.om.OMElement) BeginString(quickfix.field.BeginString) InvalidMessage(quickfix.InvalidMessage) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) DataDictionary(quickfix.DataDictionary) SOAPFactory(org.apache.axiom.soap.SOAPFactory) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource) DataSource(javax.activation.DataSource) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource)

Example 24 with SOAPFactory

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

the class StockQuoteSampleClient 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 : SOAPBody(org.apache.axiom.soap.SOAPBody) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 25 with SOAPFactory

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

the class ServerWorker method processEntityEnclosingRequest.

public void processEntityEnclosingRequest(MessageContext msgContext, boolean injectToAxis2Engine) {
    try {
        String contentTypeHeader = request.getHeaders().get(HTTP.CONTENT_TYPE);
        contentTypeHeader = contentTypeHeader != null ? contentTypeHeader : inferContentType();
        String charSetEncoding = null;
        String contentType = null;
        if (contentTypeHeader != null) {
            charSetEncoding = BuilderUtil.getCharSetEncoding(contentTypeHeader);
            contentType = TransportUtils.getContentType(contentTypeHeader, msgContext);
        }
        // get the contentType of char encoding
        if (charSetEncoding == null) {
            charSetEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
        }
        String method = request.getRequest() != null ? request.getRequest().getRequestLine().getMethod().toUpperCase() : "";
        msgContext.setTo(new EndpointReference(request.getUri()));
        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEncoding);
        msgContext.setServerSide(true);
        msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentTypeHeader);
        msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
        if (contentTypeHeader == null || HTTPTransportUtils.isRESTRequest(contentTypeHeader) || isRest(contentTypeHeader)) {
            msgContext.setProperty(PassThroughConstants.REST_REQUEST_CONTENT_TYPE, contentType);
            msgContext.setDoingREST(true);
            SOAPEnvelope soapEnvelope = this.handleRESTUrlPost(contentTypeHeader);
            msgContext.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, request.getPipe());
            processNonEntityEnclosingRESTHandler(soapEnvelope, msgContext, injectToAxis2Engine);
            return;
        } else {
            String soapAction = request.getHeaders().get(SOAP_ACTION_HEADER);
            int soapVersion = HTTPTransportUtils.initializeMessageContext(msgContext, soapAction, request.getUri(), contentTypeHeader);
            SOAPEnvelope envelope;
            if (soapVersion == 1) {
                SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
                envelope = fac.getDefaultEnvelope();
            } else if (soapVersion == 2) {
                SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
                envelope = fac.getDefaultEnvelope();
            } else {
                SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
                envelope = fac.getDefaultEnvelope();
            }
            if ((soapAction != null) && soapAction.startsWith("\"") && soapAction.endsWith("\"")) {
                soapAction = soapAction.substring(1, soapAction.length() - 1);
                msgContext.setSoapAction(soapAction);
            }
            msgContext.setEnvelope(envelope);
        }
        msgContext.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, request.getPipe());
        if (injectToAxis2Engine) {
            AxisEngine.receive(msgContext);
        }
    } catch (AxisFault axisFault) {
        handleException("Error processing " + request.getMethod() + " request for : " + request.getUri(), axisFault);
    } catch (Exception e) {
        handleException("Error processing " + request.getMethod() + " request for : " + request.getUri() + ". Error detail: " + e.getMessage() + ". ", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

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