Search in sources :

Example 36 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class PassThroughHttpSender method sendRequestContent.

private void sendRequestContent(final MessageContext msgContext, final EndpointReference epr) throws AxisFault {
    // consume the buffer completely before sending a GET request or DELETE request without a payload
    if (HTTPConstants.HTTP_METHOD_GET.equals(msgContext.getProperty(Constants.Configuration.HTTP_METHOD)) || RelayUtils.isDeleteRequestWithoutPayload(msgContext)) {
        RelayUtils.discardMessage(msgContext);
    }
    if (Boolean.TRUE.equals(msgContext.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED))) {
        String disableChunking = (String) msgContext.getProperty(PassThroughConstants.DISABLE_CHUNKING);
        String forceHttp10 = (String) msgContext.getProperty(PassThroughConstants.FORCE_HTTP_1_0);
        Pipe pipe = (Pipe) msgContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
        OutputStream out = null;
        MessageFormatter formatter = MessageFormatterDecoratorFactory.createMessageFormatterDecorator(msgContext);
        OMOutputFormat format = PassThroughTransportUtils.getOMOutputFormat(msgContext);
        if ("true".equals(disableChunking) || "true".equals(forceHttp10)) {
            try {
                OverflowBlob overflowBlob = setStreamAsTempData(formatter, msgContext, format);
                long messageSize = overflowBlob.getLength();
                msgContext.setProperty(PassThroughConstants.PASSTROUGH_MESSAGE_LENGTH, messageSize);
                if (!deliveryAgent.submit(msgContext, epr)) {
                    return;
                }
                if (!waitForReady(msgContext)) {
                    return;
                }
                out = (OutputStream) msgContext.getProperty(PassThroughConstants.BUILDER_OUTPUT_STREAM);
                if (out != null) {
                    // Check HTTP method is GET or DELETE with no body
                    if (ignoreMessageBody(msgContext, pipe)) {
                        return;
                    }
                    overflowBlob.writeTo(out);
                    if (pipe.isStale) {
                        throw new IOException("Target Connection is stale..");
                    }
                    pipe.setSerializationComplete(true);
                }
            } catch (IOException e) {
                handleException("IO while building message", e);
            }
        } else {
            if (!deliveryAgent.submit(msgContext, epr)) {
                return;
            }
            if (!waitForReady(msgContext)) {
                return;
            }
            out = (OutputStream) msgContext.getProperty(PassThroughConstants.BUILDER_OUTPUT_STREAM);
            if (out != null) {
                // Check HTTP method is GET or DELETE with no body
                if (ignoreMessageBody(msgContext, pipe)) {
                    return;
                }
                formatter.writeTo(msgContext, format, out, false);
                if (pipe.isStale) {
                    handleException("IO while building message", new IOException("Target Connection is stale.."));
                }
                pipe.setSerializationComplete(true);
            }
        }
    } else {
        if (!deliveryAgent.submit(msgContext, epr)) {
            return;
        }
    }
}
Also used : OverflowBlob(org.apache.axiom.util.blob.OverflowBlob) OutputStream(java.io.OutputStream) MessageFormatter(org.apache.axis2.transport.MessageFormatter) IOException(java.io.IOException) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 37 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class PassThroughHttpSender method sendUsingOutputStream.

