Author: hiranya
Date: Thu Jun 9 06:57:12 2016
New Revision: 1747502
URL: http://svn.apache.org/viewvc?rev=1747502&view=rev
Log:
Supporting the DISABLE_CHUNKING property in the response path of HTTP message
mediation; Applied patches from SYNAPSE-1023 and SYNAPSE-1029
Added:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample160.java
synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_160.xml
synapse/trunk/java/modules/integration/src/test/resources/sample160.xml
Modified:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceResponse.java
Modified:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java?rev=1747502&r1=1747501&r2=1747502&view=diff
==============================================================================
---
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
(original)
+++
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
Thu Jun 9 06:57:12 2016
@@ -207,7 +207,9 @@ public class TestSamplesHandlerSuite ext
sampleClassRepo.put("155", Sample155.class);
sampleClassRepo.put("156", Sample156.class);
sampleClassRepo.put("157", Sample157.class);
+ sampleClassRepo.put("160", Sample160.class);
sampleClassRepo.put("161", Sample161.class);
+
//Transport switching
sampleClassRepo.put("250", Sample250.class);
sampleClassRepo.put("251", Sample251.class);
Added:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample160.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample160.java?rev=1747502&view=auto
==============================================================================
---
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample160.java
(added)
+++
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample160.java
Thu Jun 9 06:57:12 2016
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.samples.framework.tests.proxy;
+
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpStatus;
+import org.apache.synapse.samples.framework.SynapseTestCase;
+import org.apache.synapse.samples.framework.clients.BasicHttpClient;
+import org.apache.synapse.samples.framework.clients.HttpResponse;
+
+public class Sample160 extends SynapseTestCase {
+
+ private String requestXml;
+ private BasicHttpClient httpClient;
+
+ public Sample160() {
+ super(160);
+ httpClient = new BasicHttpClient();
+ requestXml = "<soap:Envelope
xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"
xmlns:ser=\"http://services.samples\"
xmlns:xsd=\"http://services.samples/xsd\">\n" +
+ " <soap:Header/>\n" +
+ " <soap:Body>\n" +
+ " <ser:getQuote>\n" +
+ " <ser:request>\n" +
+ " <xsd:symbol>IBM</xsd:symbol>\n" +
+ " </ser:request>\n" +
+ " </ser:getQuote>\n" +
+ " </soap:Body>\n" +
+ " </soap:Envelope>";
+ }
+
+ public void testDisableChunkingWithBasicProxy() throws Exception {
+ String url = "http://localhost:8280/services/StockQuoteProxy";
+ HttpResponse response = httpClient.doPost(url, requestXml.getBytes(),
+ "application/soap+xml;charset=UTF-8");
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ assertFalse(HttpHeaders.TRANSFER_ENCODING + " is present in the
header",
+
response.getHeaders().containsKey(HttpHeaders.TRANSFER_ENCODING));
+ assertTrue(HttpHeaders.CONTENT_LENGTH + " is missing in the header",
+ response.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH));
+
+ }
+
+}
\ No newline at end of file
Modified:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java?rev=1747502&r1=1747501&r2=1747502&view=diff
==============================================================================
---
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java
(original)
+++
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/proxy/Sample161.java
Thu Jun 9 06:57:12 2016
@@ -25,14 +25,14 @@ import org.apache.synapse.samples.framew
import org.apache.synapse.samples.framework.clients.HttpResponse;
public class Sample161 extends SynapseTestCase {
- private String requestXml = "<test>foo</test>";
+
+ private static final String requestXml = "<test>foo</test>";
public Sample161() {
super(161);
}
public void testRespondMediator() throws Exception {
-
String url = "http://localhost:8280/services/EchoService";
BasicHttpClient client = new BasicHttpClient();
HttpResponse response = client.doPost(url, requestXml.getBytes(),
"application/xml");
Added:
synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_160.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_160.xml?rev=1747502&view=auto
==============================================================================
---
synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_160.xml
(added)
+++
synapse/trunk/java/modules/integration/src/test/resources/extras/synapse_sample_160.xml
Thu Jun 9 06:57:12 2016
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<!-- DISABLE_CHUNKING in response path proxy services -->
+<definitions xmlns="http://ws.apache.org/ns/synapse">
+ <proxy name="StockQuoteProxy">
+ <target>
+ <endpoint>
+ <address
uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ <outSequence>
+ <property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
+ <send/>
+ </outSequence>
+ </target>
+ <publishWSDL
uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/>
+ </proxy>
+</definitions>
Added: synapse/trunk/java/modules/integration/src/test/resources/sample160.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/sample160.xml?rev=1747502&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/resources/sample160.xml
(added)
+++ synapse/trunk/java/modules/integration/src/test/resources/sample160.xml Thu
Jun 9 06:57:12 2016
@@ -0,0 +1,18 @@
+<synapseSample>
+ <sampleID>160</sampleID>
+ <sampleName>DISABLE_CHUNKING in response path proxy services</sampleName>
+ <synapseConfig>
+ <axis2Repo>modules/integration/target/test_repos/synapse</axis2Repo>
+
<axis2Xml>modules/integration/target/test_repos/synapse/conf/axis2_def.xml</axis2Xml>
+
<synapseXml>modules/integration/src/test/resources/extras/synapse_sample_160.xml</synapseXml>
+ </synapseConfig>
+ <backEndServerConfig>
+ <axis2Server id='0'>
+
<axis2Repo>modules/integration/target/test_repos/axis2Server</axis2Repo>
+
<axis2Xml>modules/integration/target/test_repos/axis2Server/conf/axis2_def.xml</axis2Xml>
+ </axis2Server>
+ </backEndServerConfig>
+ <clientConfig>
+
<clientRepo>modules/integration/target/test_repos/axis2Client</clientRepo>
+ </clientConfig>
+</synapseSample>
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java?rev=1747502&r1=1747501&r2=1747502&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java
Thu Jun 9 06:57:12 2016
@@ -519,6 +519,7 @@ public class PassThroughHttpSender exten
SourceResponse sourceResponse =
SourceResponseFactory.create(msgContext,
sourceRequest, sourceConfiguration);
+ sourceResponse.processChunkingOptions(msgContext);
SourceContext.setResponse(conn, sourceResponse);
Boolean noEntityBody = (Boolean)
msgContext.getProperty(PassThroughConstants.NO_ENTITY_BODY);
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceResponse.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceResponse.java?rev=1747502&r1=1747501&r2=1747502&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceResponse.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceResponse.java
Thu Jun 9 06:57:12 2016
@@ -28,6 +28,12 @@ import org.apache.http.protocol.HttpCont
import org.apache.http.protocol.HttpCoreContext;
import org.apache.synapse.transport.passthru.config.SourceConfiguration;
import org.apache.synapse.transport.passthru.util.PassThroughTransportUtils;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.util.MessageProcessorSelector;
+import org.apache.synapse.transport.passthru.util.RelayUtils;
+import org.apache.commons.io.output.CountingOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
import java.io.IOException;
import java.util.HashMap;
@@ -60,7 +66,8 @@ public class SourceResponse {
private SourceRequest request = null;
-
+ private boolean versionChangeRequired =false;
+
public SourceResponse(SourceConfiguration config, int status,
SourceRequest request) {
this(config, status, null, request);
}
@@ -93,7 +100,9 @@ public class SourceResponse {
request.getVersion(), HttpStatus.SC_OK,
request.getConnection().getContext());
- if (statusLine != null) {
+ if (versionChangeRequired) {
+ response.setStatusLine(version, status);
+ } else if (statusLine != null) {
response.setStatusLine(version, status, statusLine);
} else {
response.setStatusCode(status);
@@ -184,6 +193,55 @@ public class SourceResponse {
}
}
+ /**
+ * Process the disable chunking option in response path.
+ */
+ public void processChunkingOptions(MessageContext responseMsgContext)
throws IOException {
+ boolean forceHttp10 = responseMsgContext.isPropertyTrue(
+ PassThroughConstants.FORCE_HTTP_1_0, false);
+ boolean disableChunking = responseMsgContext.isPropertyTrue(
+ PassThroughConstants.DISABLE_CHUNKING, false);
+ if (!forceHttp10 && !disableChunking) {
+ return;
+ }
+ if
(!responseMsgContext.isPropertyTrue(PassThroughConstants.MESSAGE_BUILDER_INVOKED,
false)) {
+ try {
+ RelayUtils.buildMessage(responseMsgContext, false);
+ responseMsgContext.getEnvelope().buildWithAttachments();
+ } catch (Exception e) {
+ throw new AxisFault(e.getMessage(), e);
+ }
+ }
+ if (forceHttp10) {
+ version = HttpVersion.HTTP_1_0;
+ versionChangeRequired = true;
+ }
+ Boolean noEntityBody =
+ (Boolean)
responseMsgContext.getProperty(PassThroughConstants.NO_ENTITY_BODY);
+ if (Boolean.TRUE.equals(noEntityBody)) {
+ headers.remove(HTTP.CONTENT_TYPE);
+ return;
+ }
+ TreeSet<String> contentLength = new TreeSet<String>();
+ contentLength.add(Long.toString(getStreamLength(responseMsgContext)));
+ headers.put(HTTP.CONTENT_LEN, contentLength);
+ }
+
+ /**
+ * Write the stream to a temporary storage and calculate the content length
+ */
+ private long getStreamLength(MessageContext msgContext) throws IOException
{
+ CountingOutputStream counter = new CountingOutputStream(
+ NullOutputStream.NULL_OUTPUT_STREAM);
+ try {
+
MessageProcessorSelector.getMessageFormatter(msgContext).writeTo(msgContext,
+ PassThroughTransportUtils.getOMOutputFormat(msgContext),
counter, true);
+ } finally {
+ counter.close();
+ }
+ return counter.getCount();
+ }
+
public void setStatus(int status) {
this.status = status;
}