Search in sources :

Example 11 with SOAPFactory

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

the class JsonStreamBuilder method processDocument.

public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext) throws AxisFault {
    if (inputStream != null) {
        OMElement element = JsonUtil.getNewJsonPayload(messageContext, inputStream, false, false);
        if (element != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("#processDocument. Built JSON payload from JSON stream. MessageID: " + messageContext.getMessageID());
            }
            return element;
        }
    } else {
        EndpointReference endpointReference = messageContext.getTo();
        if (endpointReference == null) {
            logger.error("#processDocument. Cannot build payload without a valid EPR. MessageID: " + messageContext.getMessageID());
            throw new AxisFault("Cannot build payload without a valid EPR.");
        }
        String requestURL;
        try {
            requestURL = URIEncoderDecoder.decode(endpointReference.getAddress());
        } catch (UnsupportedEncodingException e) {
            logger.error("#processDocument. Could not decode request URL. MessageID: " + messageContext.getMessageID());
            throw new AxisFault("Could not decode request URL.", e);
        }
        String jsonString;
        int index;
        // half as the incoming JSON message
        if ((index = requestURL.indexOf('=')) > 0) {
            jsonString = requestURL.substring(index + 1);
            messageContext.setProperty(Constants.JSON_STRING, jsonString);
            ByteArrayInputStream is = new ByteArrayInputStream(jsonString.getBytes());
            return processDocument(is, s, messageContext);
        } else {
            messageContext.setProperty(Constants.JSON_STRING, null);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("#processDocument. No JSON payload found in request. MessageID: " + messageContext.getMessageID());
    }
    SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
    return factory.getDefaultEnvelope();
}
Also used : AxisFault(org.apache.axis2.AxisFault) OMElement(org.apache.axiom.om.OMElement) SOAPFactory(org.apache.axiom.soap.SOAPFactory) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 12 with SOAPFactory

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

the class XFormURLEncodedBuilder method processDocument.

public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext) throws AxisFault {
    // first process the input stream
    SOAPEnvelope soapEnv = (SOAPEnvelope) processDocumentWrapper(inputStream, s, messageContext);
    // when this is a POST request, if the body of the soap envelope is empty and the parameter
    // map is there, build a dummy soap body which contains all the parameters coming in.
    SOAPBody body = soapEnv.getBody();
    String httpMethod = (String) messageContext.getProperty(HTTPConstants.HTTP_METHOD);
    if (body.getFirstElement() == null && HTTPConstants.HTTP_METHOD_POST.equals(httpMethod) && messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP) != null) {
        MultipleEntryHashMap map = (MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP);
        SOAPFactory soapFactory = getSOAPFactory(messageContext);
        OMElement bodyFirstChild = soapFactory.createOMElement(XFORM_FIRST_ELEMENT, body);
        createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, map);
    } else if (body.getFirstElement() != null && "mediate".equals(body.getFirstElement().getLocalName())) {
        body.getFirstElement().setLocalName(XFORM_FIRST_ELEMENT.getLocalPart());
    }
    return soapEnv;
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 13 with SOAPFactory

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

the class XFormURLEncodedBuilder method getSOAPFactory.

private SOAPFactory getSOAPFactory(MessageContext messageContext) throws AxisFault {
    SOAPFactory soapFactory;
    AxisEndpoint axisEndpoint = (AxisEndpoint) messageContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
    if (axisEndpoint != null) {
        AxisBinding axisBinding = axisEndpoint.getBinding();
        String soapVersion = (String) axisBinding.getProperty(WSDL2Constants.ATTR_WSOAP_VERSION);
        soapFactory = getSOAPFactory(soapVersion);
    } else {
        soapFactory = getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    }
    return soapFactory;
}
Also used : AxisBinding(org.apache.axis2.description.AxisBinding) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 14 with SOAPFactory

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

the class XFormURLEncodedBuilder method processDocumentWrapper.

/**
 * @return Returns the document element.
 */
