camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-6327: More work on new camel-netty-http component.
Date Tue, 18 Jun 2013 15:21:09 GMT
Updated Branches:
  refs/heads/master cf1273af0 -> 90c679c6f


CAMEL-6327: More work on new camel-netty-http component.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/90c679c6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/90c679c6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/90c679c6

Branch: refs/heads/master
Commit: 90c679c6fc604f402c0c997d6de5d5bf1bfe746a
Parents: cf1273a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jun 18 17:18:26 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jun 18 17:18:26 2013 +0200

----------------------------------------------------------------------
 .../netty/http/DefaultNettyHttpBinding.java     | 20 ++++++
 .../netty/http/NettyHttpComponent.java          |  8 ++-
 .../netty/http/NettyHttpConfiguration.java      |  9 +++
 .../http/handlers/HttpServerChannelHandler.java | 17 +++++
 .../HttpServerMultiplexChannelHandler.java      | 11 ++-
 .../http/NettyHttpBridgeEncodedPathTest.java    | 66 ++++++++++++++++++
 ...NettyHttpBridgeRouteUsingHttpClientTest.java | 72 ++++++++++++++++++++
 ...tpProducerBridgePathWithSpacesAtEndTest.java | 54 +++++++++++++++
 .../netty/http/NettyHttpProducerBridgeTest.java | 50 ++++++++++++++
 .../src/test/resources/log4j.properties         |  2 +-
 .../netty/handlers/ServerChannelHandler.java    | 12 ++++
 11 files changed, 315 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