private void sendUsingOutputStream(MessageContext msgContext) throws AxisFault {
    OMOutputFormat format = NhttpUtil.getOMOutputFormat(msgContext);
    MessageFormatter messageFormatter = MessageFormatterDecoratorFactory.createMessageFormatterDecorator(msgContext);
    OutputStream out = (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT);
    if (msgContext.isServerSide()) {
        OutTransportInfo transportInfo = (OutTransportInfo) msgContext.getProperty(Constants.OUT_TRANSPORT_INFO);
        if (transportInfo != null) {
            transportInfo.setContentType(messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction()));
        } else {
            throw new AxisFault(Constants.OUT_TRANSPORT_INFO + " has not been set");
        }
    }
    try {
        messageFormatter.writeTo(msgContext, format, out, false);
        out.close();
    } catch (IOException e) {
        handleException("IO Error sending response message", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) OutTransportInfo(org.apache.axis2.transport.OutTransportInfo) OutputStream(java.io.OutputStream) MessageFormatter(org.apache.axis2.transport.MessageFormatter) IOException(java.io.IOException) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 38 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class NhttpUtil method getOMOutputFormat.

/**
 * Retirn the OMOutputFormat to be used for the message context passed in
 * @param msgContext the message context
 * @return the OMOutputFormat to be used
 */
public static OMOutputFormat getOMOutputFormat(MessageContext msgContext) {
    OMOutputFormat format = new OMOutputFormat();
    msgContext.setDoingMTOM(TransportUtils.doWriteMTOM(msgContext));
    msgContext.setDoingSwA(TransportUtils.doWriteSwA(msgContext));
    msgContext.setDoingREST(TransportUtils.isDoingREST(msgContext));
    format.setSOAP11(msgContext.isSOAP11());
    format.setDoOptimize(msgContext.isDoingMTOM());
    format.setDoingSWA(msgContext.isDoingSwA());
    format.setCharSetEncoding(TransportUtils.getCharSetEncoding(msgContext));
    Object mimeBoundaryProperty = msgContext.getProperty(Constants.Configuration.MIME_BOUNDARY);
    if (mimeBoundaryProperty != null) {
        format.setMimeBoundary((String) mimeBoundaryProperty);
    }
    return format;
}
Also used : OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 39 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class HessianMessageFormatterTest method testGetBytes.

public void testGetBytes() {
    try {
        HessianMessageFormatter formatter = new HessianMessageFormatter();
        OMOutputFormat format = new OMOutputFormat();
        HessianTestHelper testHelper = new HessianTestHelper();
        MessageContext msgContext = testHelper.createAxis2MessageContext(null);
        formatter.getBytes(msgContext, format);
        fail("getBytes() should have thrown an AxisFault!");
    } catch (AxisFault fault) {
        assertTrue(fault.getMessage().length() > 0);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 40 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class HessianMessageFormatterTest method testGetContentType.

public void testGetContentType() throws AxisFault {
    HessianMessageFormatter formatter = new HessianMessageFormatter();
    OMOutputFormat format = new OMOutputFormat();
    String soapActionString = "soapAction";
    HessianTestHelper testHelper = new HessianTestHelper();
    MessageContext msgContext = testHelper.createAxis2MessageContext(null);
    String contentType = formatter.getContentType(msgContext, format, soapActionString);
    assertEquals(HessianConstants.HESSIAN_CONTENT_TYPE, contentType);
    msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, HessianConstants.HESSIAN_CONTENT_TYPE);
    format.setCharSetEncoding(HessianTestHelper.CHARSET_ENCODING);
    contentType = formatter.getContentType(msgContext, format, soapActionString);
    String expectedContentType = HessianConstants.HESSIAN_CONTENT_TYPE + "; charset=" + HessianTestHelper.CHARSET_ENCODING;
    assertEquals(expectedContentType, contentType);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Aggregations

OMOutputFormat (org.apache.axiom.om.OMOutputFormat)64 MessageFormatter (org.apache.axis2.transport.MessageFormatter)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 OutputStream (java.io.OutputStream)18 IOException (java.io.IOException)16 AxisFault (org.apache.axis2.AxisFault)13 MessageContext (org.apache.axis2.context.MessageContext)12 OMElement (org.apache.axiom.om.OMElement)11 DataHandler (javax.activation.DataHandler)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 StringWriter (java.io.StringWriter)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 OMText (org.apache.axiom.om.OMText)5 Map (java.util.Map)4 MultipartBody (org.apache.axiom.mime.MultipartBody)4 SOAPFactory (org.apache.axiom.soap.SOAPFactory)4 Collection (java.util.Collection)3