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;
}
}
}
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);
}
}
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;
}
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);
}
}
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);
}
Aggregations