Updated Branches:
  refs/heads/master a30c165fb -> 079093ec0

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

Branch: refs/heads/master
Commit: 079093ec0ec494d27d58afc0bb6f7a7bd7a0f279
Parents: a30c165
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed Jun 19 13:09:34 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Jun 19 13:09:34 2013 +0200

----------------------------------------------------------------------
 .../apache/camel/util/IntrospectionSupport.java | 23 ++++-
 ...eterAndNoMethodWithNoParameterIssueTest.java | 64 ++++++++++++++
 .../camel/util/IntrospectionSupportTest.java    | 15 ++++
 .../netty/http/NettyHttpComponent.java          | 11 +++
 ...HttpTwoRoutesBootstrapConfigurationTest.java | 93 ++++++++++++++++++++
 .../camel/component/netty/NettyComponent.java   | 12 ++-
 6 files changed, 215 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/079093ec/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java 
b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index 22bb389..3828b71 100755
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -199,10 +199,12 @@ public final class IntrospectionSupport {
         return isSetter(method, false);
     }
 
+
     /**
      * Will inspect the target for properties.
      * <p/>
      * Notice a property must have both a getter/setter method to be included.
+     * Notice all <tt>null</tt> values will be included.
      *
      * @param target         the target bean
      * @param properties     the map to fill in found properties
@@ -210,6 +212,21 @@ public final class IntrospectionSupport {
      * @return <tt>true</tt> if any properties was found, <tt>false</tt> 
otherwise.
      */
     public static boolean getProperties(Object target, Map<String, Object> 
properties, String optionPrefix) {
+        return getProperties(target, properties, optionPrefix, true);
+    }
+
+    /**
+     * Will inspect the target for properties.
+     * <p/>
+     * Notice a property must have both a getter/setter method to be included.
+     *
+     * @param target         the target bean
+     * @param properties     the map to fill in found properties
+     * @param optionPrefix   an optional prefix to append the property key
+     * @param includeNull    whether to include <tt>null</tt> values
+     * @return <tt>true</tt> if any properties was found, <tt>false</tt> 
otherwise.
+     */
+    public static boolean getProperties(Object target, Map<String, Object> 
properties, String optionPrefix, boolean includeNull) {
         ObjectHelper.notNull(target, "target");
         ObjectHelper.notNull(properties, "properties");
         boolean rc = false;
@@ -228,8 +245,10 @@ public final class IntrospectionSupport {
                     // we may want to set options on classes that has package 
view visibility, so override the accessible
                     method.setAccessible(true);
                     Object value = method.invoke(target);
-                    properties.put(optionPrefix + name, value);
-                    rc = true;
+                    if (value != null || includeNull) {
+                        properties.put(optionPrefix + name, value);
+                        rc = true;
+                    }
                 } catch (Exception e) {
                     if (LOG.isTraceEnabled()) {
                         LOG.trace("Error invoking getter method " + method + 
". This exception is ignored.", e);

http://git-wip-us.apache.org/repos/asf/camel/blob/079093ec/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodWithEmptyParameterAndNoMethodWithNoParameterIssueTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodWithEmptyParameterAndNoMethodWithNoParameterIssueTest.java
 
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodWithEmptyParameterAndNoMethodWithNoParameterIssueTest.java
new file mode 100644
index 0000000..45c0292
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanMethodWithEmptyParameterAndNoMethodWithNoParameterIssueTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ *
+ */
+public class BeanMethodWithEmptyParameterAndNoMethodWithNoParameterIssueTest 
extends ContextTestSupport {
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myBean", new MyBean());
+        return jndi;
+    }
+
+    public void testBean() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Camel");
+        getMockEndpoint("mock:result").expectedHeaderReceived("foo", "bar");
+
+        template.sendBody("direct:start", "Camel");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("bean:myBean?method=doSomething()")
+                    .to("mock:result");
+            }
+        };
+    }
+
+    public static final class MyBean {
+
+        public static void doSomething(Exchange exchange) {
+            exchange.getIn().setHeader("foo", "bar");
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/079093ec/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java 
b/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
index 4cf97fa..70be483 100644
--- 
a/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
@@ -194,6 +194,21 @@ public class IntrospectionSupportTest extends 
ContextTestSupport {
         assertEquals("123", map.get("bean.id"));
     }
 
+    public void testGetPropertiesSkipNull() throws Exception {
+        ExampleBean bean = new ExampleBean();
+        bean.setName("Claus");
+        bean.setPrice(10.0);
+        bean.setId(null);
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        IntrospectionSupport.getProperties(bean, map, null, false);
+        assertEquals(2, map.size());
+
+        assertEquals("Claus", map.get("name"));
+        String price = map.get("price").toString();
+        assertTrue(price.startsWith("10"));
+    }
+
     public void testGetProperty() throws Exception {
         ExampleBean bean = new ExampleBean();
         bean.setId("123");

http://git-wip-us.apache.org/repos/asf/camel/blob/079093ec/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 1b0c57c..11a728d 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
@@ -23,9 +23,11 @@ import java.util.Map;
 import org.apache.camel.Endpoint;
 import org.apache.camel.component.netty.NettyComponent;
 import org.apache.camel.component.netty.NettyConfiguration;
+import org.apache.camel.component.netty.NettyServerBootstrapConfiguration;
 import 
org.apache.camel.component.netty.http.handlers.HttpServerMultiplexChannelHandler;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
+import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.camel.util.URISupport;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
@@ -59,6 +61,15 @@ public class NettyHttpComponent extends NettyComponent 
implements HeaderFilterSt
             config = new NettyHttpConfiguration();
         }
 
+        // merge any custom bootstrap configuration on the config
+        NettyServerBootstrapConfiguration bootstrapConfiguration = 
resolveAndRemoveReferenceParameter(parameters, "bootstrapConfiguration", 
NettyServerBootstrapConfiguration.class);
+        if (bootstrapConfiguration != null) {
+            Map<String, Object> options = new HashMap<String, Object>();
+            if (IntrospectionSupport.getProperties(bootstrapConfiguration, 
options, null, false)) {
+                
IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), 
config, options);
+            }
+        }
+
         config = parseConfiguration(config, remaining, parameters);
 
         // validate config

