You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/06/18 13:02:54 UTC

[1/3] git commit: CAMEL-6327: More work on new camel-netty-http component.

Updated Branches:
  refs/heads/master 1bb480f57 -> cf1273af0


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/2e278438
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2e278438
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2e278438

Branch: refs/heads/master
Commit: 2e2784384d3dc2052f42803a33f4576a59d38afe
Parents: 1bb480f
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jun 18 12:03:16 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jun 18 12:03:16 2013 +0200

----------------------------------------------------------------------
 .../http/HttpNettyServerBootstrapFactory.java     | 15 +++++++++------
 .../component/netty/http/NettyHttpComponent.java  |  3 ++-
 .../camel/component/netty/NettyConsumer.java      |  5 +++--
 .../netty/NettyServerBootstrapFactory.java        |  7 +++++++
 .../SingleTCPNettyServerBootstrapFactory.java     | 18 ++++++++++++------
 .../SingleUDPNettyServerBootstrapFactory.java     | 18 ++++++++++++------
 6 files changed, 45 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java
index f0c724c..3bcc7ab 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java
@@ -19,19 +19,22 @@ package org.apache.camel.component.netty.http;
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.netty.NettyConfiguration;
 import org.apache.camel.component.netty.NettyConsumer;
-import org.apache.camel.component.netty.ServerPipelineFactory;
 import org.apache.camel.component.netty.SingleTCPNettyServerBootstrapFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
 
 public class HttpNettyServerBootstrapFactory extends SingleTCPNettyServerBootstrapFactory {
 
     private final NettyHttpComponent component;
-    private final int port;
+    private int port;
 
-    public HttpNettyServerBootstrapFactory(CamelContext camelContext, NettyConfiguration nettyConfiguration, ServerPipelineFactory pipelineFactory,
-                                           NettyHttpComponent component) {
-        super(camelContext, nettyConfiguration, pipelineFactory);
+    public HttpNettyServerBootstrapFactory(NettyHttpComponent component) {
         this.component = component;
-        this.port = nettyConfiguration.getPort();
+    }
+
+    @Override
+    public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
+        super.init(camelContext, configuration, pipelineFactory);
+        this.port = configuration.getPort();
     }
 
     public void addConsumer(NettyConsumer consumer) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/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 23762a8..4c775ae 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
@@ -131,7 +131,8 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
         String key = consumer.getConfiguration().getAddress();
         HttpNettyServerBootstrapFactory answer = bootstrapFactories.get(key);
         if (answer == null) {
-            answer = new HttpNettyServerBootstrapFactory(getCamelContext(), consumer.getConfiguration(), new HttpServerPipelineFactory(consumer), this);
+            answer = new HttpNettyServerBootstrapFactory(this);
+            answer.init(getCamelContext(), consumer.getConfiguration(), new HttpServerPipelineFactory(consumer));
             bootstrapFactories.put(key, answer);
         }
         return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
index b2ca07c..6234cba 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
@@ -58,10 +58,11 @@ public class NettyConsumer extends DefaultConsumer {
 
         if (nettyServerBootstrapFactory == null) {
             if (isTcp()) {
-                nettyServerBootstrapFactory = new SingleTCPNettyServerBootstrapFactory(context, getConfiguration(), pipelineFactory);
+                nettyServerBootstrapFactory = new SingleTCPNettyServerBootstrapFactory();
             } else {
-                nettyServerBootstrapFactory = new SingleUDPNettyServerBootstrapFactory(context, getConfiguration(), pipelineFactory);
+                nettyServerBootstrapFactory = new SingleUDPNettyServerBootstrapFactory();
             }
+            nettyServerBootstrapFactory.init(context, configuration, pipelineFactory);
         }
 
         ServiceHelper.startServices(nettyServerBootstrapFactory);

http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java
index 675f70e..6dbb817 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBootstrapFactory.java
@@ -16,8 +16,10 @@
  */
 package org.apache.camel.component.netty;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Service;
 import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelPipelineFactory;
 
 /**
  * Factory for setting up Netty {@link org.jboss.netty.bootstrap.ServerBootstrap} and all
@@ -29,6 +31,11 @@ import org.jboss.netty.channel.Channel;
 public interface NettyServerBootstrapFactory extends Service {
 
     /**
+     * Initializes this {@link NettyServerBootstrapFactory}.
+     */
+    void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory);
+
+    /**
      * When a new {@link Channel} is opened.
      */
     void addChannel(Channel channel);

http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java
index 57df5d0..22b2d49 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleTCPNettyServerBootstrapFactory.java
@@ -22,9 +22,11 @@ import java.util.concurrent.ExecutorService;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.ObjectHelper;
 import org.jboss.netty.bootstrap.ServerBootstrap;
 import org.jboss.netty.channel.Channel;
 import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
 import org.jboss.netty.channel.group.ChannelGroup;
 import org.jboss.netty.channel.group.ChannelGroupFuture;
 import org.jboss.netty.channel.group.DefaultChannelGroup;
@@ -38,21 +40,24 @@ import org.slf4j.LoggerFactory;
 public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport implements NettyServerBootstrapFactory {
 
     protected static final Logger LOG = LoggerFactory.getLogger(SingleTCPNettyServerBootstrapFactory.class);
-    private final CamelContext camelContext;
-    private final NettyConfiguration configuration;
     private final ChannelGroup allChannels;
-    private final ServerPipelineFactory pipelineFactory;
+    private CamelContext camelContext;
+    private NettyConfiguration configuration;
+    private ChannelPipelineFactory pipelineFactory;
     private ChannelFactory channelFactory;
     private ServerBootstrap serverBootstrap;
     private Channel channel;
     private ExecutorService bossExecutor;
     private ExecutorService workerExecutor;
 
-    public SingleTCPNettyServerBootstrapFactory(CamelContext camelContext, NettyConfiguration nettyConfiguration, ServerPipelineFactory pipelineFactory) {
+    public SingleTCPNettyServerBootstrapFactory() {
+        this.allChannels = new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName());
+    }
+
+    public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
         this.camelContext = camelContext;
-        this.configuration = nettyConfiguration;
+        this.configuration = configuration;
         this.pipelineFactory = pipelineFactory;
-        this.allChannels = new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName());
     }
 
     public void addChannel(Channel channel) {
@@ -73,6 +78,7 @@ public class SingleTCPNettyServerBootstrapFactory extends ServiceSupport impleme
 
     @Override
     protected void doStart() throws Exception {
+        ObjectHelper.notNull(camelContext, "CamelContext");
         startServerBoostrap();
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/2e278438/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java
index 8c43990..ea6e5a0 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/SingleUDPNettyServerBootstrapFactory.java
@@ -22,8 +22,10 @@ import java.util.concurrent.ExecutorService;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.ObjectHelper;
 import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
 import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelPipelineFactory;
 import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
 import org.jboss.netty.channel.group.ChannelGroup;
 import org.jboss.netty.channel.group.ChannelGroupFuture;
@@ -39,21 +41,24 @@ import org.slf4j.LoggerFactory;
 public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport implements NettyServerBootstrapFactory {
 
     protected static final Logger LOG = LoggerFactory.getLogger(SingleUDPNettyServerBootstrapFactory.class);
-    private final CamelContext camelContext;
-    private final NettyConfiguration configuration;
     private final ChannelGroup allChannels;
-    private final ServerPipelineFactory pipelineFactory;
+    private CamelContext camelContext;
+    private NettyConfiguration configuration;
+    private ChannelPipelineFactory pipelineFactory;
     private DatagramChannelFactory datagramChannelFactory;
     private ConnectionlessBootstrap connectionlessServerBootstrap;
     private Channel channel;
     private ExecutorService bossExecutor;
     private ExecutorService workerExecutor;
 
-    public SingleUDPNettyServerBootstrapFactory(CamelContext camelContext, NettyConfiguration nettyConfiguration, ServerPipelineFactory pipelineFactory) {
+    public SingleUDPNettyServerBootstrapFactory() {
+        this.allChannels = new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName());
+    }
+
+    public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
         this.camelContext = camelContext;
-        this.configuration = nettyConfiguration;
+        this.configuration = configuration;
         this.pipelineFactory = pipelineFactory;
-        this.allChannels = new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName());
     }
 
     public void addChannel(Channel channel) {
@@ -74,6 +79,7 @@ public class SingleUDPNettyServerBootstrapFactory extends ServiceSupport impleme
 
     @Override
     protected void doStart() throws Exception {
+        ObjectHelper.notNull(camelContext, "CamelContext");
         startServerBootstrap();
     }
 


[2/3] git commit: CAMEL-6327: More work on new camel-netty-http component.

Posted by da...@apache.org.
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/aac94287
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/aac94287
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/aac94287

Branch: refs/heads/master
Commit: aac942878b5b54f9a25941c1d83c22059855beec
Parents: 2e27843
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jun 18 12:24:01 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jun 18 12:25:24 2013 +0200

----------------------------------------------------------------------
 .../http/HttpNettyServerBootstrapFactory.java   | 60 ---------------
 .../netty/http/HttpServerBootstrapFactory.java  | 81 ++++++++++++++++++++
 .../netty/http/NettyHttpComponent.java          |  8 +-
 .../component/netty/http/NettyHttpConsumer.java |  2 +-
 .../component/netty/http/NettyHttpEndpoint.java |  2 +-
 .../http/handlers/HttpServerChannelHandler.java |  5 +-
 .../HttpServerMultiplexChannelHandler.java      |  5 +-
 .../src/test/resources/log4j.properties         |  1 +
 8 files changed, 90 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java
deleted file mode 100644
index 3bcc7ab..0000000
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpNettyServerBootstrapFactory.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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.CamelContext;
-import org.apache.camel.component.netty.NettyConfiguration;
-import org.apache.camel.component.netty.NettyConsumer;
-import org.apache.camel.component.netty.SingleTCPNettyServerBootstrapFactory;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-
-public class HttpNettyServerBootstrapFactory extends SingleTCPNettyServerBootstrapFactory {
-
-    private final NettyHttpComponent component;
-    private int port;
-
-    public HttpNettyServerBootstrapFactory(NettyHttpComponent component) {
-        this.component = component;
-    }
-
-    @Override
-    public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
-        super.init(camelContext, configuration, pipelineFactory);
-        this.port = configuration.getPort();
-    }
-
-    public void addConsumer(NettyConsumer consumer) {
-        component.getMultiplexChannelHandler(port).addConsumer((NettyHttpConsumer) consumer);
-    }
-
-    @Override
-    public void removeConsumer(NettyConsumer consumer) {
-        component.getMultiplexChannelHandler(port).removeConsumer((NettyHttpConsumer) consumer);
-    }
-
-    @Override
-    public void stop() throws Exception {
-        // only stop if no more active consumers
-        int consumers = component.getMultiplexChannelHandler(port).consumers();
-        if (consumers == 0) {
-            super.stop();
-        } else {
-            LOG.info("There are {} active consumers, so cannot stop {} yet.", consumers, HttpNettyServerBootstrapFactory.class.getName());
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java
new file mode 100644
index 0000000..d004d96
--- /dev/null
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java
@@ -0,0 +1,81 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.component.netty.NettyConfiguration;
+import org.apache.camel.component.netty.NettyConsumer;
+import org.apache.camel.component.netty.SingleTCPNettyServerBootstrapFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HttpServerBootstrapFactory extends SingleTCPNettyServerBootstrapFactory {
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpServerBootstrapFactory.class);
+    private final NettyHttpComponent component;
+    private int port;
+
+    public HttpServerBootstrapFactory(NettyHttpComponent component) {
+        this.component = component;
+    }
+
+    @Override
+    public void init(CamelContext camelContext, NettyConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
+        super.init(camelContext, configuration, pipelineFactory);
+        this.port = configuration.getPort();
+
+        LOG.info("BootstrapFactory on port {} is using configuration: {}", port, configuration);
+    }
+
+    public void addConsumer(NettyConsumer consumer) {
+        if (LOG.isDebugEnabled()) {
+            NettyHttpConsumer httpConsumer = (NettyHttpConsumer) consumer;
+            LOG.debug("BootstrapFactory on port {} is adding consumer with context-path {}", port, httpConsumer.getConfiguration().getPath());
+        }
+        component.getMultiplexChannelHandler(port).addConsumer((NettyHttpConsumer) consumer);
+    }
+
+    @Override
+    public void removeConsumer(NettyConsumer consumer) {
+        if (LOG.isDebugEnabled()) {
+            NettyHttpConsumer httpConsumer = (NettyHttpConsumer) consumer;
+            LOG.debug("BootstrapFactory on port {} is removing consumer with context-path {}", port, httpConsumer.getConfiguration().getPath());
+        }
+        component.getMultiplexChannelHandler(port).removeConsumer((NettyHttpConsumer) consumer);
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        LOG.debug("BootstrapFactory on port {} is starting", port);
+        super.doStart();
+    }
+
+    @Override
+    public void stop() throws Exception {
+        // only stop if no more active consumers
+        int consumers = component.getMultiplexChannelHandler(port).consumers();
+        if (consumers == 0) {
+            LOG.debug("BootstrapFactory on port {} is stopping", port);
+            super.stop();
+        } else {
+            LOG.debug("BootstrapFactory on port {} has {} active consumers, so cannot stop {} yet.",
+                    new Object[]{port, consumers, HttpServerBootstrapFactory.class.getName()});
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/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 4c775ae..8dfe774 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
@@ -41,7 +41,7 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
     // - urlrewrite
 
     private final Map<Integer, HttpServerMultiplexChannelHandler> multiplexChannelHandlers = new HashMap<Integer, HttpServerMultiplexChannelHandler>();
-    private final Map<String, HttpNettyServerBootstrapFactory> bootstrapFactories = new HashMap<String, HttpNettyServerBootstrapFactory>();
+    private final Map<String, HttpServerBootstrapFactory> bootstrapFactories = new HashMap<String, HttpServerBootstrapFactory>();
     private NettyHttpBinding nettyHttpBinding;
     private HeaderFilterStrategy headerFilterStrategy;
 
@@ -127,11 +127,11 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
         return answer;
     }
 
-    protected synchronized HttpNettyServerBootstrapFactory getOrCreateHttpNettyServerBootstrapFactory(NettyHttpConsumer consumer) {
+    protected synchronized HttpServerBootstrapFactory getOrCreateHttpNettyServerBootstrapFactory(NettyHttpConsumer consumer) {
         String key = consumer.getConfiguration().getAddress();
-        HttpNettyServerBootstrapFactory answer = bootstrapFactories.get(key);
+        HttpServerBootstrapFactory answer = bootstrapFactories.get(key);
         if (answer == null) {
-            answer = new HttpNettyServerBootstrapFactory(this);
+            answer = new HttpServerBootstrapFactory(this);
             answer.init(getCamelContext(), consumer.getConfiguration(), new HttpServerPipelineFactory(consumer));
             bootstrapFactories.put(key, answer);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConsumer.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConsumer.java
index 8c60595..2c27204 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConsumer.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConsumer.java
@@ -43,7 +43,7 @@ public class NettyHttpConsumer extends NettyConsumer {
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-        ObjectHelper.notNull(getNettyServerBootstrapFactory(), "HttpNettyServerBootstrapFactory", this);
+        ObjectHelper.notNull(getNettyServerBootstrapFactory(), "HttpServerBootstrapFactory", this);
         getNettyServerBootstrapFactory().addConsumer(this);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
index 2c9399f..011ce65 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
@@ -57,7 +57,7 @@ public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStra
         NettyHttpConsumer answer = new NettyHttpConsumer(this, processor, getConfiguration());
         configureConsumer(answer);
         // reuse pipeline factory for the same address
-        HttpNettyServerBootstrapFactory factory = getComponent().getOrCreateHttpNettyServerBootstrapFactory(answer);
+        HttpServerBootstrapFactory factory = getComponent().getOrCreateHttpNettyServerBootstrapFactory(answer);
         // force using our server bootstrap factory
         answer.setNettyServerBootstrapFactory(factory);
         return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/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 e556cba..64c1441 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
@@ -62,10 +62,7 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
         // store request, as this channel handler is created per pipeline
         request = (HttpRequest) messageEvent.getMessage();
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Message received: {}", request);
-            LOG.debug("   is keep-alive: {}", isKeepAlive(request));
-        }
+        LOG.debug("Message received: {}", request);
 
         if (is100ContinueExpected(request)) {
             // send back http 100 response to continue

http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/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 9237281..3760d2a 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
@@ -74,10 +74,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
         // store request, as this channel handler is created per pipeline
         HttpRequest request = (HttpRequest) messageEvent.getMessage();
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Message received: {}", request);
-            LOG.debug("   is keep-alive: {}", isKeepAlive(request));
-        }
+        LOG.debug("Message received: {}", request);
 
         HttpServerChannelHandler handler = getHandler(request);
         if (handler != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/aac94287/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 d7285ad..df84584 100644
--- a/components/camel-netty-http/src/test/resources/log4j.properties
+++ b/components/camel-netty-http/src/test/resources/log4j.properties
@@ -22,6 +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=DEBUG
 #log4j.logger.org.jboss.netty=TRACE
 


[3/3] git commit: CAMEL-6327: More work on new camel-netty-http component.

Posted by da...@apache.org.
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/cf1273af
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cf1273af
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cf1273af

Branch: refs/heads/master
Commit: cf1273af032e28b187a99a9f525fc1db7eff461c
Parents: aac9428
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jun 18 13:02:43 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jun 18 13:02:43 2013 +0200

----------------------------------------------------------------------
 .../netty/http/ContextPathMatcher.java          | 36 ++++++++++
 .../netty/http/DefaultContextPathMatcher.java   | 72 ++++++++++++++++++++
 .../netty/http/HttpServerBootstrapFactory.java  |  3 +-
 .../netty/http/NettyHttpComponent.java          |  1 -
 .../netty/http/NettyHttpConfiguration.java      |  9 +++
 .../HttpServerMultiplexChannelHandler.java      | 22 ++++--
 .../NettyHttpTwoRoutesMatchOnUriPrefixTest.java | 68 ++++++++++++++++++
 .../camel/component/netty/NettyConsumer.java    | 18 ++---
 8 files changed, 210 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java
new file mode 100644
index 0000000..030fb9f
--- /dev/null
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/ContextPathMatcher.java
@@ -0,0 +1,36 @@
+/**
+ * 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;
+
+/**
+ * A matcher used for selecting the correct {@link org.apache.camel.component.netty.http.handlers.HttpServerChannelHandler}
+ * to handle an incoming {@link org.jboss.netty.handler.codec.http.HttpRequest} when you use multiple routes on the same
+ * port.
+ * <p/>
+ * As when we do that, we need to multiplex and select the correct consumer route to process the HTTP request.
+ * To do that we need to match on the incoming HTTP request context-path from the request.
+ */
+public interface ContextPathMatcher {
+
+    /**
+     * Whether the target context-path matches.
+     *
+     * @param target  the context-path from the incoming HTTP request
+     * @return <tt>true</tt> to match, <tt>false</tt> if not.
+     */
+    boolean matches(String target);
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
new file mode 100644
index 0000000..55bfb58
--- /dev/null
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.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.util.Locale;
+
+/**
+ * A default {@link ContextPathMatcher} which supports the <tt>matchOnUriPrefix</tt> option.
+ */
+public class DefaultContextPathMatcher implements ContextPathMatcher {
+
+    private final String path;
+    private final boolean matchOnUriPrefix;
+
+    public DefaultContextPathMatcher(String path, boolean matchOnUriPrefix) {
+        this.path = path.toLowerCase(Locale.US);
+        this.matchOnUriPrefix = matchOnUriPrefix;
+    }
+
+    public boolean matches(String target) {
+        target = target.toLowerCase(Locale.US);
+        if (!matchOnUriPrefix) {
+            // exact match
+            return target.equals(path);
+        } else {
+            // match on prefix, then we just need to match the start of the context-path
+            return target.startsWith(path);
+        }
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        DefaultContextPathMatcher that = (DefaultContextPathMatcher) o;
+
+        if (matchOnUriPrefix != that.matchOnUriPrefix) {
+            return false;
+        }
+        if (!path.equals(that.path)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = path.hashCode();
+        result = 31 * result + (matchOnUriPrefix ? 1 : 0);
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java
index d004d96..223ccdb 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerBootstrapFactory.java
@@ -73,8 +73,7 @@ public class HttpServerBootstrapFactory extends SingleTCPNettyServerBootstrapFac
             LOG.debug("BootstrapFactory on port {} is stopping", port);
             super.stop();
         } else {
-            LOG.debug("BootstrapFactory on port {} has {} active consumers, so cannot stop {} yet.",
-                    new Object[]{port, consumers, HttpServerBootstrapFactory.class.getName()});
+            LOG.debug("BootstrapFactory on port {} has {} registered consumers, so cannot stop yet.", port, consumers);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/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 8dfe774..6d8183b 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
@@ -37,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
-    // - matchOnUriPrefix
     // - urlrewrite
 
     private final Map<Integer, HttpServerMultiplexChannelHandler> multiplexChannelHandlers = new HashMap<Integer, HttpServerMultiplexChannelHandler>();

http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/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 a89ef96..cc71f9f 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
@@ -34,6 +34,7 @@ public class NettyHttpConfiguration extends NettyConfiguration {
     private boolean compression;
     private boolean throwExceptionOnFailure = true;
     private boolean transferException;
+    private boolean matchOnUriPrefix;
     private String path;
 
     public NettyHttpConfiguration() {
@@ -108,6 +109,14 @@ public class NettyHttpConfiguration extends NettyConfiguration {
         this.mapHeaders = mapHeaders;
     }
 
+    public boolean isMatchOnUriPrefix() {
+        return matchOnUriPrefix;
+    }
+
+    public void setMatchOnUriPrefix(boolean matchOnUriPrefix) {
+        this.matchOnUriPrefix = matchOnUriPrefix;
+    }
+
     public String getPath() {
         return path;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/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 3760d2a..e00faf8 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
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.netty.http.handlers;
 
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+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.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.ExceptionEvent;
@@ -30,7 +33,6 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.jboss.netty.handler.codec.http.HttpHeaders.isKeepAlive;
 import static org.jboss.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE;
 import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
 
@@ -43,7 +45,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
 
     // use NettyHttpConsumer as logger to make it easier to read the logs as this is part of the consumer
     private static final transient Logger LOG = LoggerFactory.getLogger(NettyHttpConsumer.class);
-    private final ConcurrentMap<String, HttpServerChannelHandler> consumers = new ConcurrentHashMap<String, HttpServerChannelHandler>();
+    private final ConcurrentMap<ContextPathMatcher, HttpServerChannelHandler> consumers = new ConcurrentHashMap<ContextPathMatcher, HttpServerChannelHandler>();
     private final String token;
     private final int len;
 
@@ -54,12 +56,14 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
 
     public void addConsumer(NettyHttpConsumer consumer) {
         String path = pathAsKey(consumer.getConfiguration().getPath());
-        consumers.put(path, new HttpServerChannelHandler(consumer));
+        ContextPathMatcher matcher = new DefaultContextPathMatcher(path, consumer.getConfiguration().isMatchOnUriPrefix());
+        consumers.put(matcher, new HttpServerChannelHandler(consumer));
     }
 
     public void removeConsumer(NettyHttpConsumer consumer) {
         String path = pathAsKey(consumer.getConfiguration().getPath());
-        consumers.remove(path);
+        ContextPathMatcher matcher = new DefaultContextPathMatcher(path, consumer.getConfiguration().isMatchOnUriPrefix());
+        consumers.remove(matcher);
     }
 
     /**
@@ -106,12 +110,16 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
             path = path.substring(idx + len);
         }
 
-        // TODO: support matchOnUriPrefix
-
         // use the path as key to find the consumer handler to use
         path = pathAsKey(path);
 
-        return consumers.get(path);
+        // find the one that matches
+        for (Map.Entry<ContextPathMatcher, HttpServerChannelHandler> entry : consumers.entrySet()) {
+            if (entry.getKey().matches(path)) {
+                return entry.getValue();
+            }
+        }
+        return null;
     }
 
     private static String pathAsKey(String path) {

http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
new file mode 100644
index 0000000..382e2c9
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpTwoRoutesMatchOnUriPrefixTest extends BaseNettyTest {
+
+    @Test
+    public void testTwoRoutesMatchOnUriPrefix() throws Exception {
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel", "Hi Camel");
+
+        String out = template.requestBody("netty-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+        assertEquals("Bye World", out);
+
+        // the foo is not match on prefix so we cannot do /foo/beer
+        try {
+            template.requestBody("netty-http:http://localhost:{{port}}/foo/beer", "Hello World", String.class);
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+            assertEquals(503, cause.getStatusCode());
+        }
+
+        out = template.requestBody("netty-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);
+        assertEquals("Bye Camel", out);
+
+        // the bar is match on prefix so we can do /bar/beer
+        out = template.requestBody("netty-http:http://localhost:{{port}}/bar/beer", "Hi Camel", String.class);
+        assertEquals("Bye Camel", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty-http:http://0.0.0.0:{{port}}/foo")
+                    .to("mock:foo")
+                    .transform().constant("Bye World");
+
+                from("netty-http:http://0.0.0.0:{{port}}/bar?matchOnUriPrefix=true")
+                    .to("mock:bar")
+                    .transform().constant("Bye Camel");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/cf1273af/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
index 6234cba..6435b40 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
@@ -47,16 +47,16 @@ public class NettyConsumer extends DefaultConsumer {
 
         LOG.debug("Netty consumer binding to: {}", configuration.getAddress());
 
-        // setup pipeline factory
-        ServerPipelineFactory pipelineFactory;
-        ServerPipelineFactory factory = configuration.getServerPipelineFactory();
-        if (factory != null) {
-            pipelineFactory = factory.createPipelineFactory(this);
-        } else {
-            pipelineFactory = new DefaultServerPipelineFactory(this);
-        }
-
         if (nettyServerBootstrapFactory == null) {
+            // setup pipeline factory
+            ServerPipelineFactory pipelineFactory;
+            ServerPipelineFactory factory = configuration.getServerPipelineFactory();
+            if (factory != null) {
+                pipelineFactory = factory.createPipelineFactory(this);
+            } else {
+                pipelineFactory = new DefaultServerPipelineFactory(this);
+            }
+
             if (isTcp()) {
                 nettyServerBootstrapFactory = new SingleTCPNettyServerBootstrapFactory();
             } else {