Author: ningjiang
Date: Wed May 19 11:16:54 2010
New Revision: 946128
URL: http://svn.apache.org/viewvc?rev=946128&view=rev
Log:
CAMEL-2738 Add a option to let the user access the under layer raw inputStream
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java?rev=946128&r1=946127&r2=946128&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
Wed May 19 11:16:54 2010
@@ -59,9 +59,12 @@ public class CamelServlet extends HttpSe
// create exchange and set data on it
Exchange exchange = new DefaultExchange(consumer.getEndpoint(),
ExchangePattern.InOut);
- if ((consumer.getEndpoint()).isBridgeEndpoint()) {
+ if (consumer.getEndpoint().isBridgeEndpoint()) {
exchange.setProperty(Exchange.SKIP_GZIP_ENCODING,
Boolean.TRUE);
}
+ if (consumer.getEndpoint().isDisableStreamCache()) {
+ exchange.setProperty(Exchange.DISABLE_STREAM_CACHE,
Boolean.TRUE);
+ }
exchange.setIn(new HttpMessage(exchange, request, response));
// Have the camel process the HTTP exchange.
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=946128&r1=946127&r2=946128&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
Wed May 19 11:16:54 2010
@@ -313,13 +313,18 @@ public class DefaultHttpBinding implemen
if (is == null) {
return is;
}
- // convert the input stream to StreamCache
- try {
- CachedOutputStream cos = new
CachedOutputStream(httpMessage.getExchange());
- IOHelper.copy(is, cos);
- return cos.getStreamCache();
- } finally {
- is.close();
+ // convert the input stream to StreamCache if the stream cache is
not disabled
+ if
(httpMessage.getExchange().getProperty(Exchange.DISABLE_STREAM_CACHE,
Boolean.FALSE, Boolean.class)) {
+ return is;
+ } else {
+ try {
+ CachedOutputStream cos = new
CachedOutputStream(httpMessage.getExchange());
+ IOHelper.copy(is, cos);
+ return cos.getStreamCache();
+
+ } finally {
+ is.close();
+ }
}
}
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=946128&r1=946127&r2=946128&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
Wed May 19 11:16:54 2010
@@ -205,6 +205,7 @@ public class HttpComponent extends Heade
Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters,
"throwExceptionOnFailure", Boolean.class);
Boolean bridgeEndpoint = getAndRemoveParameter(parameters,
"bridgeEndpoint", Boolean.class);
Boolean matchOnUriPrefix = getAndRemoveParameter(parameters,
"matchOnUriPrefix", Boolean.class);
+ Boolean disableStreamCache = getAndRemoveParameter(parameters,
"disableStreamCache", Boolean.class);
String proxyHost = getAndRemoveParameter(parameters, "proxyHost",
String.class);
Integer proxyPort = getAndRemoveParameter(parameters, "proxyPort",
Integer.class);
String authMethodPriority = getAndRemoveParameter(parameters,
"authMethodPriority", String.class);
@@ -254,6 +255,9 @@ public class HttpComponent extends Heade
if (matchOnUriPrefix != null) {
endpoint.setMatchOnUriPrefix(matchOnUriPrefix);
}
+ if (disableStreamCache != null) {
+ endpoint.setDisableStreamCache(disableStreamCache);
+ }
if (proxyHost != null) {
endpoint.setProxyHost(proxyHost);
endpoint.setProxyPort(proxyPort);
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=946128&r1=946127&r2=946128&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
Wed May 19 11:16:54 2010
@@ -54,6 +54,7 @@ public class HttpEndpoint extends Defaul
private boolean bridgeEndpoint;
private boolean matchOnUriPrefix;
private boolean chunked = true;
+ private boolean disableStreamCache;
private String proxyHost;
private int proxyPort;
private String authMethodPriority;
@@ -272,6 +273,14 @@ public class HttpEndpoint extends Defaul
this.matchOnUriPrefix = match;
}
+ public boolean isDisableStreamCache() {
+ return this.disableStreamCache;
+ }
+
+ public void setDisableStreamCache(boolean disable) {
+ this.disableStreamCache = disable;
+ }
+
public boolean isChunked() {
return this.chunked;
}
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=946128&r1=946127&r2=946128&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
Wed May 19 11:16:54 2010
@@ -220,6 +220,8 @@ public class HttpProducer extends Defaul
}
private static InputStream doExtractResponseBody(InputStream is, Exchange
exchange) throws IOException {
+ // As httpclient is using a AutoCloseInputStream, it will be closed
when the connection is closed
+ // we need to cache the stream for it.
try {
CachedOutputStream cos = new CachedOutputStream(exchange);
IOHelper.copy(is, cos);
Modified:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java?rev=946128&r1=946127&r2=946128&view=diff
==============================================================================
---
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
(original)
+++
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java
Wed May 19 11:16:54 2010
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.jetty;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -138,6 +139,16 @@ public class HttpRouteTest extends Camel
String out = context.getTypeConverter().convertTo(String.class,
response);
assertEquals("Get a wrong output " , "PutParameter", out);
}
+
+ @Test
+ public void testDisableStreamCache() throws Exception {
+ String response =
+
template.requestBodyAndHeader("http://localhost:9083/noStreamCache",
+ new ByteArrayInputStream("This is a
test".getBytes()), "Content-Type", "application/xml", String.class);
+
+ assertEquals("Get a wrong output ", "OK", response);
+ }
+
protected void invokeHttpEndpoint() throws IOException {
template.requestBodyAndHeader("http://localhost:9280/test",
expectedBody, "Content-Type", "application/xml");
@@ -205,6 +216,17 @@ public class HttpRouteTest extends Camel
}
});
+
+
from("jetty:http://localhost:9083/noStreamCache?disableStreamCache=true").noStreamCaching().process(new
Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ InputStream is =
(InputStream)exchange.getIn().getBody();
+ System.out.println(is.getClass());
+ assertTrue("It should be a raw inputstream", is
instanceof org.eclipse.jetty.server.HttpInput);
+ exchange.getOut().setBody("OK");
+ }
+
+ });
}
};