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 2014/10/24 09:00:29 UTC
[3/4] git commit: CAMEL-7848 Need to added the encode and decode
after the http codec
CAMEL-7848 Need to added the encode and decode after the http codec
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2002204e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2002204e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2002204e
Branch: refs/heads/master
Commit: 2002204ea50ad03eb98b75e25b683a6c2a5216c9
Parents: 25ebff7
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Oct 24 14:08:31 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Oct 24 14:08:31 2014 +0800
----------------------------------------------------------------------
.../netty/http/HttpClientPipelineFactory.java | 4 +-
.../netty/http/HttpServerPipelineFactory.java | 10 ++-
.../netty/http/NettyHttpCompressTest.java | 70 ++++++++++++++++++++
3 files changed, 76 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2002204e/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
index 846d690..019a6cd 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
@@ -82,6 +82,8 @@ public class HttpClientPipelineFactory extends ClientPipelineFactory {
pipeline.addLast("ssl", sslHandler);
}
+ pipeline.addLast("http", new HttpClientCodec());
+
List<ChannelHandler> decoders = producer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
@@ -102,8 +104,6 @@ public class HttpClientPipelineFactory extends ClientPipelineFactory {
pipeline.addLast("encoder-" + x, encoder);
}
- pipeline.addLast("http", new HttpClientCodec());
-
if (producer.getConfiguration().getRequestTimeout() > 0) {
if (LOG.isTraceEnabled()) {
LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout());
http://git-wip-us.apache.org/repos/asf/camel/blob/2002204e/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
index 37fc58b..22ea852 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
@@ -86,6 +86,7 @@ public class HttpServerPipelineFactory extends ServerPipelineFactory {
pipeline.addLast("ssl", sslHandler);
}
+ pipeline.addLast("decoder", new HttpRequestDecoder());
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
@@ -95,7 +96,9 @@ public class HttpServerPipelineFactory extends ServerPipelineFactory {
}
pipeline.addLast("decoder-" + x, decoder);
}
+ pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
+ pipeline.addLast("encoder", new HttpResponseEncoder());
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
@@ -105,15 +108,10 @@ public class HttpServerPipelineFactory extends ServerPipelineFactory {
}
pipeline.addLast("encoder-" + x, encoder);
}
-
- pipeline.addLast("decoder", new HttpRequestDecoder());
- pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
-
- pipeline.addLast("encoder", new HttpResponseEncoder());
if (supportCompressed()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
-
+
if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) {
// this must be added just before the HttpServerMultiplexChannelHandler
// use ordered thread pool, to ensure we process the events in order, and can send back
http://git-wip-us.apache.org/repos/asf/camel/blob/2002204e/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java
new file mode 100644
index 0000000..f642b13
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.camel.component.netty.http;
+
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.jboss.netty.channel.ChannelHandler;
+import org.jboss.netty.handler.codec.http.HttpContentDecompressor;
+import org.junit.Test;
+
+public class NettyHttpCompressTest extends BaseNettyTest {
+
+ // setup the decompress decoder here
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
+ decoders.add(new HttpContentDecompressor());
+ registry.bind("myDecoders", decoders);
+ return registry;
+ }
+
+
+ @Test
+ public void testContentType() throws Exception {
+
+ byte[] data = "Hello World".getBytes(Charset.forName("UTF-8"));
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put("content-type", "text/plain; charset=\"UTF-8\"");
+ headers.put("Accept-Encoding", "compress, gzip");
+ String out = template.requestBodyAndHeaders("netty-http:http://0.0.0.0:9001/foo?decoders=#myDecoders", data,
+ headers, String.class);
+ // The decoded out has some space to clean up.
+ assertEquals("Bye World", out.trim());
+
+
+
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("netty-http:http://0.0.0.0:9001/foo?compression=true")
+ .transform().constant("Bye World").setHeader("content-type").constant("text/plain; charset=\"UTF-8\"");
+ }
+ };
+ }
+}