http://git-wip-us.apache.org/repos/asf/camel/blob/079093ec/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java
new file mode 100644
index 0000000..34236e5
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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.apache.camel.component.netty.NettyServerBootstrapConfiguration;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class NettyHttpTwoRoutesBootstrapConfigurationTest extends 
BaseNettyTest {
+
+    private NettyServerBootstrapConfiguration bootstrapConfiguration;
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+
+        // create NettyServerBootstrapConfiguration instance where we can 
configure the bootstrap
+        // option we want to use in our Camel routes. This allows us to 
configure this once,
+        // and also explicit
+        bootstrapConfiguration = new NettyServerBootstrapConfiguration();
+        bootstrapConfiguration.setBacklog(200);
+        bootstrapConfiguration.setConnectTimeout(5000);
+        bootstrapConfiguration.setKeepAlive(true);
+        bootstrapConfiguration.setWorkerCount(4);
+
+        // register the configuration in the registry with this key
+        jndi.bind("myBootstrapOptions", bootstrapConfiguration);
+        return jndi;
+    }
+
+    @Test
+    public void testTwoRoutes() throws Exception {
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel");
+
+        String out = 
template.requestBody("netty-http:http://localhost:{{port}}/foo";, "Hello World", 
String.class);
+        assertEquals("Bye World", out);
+
+        out = template.requestBody("netty-http:http://localhost:{{port}}/bar";, 
"Hello Camel", String.class);
+        assertEquals("Bye Camel", out);
+
+        assertMockEndpointsSatisfied();
+
+        // validate the options
+        NettyHttpConsumer consumer = (NettyHttpConsumer) 
context.getRoute("foo").getConsumer();
+        assertEquals(200, consumer.getConfiguration().getBacklog());
+        assertEquals(4, consumer.getConfiguration().getWorkerCount());
+        assertEquals(true, consumer.getConfiguration().isKeepAlive());
+        assertEquals(5000, consumer.getConfiguration().getConnectTimeout());
+
+        consumer = (NettyHttpConsumer) context.getRoute("bar").getConsumer();
+        assertEquals(200, consumer.getConfiguration().getBacklog());
+        assertEquals(4, consumer.getConfiguration().getWorkerCount());
+        assertEquals(true, consumer.getConfiguration().isKeepAlive());
+        assertEquals(5000, consumer.getConfiguration().getConnectTimeout());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // we want to use the same bootstrap options and want to 
configure this explicit, so we
+                // have a NettyServerBootstrapConfiguration instance in the 
registry, with the key = myBootstrapOptions
+                // which we then tell netty-http to lookup and use
+
+                
from("netty-http:http://0.0.0.0:{{port}}/foo?bootstrapConfiguration=#myBootstrapOptions";).routeId("foo")
+                    .to("mock:foo")
+                    .transform().constant("Bye World");
+
+                
from("netty-http:http://0.0.0.0:{{port}}/bar?bootstrapConfiguration=#myBootstrapOptions";).routeId("bar")
+                    .to("mock:bar")
+                    .transform().constant("Bye Camel");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/079093ec/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
 
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
index 65f095b..a570df8 100644
--- 
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
+++ 
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.netty;
 
 import java.net.URI;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
@@ -24,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.concurrent.CamelThreadFactory;
 import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
 import org.jboss.netty.util.HashedWheelTimer;
@@ -50,9 +52,17 @@ public class NettyComponent extends DefaultComponent {
         } else {
             config = new NettyConfiguration();
         }
-
         config = parseConfiguration(config, remaining, parameters);
 
+        // merge any custom bootstrap configuration on the config
+        NettyServerBootstrapConfiguration bootstrapConfiguration = 
resolveAndRemoveReferenceParameter(parameters, "bootstrapConfiguration", 
NettyServerBootstrapConfiguration.class);
+        if (bootstrapConfiguration != null) {
+            Map<String, Object> options = new HashMap<String, Object>();
+            if (IntrospectionSupport.getProperties(bootstrapConfiguration, 
options, null, false)) {
+                
IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), 
config, options);
+            }
+        }
+
         // validate config
         config.validateConfiguration();
 

Reply via email to