Author: ningjiang
Date: Thu Feb 12 08:22:27 2009
New Revision: 743652
URL: http://svn.apache.org/viewvc?rev=743652&view=rev
Log:
Merged revisions 742906,743613 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r742906 | ningjiang | 2009-02-10 17:22:13 +0800 (Tue, 10 Feb 2009) | 1 line
CAMEL-1327 little refactoring of camel-jetty unit tests
........
r743613 | ningjiang | 2009-02-12 12:02:33 +0800 (Thu, 12 Feb 2009) | 1 line
CAMEL-1327 applied patch with thanks to Roberto, also update the unit tests
for verification
........
Modified:
camel/branches/camel-1.x/ (props changed)
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Feb 12 08:22:27 2009
@@ -1 +1 @@
-/camel/trunk:739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742854,742856,742898
+/camel/trunk:739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742854,742856,742898,742906,743613
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=743652&r1=743651&r2=743652&view=diff
==============================================================================
---
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
(original)
+++
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
Thu Feb 12 08:22:27 2009
@@ -162,10 +162,14 @@
public Object parseBody(HttpMessage httpMessage) throws IOException {
// lets assume the body is a reader
HttpServletRequest request = httpMessage.getRequest();
+ // Need to handle the GET Method which has no inputStream
+ if ("GET".equals(request.getMethod())) {
+ return null;
+ }
if (isUseReaderForPayload()) {
return request.getReader();
} else {
- return request.getInputStream();
+ return GZIPHelper.getInputStream(request);
}
}
Modified:
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java?rev=743652&r1=743651&r2=743652&view=diff
==============================================================================
---
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
(original)
+++
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
Thu Feb 12 08:22:27 2009
@@ -66,7 +66,7 @@
method.getResponseBodyAsStream());
}
- public static InputStream getInputStream(HttpServletRequest request)
throws Exception {
+ public static InputStream getInputStream(HttpServletRequest request)
throws IOException {
InputStream dataStream = request.getInputStream();
String contentEncoding = request.getHeader(CONTENT_ENCODING);
return getGZIPWrappedInputStream(contentEncoding, dataStream);
Modified:
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java?rev=743652&r1=743651&r2=743652&view=diff
==============================================================================
---
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
(original)
+++
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java
Thu Feb 12 08:22:27 2009
@@ -27,33 +27,28 @@
* Unit test for content-type
*/
public class JettyContentTypeTest extends ContextTestSupport {
-
- public void testSameContentType() throws Exception {
+ protected void sendMessageWithContentType(boolean usingGZip) {
Endpoint endpoint =
context.getEndpoint("http://localhost:9080/myapp/myservice");
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("<order>123</order>");
exchange.getIn().setHeader("user", "Claus");
exchange.getIn().setHeader("content-type", "text/xml");
+ if (usingGZip) {
+ GZIPHelper.setGZIPMessageHeader(exchange.getIn());
+ }
template.send(endpoint, exchange);
String body = exchange.getOut().getBody(String.class);
assertEquals("<order>OK</order>", body);
assertOutMessageHeader(exchange, "content-type", "text/xml");
}
+
+ public void testSameContentType() throws Exception {
+ sendMessageWithContentType(false);
+ }
public void testContentTypeWithGZip() throws Exception {
- Endpoint endpoint =
context.getEndpoint("http://localhost:9080/myapp/myservice");
- Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody("<order>123</order>");
- exchange.getIn().setHeader("user", "Claus");
- exchange.getIn().setHeader("content-type", "text/xml");
- GZIPHelper.setGZIPMessageHeader(exchange.getIn());
- template.send(endpoint, exchange);
-
- String body = exchange.getOut().getBody(String.class);
- assertEquals("<order>OK</order>", body);
- assertOutMessageHeader(exchange, "content-type", "text/xml");
- assertOutMessageHeader(exchange, GZIPHelper.CONTENT_ENCODING,
GZIPHelper.GZIP);
+ sendMessageWithContentType(true);
}
public void testMixedContentType() throws Exception {
@@ -72,14 +67,14 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
-
from("jetty:http://localhost:9080/myapp/myservice").process(new
MyBookService());
+
from("jetty:http://localhost:9080/myapp/myservice").streamCaching().process(new
MyBookService());
}
};
}
public class MyBookService implements Processor {
public void process(Exchange exchange) throws Exception {
- if (exchange.getIn().getHeader("user") != null) {
+ if (exchange.getIn().getHeader("user") != null &&
exchange.getIn().getBody(String.class).equals("<order>123</order>")) {
exchange.getOut().setBody("<order>OK</order>");
} else {
exchange.getOut().setBody("FAIL");
Modified:
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java?rev=743652&r1=743651&r2=743652&view=diff
==============================================================================
---
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
(original)
+++
camel/branches/camel-1.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyImageFileTest.java
Thu Feb 12 08:22:27 2009
@@ -29,37 +29,38 @@
* Unit test for exposing a http server that returns images
*/
public class JettyImageFileTest extends ContextTestSupport {
-
- public void testImageContentType() throws Exception {
+
+ private void sendImageContent(boolean usingGZip) throws Exception {
Endpoint endpoint =
context.getEndpoint("http://localhost:9080/myapp/myservice");
- Exchange exchange = endpoint.createExchange();
+ Exchange exchange = endpoint.createExchange();
+ if (usingGZip) {
+ GZIPHelper.setGZIPMessageHeader(exchange.getIn());
+ }
template.send(endpoint, exchange);
assertNotNull(exchange.getOut().getBody());
assertOutMessageHeader(exchange, "Content-Type", "image/jpeg");
}
-
- public void testImageWithGZip() throws Exception {
- Endpoint endpoint =
context.getEndpoint("http://localhost:9080/myapp/myservice");
- Exchange exchange = endpoint.createExchange();
- GZIPHelper.setGZIPMessageHeader(exchange.getIn());
- template.send(endpoint, exchange);
- assertNotNull(exchange.getOut().getBody());
- assertOutMessageHeader(exchange, "Content-Type", "image/jpeg");
+ public void testImageContentType() throws Exception {
+ sendImageContent(false);
+ }
+
+ public void testImageContentWithGZip() throws Exception {
+ sendImageContent(true);
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
-
from("jetty:http://localhost:9080/myapp/myservice").process(new
MyImageService());
+
from("jetty:http://localhost:9080/myapp/myservice").streamCaching().process(new
MyImageService());
}
};
}
public class MyImageService implements Processor {
- public void process(Exchange exchange) throws Exception {
+ public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(new File("src/test/data/logo.jpeg"));
exchange.getOut().setHeader("Content-Type", "image/jpeg");
}