You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/01/25 15:10:30 UTC
svn commit: r1438525 - in /camel/branches/camel-2.10.x: ./
components/camel-http/src/main/java/org/apache/camel/component/http/
components/camel-http4/src/main/java/org/apache/camel/component/http4/
components/camel-jetty/src/test/java/org/apache/camel...
Author: ningjiang
Date: Fri Jan 25 14:10:29 2013
New Revision: 1438525
URL: http://svn.apache.org/viewvc?rev=1438525&view=rev
Log:
CAMEL-5821 Fixed the jetty chunked false option broken issue
Merged revisions 1438499-1438500 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1438499 | ningjiang | 2013-01-25 21:24:13 +0800 (Fri, 25 Jan 2013) | 1 line
CAMEL-5821 Fixed the jetty chunked false option broken issue
........
r1438500 | ningjiang | 2013-01-25 21:24:48 +0800 (Fri, 25 Jan 2013) | 1 line
CAMEL-5821 merged the change into camel-http4
........
Added:
camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/JettyChuckedFalseTest.java
- copied unchanged from r1438500, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/proxy/JettyChuckedFalseTest.java
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1438499-1438500
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=1438525&r1=1438524&r2=1438525&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (original)
+++ camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Fri Jan 25 14:10:29 2013
@@ -19,6 +19,7 @@ package org.apache.camel.component.http;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.net.URLDecoder;
@@ -38,6 +39,7 @@ import org.apache.camel.RuntimeCamelExce
import org.apache.camel.StreamCache;
import org.apache.camel.component.http.helper.CamelFileDataSource;
import org.apache.camel.component.http.helper.HttpHelper;
+import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.GZIPHelper;
import org.apache.camel.util.IOHelper;
@@ -295,6 +297,25 @@ public class DefaultHttpBinding implemen
}
}
}
+
+ protected boolean isText(String contentType) {
+ if (contentType != null) {
+ String temp = contentType.toLowerCase();
+ if (temp.indexOf("text") >= 0 || temp.indexOf("html") >= 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected void copyStream(InputStream is, OutputStream os) throws IOException {
+ try {
+ // copy directly from input stream to output stream
+ IOHelper.copy(is, os);
+ } finally {
+ IOHelper.close(os, is);
+ }
+ }
protected void doWriteDirectResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
// if content type is serialized Java object, then serialize and write it to the response
@@ -311,22 +332,32 @@ public class DefaultHttpBinding implemen
}
// prefer streaming
- InputStream is;
+ InputStream is = null;
if (checkChunked(message, exchange)) {
is = message.getBody(InputStream.class);
} else {
// try to use input stream first, so we can copy directly
- is = exchange.getContext().getTypeConverter().tryConvertTo(InputStream.class, message.getBody());
+ if (!isText(contentType)) {
+ is = exchange.getContext().getTypeConverter().tryConvertTo(InputStream.class, message.getBody());
+ }
}
if (is != null) {
ServletOutputStream os = response.getOutputStream();
LOG.trace("Writing direct response from source input stream to servlet output stream");
- try {
- // copy directly from input stream to output stream
- IOHelper.copy(is, os);
- } finally {
- IOHelper.close(os, is);
+ if (!checkChunked(message, exchange)) {
+ CachedOutputStream stream = new CachedOutputStream(exchange);
+ try {
+ // copy directly from input stream to the cached output stream to get the content length
+ int len = IOHelper.copy(is, stream);
+ // we need to setup the length if message is not chucked
+ response.setContentLength(len);
+ copyStream(stream.getInputStream(), os);
+ } finally {
+ IOHelper.close(is, stream);
+ }
+ } else {
+ copyStream(is, os);
}
} else {
// not convertable as a stream so fallback as a String
Modified: camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java?rev=1438525&r1=1438524&r2=1438525&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java (original)
+++ camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java Fri Jan 25 14:10:29 2013
@@ -19,6 +19,7 @@ package org.apache.camel.component.http4
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.net.URLDecoder;
@@ -39,6 +40,7 @@ import org.apache.camel.RuntimeCamelExce
import org.apache.camel.StreamCache;
import org.apache.camel.component.http4.helper.CamelFileDataSource;
import org.apache.camel.component.http4.helper.HttpHelper;
+import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.GZIPHelper;
import org.apache.camel.util.IOHelper;
@@ -278,6 +280,25 @@ public class DefaultHttpBinding implemen
}
}
}
+
+ protected boolean isText(String contentType) {
+ if (contentType != null) {
+ String temp = contentType.toLowerCase();
+ if (temp.indexOf("text") >= 0 || temp.indexOf("html") >= 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected void copyStream(InputStream is, OutputStream os) throws IOException {
+ try {
+ // copy directly from input stream to output stream
+ IOHelper.copy(is, os);
+ } finally {
+ IOHelper.close(os, is);
+ }
+ }
protected void doWriteDirectResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
// if content type is serialized Java object, then serialize and write it to the response
@@ -294,22 +315,32 @@ public class DefaultHttpBinding implemen
}
// prefer streaming
- InputStream is;
+ InputStream is = null;
if (checkChunked(message, exchange)) {
is = message.getBody(InputStream.class);
} else {
- // try to use input stream first, so we can copy directly
- is = exchange.getContext().getTypeConverter().tryConvertTo(InputStream.class, message.getBody());
+ // try to use input stream first, so we can copy directly
+ if (!isText(contentType)) {
+ is = exchange.getContext().getTypeConverter().tryConvertTo(InputStream.class, message.getBody());
+ }
}
if (is != null) {
ServletOutputStream os = response.getOutputStream();
- try {
- LOG.trace("Writing direct response from source input stream to servlet output stream");
- // copy directly from input stream to output stream
- IOHelper.copy(is, os);
- } finally {
- IOHelper.close(os, is);
+ LOG.trace("Writing direct response from source input stream to servlet output stream");
+ if (!checkChunked(message, exchange)) {
+ CachedOutputStream stream = new CachedOutputStream(exchange);
+ try {
+ // copy directly from input stream to the cached output stream to get the content length
+ int len = IOHelper.copy(is, stream);
+ // we need to setup the length if message is not chucked
+ response.setContentLength(len);
+ copyStream(stream.getInputStream(), os);
+ } finally {
+ IOHelper.close(is, stream);
+ }
+ } else {
+ copyStream(is, os);
}
} else {
// not convertable as a stream so try as a String