index adef7b9..90ddba3 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
@@ -356,15 +356,35 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding {
 
         TypeConverter tc = message.getExchange().getContext().getTypeConverter();
 
+        // if we bridge endpoint then we need to skip matching headers with the HTTP_QUERY
to avoid sending
+        // duplicated headers to the receiver, so use this skipRequestHeaders as the list
of headers to skip
+        Map<String, Object> skipRequestHeaders = null;
+        if (configuration.isBridgeEndpoint()) {
+            String queryString = message.getHeader(Exchange.HTTP_QUERY, String.class);
+            if (queryString != null) {
+                skipRequestHeaders = URISupport.parseQuery(queryString);
+            }
+            // Need to remove the Host key as it should be not used
+            message.getHeaders().remove("host");
+        }
+
         // append headers
         // must use entrySet to ensure case of keys is preserved
         for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
             String key = entry.getKey();
             Object value = entry.getValue();
+
+            // we should not add headers for the parameters in the uri if we bridge the endpoint
+            // as then we would duplicate headers on both the endpoint uri, and in HTTP headers
as well
+            if (skipRequestHeaders != null && skipRequestHeaders.containsKey(key))
{
+                continue;
+            }
+
             // use an iterator as there can be multiple values. (must not use a delimiter)
             final Iterator<?> it = ObjectHelper.createIterator(value, null, true);
             while (it.hasNext()) {
                 String headerValue = tc.convertTo(String.class, it.next());
+
                 if (headerValue != null && headerFilterStrategy != null
                         && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue,
message.getExchange())) {
                     LOG.trace("HTTP-Header: {}={}", key, headerValue);

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index 6d8183b..e76f524 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -28,6 +28,7 @@ import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.camel.util.URISupport;
+import org.apache.camel.util.UnsafeUriCharactersEncoder;
 
 /**
  * Netty HTTP based component.
@@ -36,7 +37,6 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
 
     // TODO: support on consumer
     // - validate routes on same port cannot have different SSL etc
-    // - bridgeEndpoint
     // - urlrewrite
 
     private final Map<Integer, HttpServerMultiplexChannelHandler> multiplexChannelHandlers
= new HashMap<Integer, HttpServerMultiplexChannelHandler>();
@@ -87,14 +87,16 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
 
     @Override
     protected NettyConfiguration parseConfiguration(NettyConfiguration configuration, String
remaining, Map<String, Object> parameters) throws Exception {
-        configuration.parseURI(new URI(remaining), parameters, this, "http", "https");
+        // ensure uri is encoded to be valid
+        String safe = UnsafeUriCharactersEncoder.encode(remaining);
+        URI uri = new URI(safe);
+        configuration.parseURI(uri, parameters, this, "http", "https");
 
         // force using tcp as the underlying transport
         configuration.setProtocol("tcp");
         configuration.setTextline(false);
 
         if (configuration instanceof NettyHttpConfiguration) {
-            URI uri = new URI(remaining);
             ((NettyHttpConfiguration) configuration).setPath(uri.getPath());
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
index cc71f9f..cc7f154 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
@@ -35,6 +35,7 @@ public class NettyHttpConfiguration extends NettyConfiguration {
     private boolean throwExceptionOnFailure = true;
     private boolean transferException;
     private boolean matchOnUriPrefix;
+    private boolean bridgeEndpoint;
     private String path;
 
     public NettyHttpConfiguration() {
@@ -117,6 +118,14 @@ public class NettyHttpConfiguration extends NettyConfiguration {
         this.matchOnUriPrefix = matchOnUriPrefix;
     }
 
+    public boolean isBridgeEndpoint() {
+        return bridgeEndpoint;
+    }
+
+    public void setBridgeEndpoint(boolean bridgeEndpoint) {
+        this.bridgeEndpoint = bridgeEndpoint;
+    }
+
     public String getPath() {
         return path;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
index 64c1441..95ca27d 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
@@ -24,6 +24,7 @@ import org.apache.camel.component.netty.NettyConsumer;
 import org.apache.camel.component.netty.NettyHelper;
 import org.apache.camel.component.netty.handlers.ServerChannelHandler;
 import org.apache.camel.component.netty.http.NettyHttpConsumer;
+import org.jboss.netty.buffer.ChannelBuffers;
 import org.jboss.netty.channel.ChannelFutureListener;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.ExceptionEvent;
@@ -75,17 +76,26 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
             // are we suspended?
             LOG.debug("Consumer suspended, cannot service request {}", request);
             HttpResponse response = new DefaultHttpResponse(HTTP_1_1, SERVICE_UNAVAILABLE);
+            response.setHeader(Exchange.CONTENT_TYPE, "text/plain");
+            response.setHeader(Exchange.CONTENT_LENGTH, 0);
+            response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
             messageEvent.getChannel().write(response);
             return;
         }
         if (consumer.getEndpoint().getHttpMethodRestrict() != null
                 && !consumer.getEndpoint().getHttpMethodRestrict().contains(request.getMethod().getName()))
{
             HttpResponse response = new DefaultHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED);
+            response.setHeader(Exchange.CONTENT_TYPE, "text/plain");
+            response.setHeader(Exchange.CONTENT_LENGTH, 0);
+            response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
             messageEvent.getChannel().write(response);
             return;
         }
         if ("TRACE".equals(request.getMethod().getName()) && !consumer.getEndpoint().isTraceEnabled())
{
             HttpResponse response = new DefaultHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED);
+            response.setHeader(Exchange.CONTENT_TYPE, "text/plain");
+            response.setHeader(Exchange.CONTENT_LENGTH, 0);
+            response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
             messageEvent.getChannel().write(response);
             return;
         }
@@ -95,6 +105,13 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
     }
 
     @Override
+    protected void beforeProcess(Exchange exchange, MessageEvent messageEvent) {
+        if (consumer.getConfiguration().isBridgeEndpoint()) {
+            exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
+        }
+    }
+
+    @Override
     public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent exceptionEvent)
throws Exception {
         // only close if we are still allowed to run
         if (consumer.isRunAllowed()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
index e00faf8..fdfdc4b 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -20,9 +20,12 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.component.netty.http.ContextPathMatcher;
 import org.apache.camel.component.netty.http.DefaultContextPathMatcher;
 import org.apache.camel.component.netty.http.NettyHttpConsumer;
+import org.apache.camel.util.UnsafeUriCharactersEncoder;
+import org.jboss.netty.buffer.ChannelBuffers;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.ExceptionEvent;
 import org.jboss.netty.channel.MessageEvent;
@@ -86,8 +89,11 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
             ctx.setAttachment(handler);
             handler.messageReceived(ctx, messageEvent);
         } else {
-            // this service is not available
+            // this service is not available, so send empty response back
             HttpResponse response = new DefaultHttpResponse(HTTP_1_1, SERVICE_UNAVAILABLE);
+            response.setHeader(Exchange.CONTENT_TYPE, "text/plain");
+            response.setHeader(Exchange.CONTENT_LENGTH, 0);
+            response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
             messageEvent.getChannel().write(response);
         }
     }
@@ -139,7 +145,8 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
             path = path.substring(0, path.length() - 1);
         }
 
-        return path;
+        String safe = UnsafeUriCharactersEncoder.encode(path);
+        return safe;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeEncodedPathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeEncodedPathTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeEncodedPathTest.java
new file mode 100644
index 0000000..71c0580
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeEncodedPathTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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 org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpBridgeEncodedPathTest extends BaseNettyTest {
+
+    private int port1;
+    private int port2;
+
+    @Test
+    public void testHttpClient() throws Exception {
+        String response = template.requestBody("http://localhost:" + port2 + "/nettyTestRouteA?param1=%2B447777111222",
null, String.class);
+        assertEquals("Get a wrong response", "param1=+447777111222", response);
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+
+                port1 = getPort();
+                port2 = getNextPort();
+
+                errorHandler(noErrorHandler());
+
+                Processor serviceProc = new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        // %2B becomes decoded to a space
+                        Object s = exchange.getIn().getHeader("param1");
+                        // can be either + or %2B
+                        assertTrue(s.equals(" 447777111222") || s.equals("+447777111222")
|| s.equals("%2B447777111222"));
+
+                        // send back the query
+                        exchange.getOut().setBody(exchange.getIn().getHeader(Exchange.HTTP_QUERY));
+                    }
+                };
+                from("netty-http://http://localhost:" + port2 + "/nettyTestRouteA?matchOnUriPrefix=true")
+                        .log("Using NettyTestRouteA route: CamelHttpPath=[${header.CamelHttpPath}],
CamelHttpUri=[${header.CamelHttpUri}]")
+                        .to("netty-http://http://localhost:" + port1 + "/nettyTestRouteB?throwExceptionOnFailure=false&bridgeEndpoint=true");
+
+                from("netty-http://http://localhost:" + port1 + "/nettyTestRouteB?matchOnUriPrefix=true")
+                        .log("Using NettyTestRouteB route: CamelHttpPath=[${header.CamelHttpPath}],
CamelHttpUri=[${header.CamelHttpUri}]")
+                        .process(serviceProc);
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java
new file mode 100644
index 0000000..ff7958b
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.io.ByteArrayInputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpBridgeRouteUsingHttpClientTest extends BaseNettyTest {
+
+    private int port1;
+    private int port2;
+
+    @Test
+    public void testBridge() throws Exception {
+        String response = template.requestBodyAndHeader("http://localhost:" + port2 + "/test/hello",
+                new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml",
String.class);
+        assertEquals("Get a wrong response", "/", response);
+
+        response = template.requestBody("http://localhost:" + port1 + "/hello/world", "hello",
String.class);
+        assertEquals("Get a wrong response", "/hello/world", response);
+
+        try {
+            template.requestBody("http://localhost:" + port2 + "/hello/world", "hello", String.class);
+            fail("Expect exception here!");
+        } catch (Exception ex) {
+            assertTrue("We should get a RuntimeCamelException", ex instanceof RuntimeCamelException);
+        }
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                port1 = getPort();
+                port2 = getNextPort();
+
+                errorHandler(noErrorHandler());
+
+                Processor serviceProc = new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        // get the request URL and copy it to the request body
+                        String uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
+                        exchange.getOut().setBody(uri);
+                    }
+                };
+                from("netty-http:http://localhost:" + port2 + "/test/hello")
+                        .to("http://localhost:" + port1 + "?throwExceptionOnFailure=false&bridgeEndpoint=true");
+
+                from("netty-http:http://localhost:" + port1 + "?matchOnUriPrefix=true").process(serviceProc);
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
new file mode 100644
index 0000000..9baf2c8
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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 org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpProducerBridgePathWithSpacesAtEndTest extends BaseNettyTest {
+
+    private int port1;
+    private int port2;
+
+    @Test
+    public void testProxy() throws Exception {
+        String reply = template.requestBody("netty-http:http://0.0.0.0:" + port1 + "/foo
", "World", String.class);
+        assertEquals("Bye World", reply);
+
+        // and with more spaces
+        String reply2 = template.requestBody("netty-http:http://0.0.0.0:" + port1 + "/foo
/bar baz", "Camel", String.class);
+        assertEquals("Bye Camel", reply2);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                port1 = getPort();
+                port2 = getNextPort();
+
+                from("netty-http:http://0.0.0.0:" + port1 + "/foo ?matchOnUriPrefix=true")
+                        .to("netty-http:http://0.0.0.0:" + port2 + "/proxy foo ?bridgeEndpoint=true&throwExceptionOnFailure=false");
+
+                from("netty-http:http://0.0.0.0:" + port2 + "/proxy foo ?matchOnUriPrefix=true")
+                        .transform().simple("Bye ${body}");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java
new file mode 100644
index 0000000..95109f4
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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 org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpProducerBridgeTest extends BaseNettyTest {
+
+    private int port1;
+    private int port2;
+
+    @Test
+    public void testProxy() throws Exception {
+        String reply = template.requestBody("netty-http:http://0.0.0.0:" + port1 + "/foo",
"World", String.class);
+        assertEquals("Bye World", reply);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                port1 = getPort();
+                port2 = getNextPort();
+
+                from("netty-http:http://0.0.0.0:" + port1 + "/foo")
+                        .to("netty-http:http://0.0.0.0:" + port2 + "/bar?bridgeEndpoint=true&throwExceptionOnFailure=false");
+
+                from("netty-http:http://0.0.0.0:" + port2 + "/bar")
+                        .transform().simple("Bye ${body}");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty-http/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/resources/log4j.properties b/components/camel-netty-http/src/test/resources/log4j.properties
index df84584..7d3c19c 100644
--- a/components/camel-netty-http/src/test/resources/log4j.properties
+++ b/components/camel-netty-http/src/test/resources/log4j.properties
@@ -22,7 +22,7 @@ log4j.rootLogger=INFO, file
 
 # uncomment the following to enable camel debugging
 #log4j.logger.org.apache.camel.component.netty=TRACE
-log4j.logger.org.apache.camel.component.netty.http=DEBUG
+#log4j.logger.org.apache.camel.component.netty.http=DEBUG
 #log4j.logger.org.apache.camel=DEBUG
 #log4j.logger.org.jboss.netty=TRACE
 

http://git-wip-us.apache.org/repos/asf/camel/blob/90c679c6/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
index 1a66cd5..2fa1bd3 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
@@ -95,6 +95,8 @@ public class ServerChannelHandler extends SimpleChannelUpstreamHandler {
             exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.normalizeCharset(consumer.getConfiguration().getCharsetName()));
         }
 
+        beforeProcess(exchange, messageEvent);
+
         // process accordingly to endpoint configuration
         if (consumer.getEndpoint().isSynchronous()) {
             processSynchronously(exchange, messageEvent);
@@ -103,6 +105,16 @@ public class ServerChannelHandler extends SimpleChannelUpstreamHandler
{
         }
     }
 
+    /**
+     * Allows any custom logic before the {@link Exchange} is processed by the routing engine.
+     *
+     * @param exchange       the exchange
+     * @param messageEvent   the Netty message event
+     */
+    protected void beforeProcess(final Exchange exchange, final MessageEvent messageEvent)
{
+        // noop
+    }
+
     private void processSynchronously(final Exchange exchange, final MessageEvent messageEvent)
{
         try {
             consumer.getProcessor().process(exchange);


Mime
View raw message