private OMElement processDocumentWrapper(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
    MultipleEntryHashMap parameterMap = new MultipleEntryHashMap();
    SOAPFactory soapFactory;
    AxisBindingOperation axisBindingOperation = (AxisBindingOperation) messageContext.getProperty(Constants.AXIS_BINDING_OPERATION);
    String queryParameterSeparator = null;
    String templatedPath = null;
    if (axisBindingOperation != null) {
        queryParameterSeparator = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
        templatedPath = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION);
    }
    if (queryParameterSeparator == null) {
        queryParameterSeparator = WSDL20DefaultValueHolder.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR_DEFAULT;
    }
    AxisEndpoint axisEndpoint = (AxisEndpoint) messageContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
    if (axisEndpoint != null) {
        AxisBinding axisBinding = axisEndpoint.getBinding();
        String soapVersion = (String) axisBinding.getProperty(WSDL2Constants.ATTR_WSOAP_VERSION);
        soapFactory = getSOAPFactory(soapVersion);
    } else {
        soapFactory = getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    }
    EndpointReference endpointReference = messageContext.getTo();
    if (endpointReference == null) {
        throw new AxisFault("Cannot create DocumentElement without destination EPR");
    }
    String requestURL = endpointReference.getAddress();
    try {
        requestURL = extractParametersUsingHttpLocation(templatedPath, parameterMap, requestURL, queryParameterSeparator);
    } catch (UnsupportedEncodingException e) {
        throw AxisFault.makeFault(e);
    }
    String query = requestURL;
    int index;
    if ((index = requestURL.indexOf("?")) > -1) {
        query = requestURL.substring(index + 1);
    }
    extractParametersFromRequest(parameterMap, query, queryParameterSeparator, (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING), inputStream);
    messageContext.setProperty(Constants.REQUEST_PARAMETER_MAP, parameterMap);
    return BuilderUtil.buildsoapMessage(messageContext, parameterMap, soapFactory);
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisBinding(org.apache.axis2.description.AxisBinding) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 15 with SOAPFactory

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

the class MessageHelper method cloneSOAPEnvelope.

/**
 * This method will clone the provided SOAPEnvelope and returns the cloned envelope
 * as an exact copy of the provided envelope
 *
 * @param envelope - this will be cloned to get the new envelope
 * @return cloned SOAPEnvelope from the provided one
 */
public static SOAPEnvelope cloneSOAPEnvelope(SOAPEnvelope envelope) {
    SOAPFactory fac;
    if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelope.getBody().getNamespace().getNamespaceURI())) {
        fac = OMAbstractFactory.getSOAP11Factory();
    } else {
        fac = OMAbstractFactory.getSOAP12Factory();
    }
    SOAPEnvelope newEnvelope = fac.getDefaultEnvelope();
    Iterator childIterator;
    if (envelope.getHeader() != null) {
        SOAPHeader body = envelope.getHeader();
        childIterator = body.getChildren();
        while (childIterator.hasNext()) {
            Object bodyNs = childIterator.next();
            if (bodyNs instanceof SOAPHeaderBlock) {
                try {
                    newEnvelope.getHeader().addChild(ElementHelper.toSOAPHeaderBlock(((OMElement) bodyNs).cloneOMElement(), fac));
                } catch (Exception e) {
                    handleException(e);
                }
            } else if (bodyNs instanceof OMElement) {
                newEnvelope.getHeader().addChild(((OMElement) bodyNs).cloneOMElement());
            }
        }
    }
    if (envelope.getBody() != null) {
        // fault would lead to class cast exceptions if accessed through the getFault method
        if (envelope.getBody().getFirstElement() instanceof SOAPFault && envelope.getBody().hasFault()) {
            SOAPFault fault = envelope.getBody().getFault();
            newEnvelope.getBody().addFault(cloneSOAPFault(fault));
        } else {
            OMElement body = envelope.getBody().cloneOMElement();
            Iterator ns = body.getAllDeclaredNamespaces();
            OMNamespace bodyNs = body.getNamespace();
            String nsUri = bodyNs.getNamespaceURI();
            String nsPrefix = bodyNs.getPrefix();
            while (ns.hasNext()) {
                OMNamespace namespace = ((OMNamespace) ns.next());
                if (nsUri != null && !nsUri.equals(namespace.getNamespaceURI()) && nsPrefix != null && !nsPrefix.equals(namespace.getPrefix())) {
                    newEnvelope.getBody().declareNamespace(namespace);
                }
                ns.remove();
            }
            Iterator attributes = body.getAllAttributes();
            while (attributes.hasNext()) {
                OMAttribute attrb = (OMAttribute) attributes.next();
                newEnvelope.getBody().addAttribute(attrb);
                attributes.remove();
            }
            Iterator itr = body.getChildren();
            while (itr.hasNext()) {
                OMNode node = (OMNode) itr.next();
                itr.remove();
                newEnvelope.getBody().addChild(node);
            }
        }
    }
    return newEnvelope;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) 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) OMNode(org.apache.axiom.om.OMNode) Iterator(java.util.Iterator) SOAPFault(org.apache.axiom.soap.SOAPFault) OMAttribute(org.apache.axiom.om.OMAttribute) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

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