From 3f8dcdde56b3012667a047f7f3b52a6f3640c12c Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Mon, 16 Jun 2014 17:48:09 +0200 Subject: [PATCH] Fix for CAMEL-7512 Expose the component options for Camel Netty --- .../camel/component/netty/NettyComponent.java | 7 ++- .../component/netty/NettyConfiguration.java | 25 ++++++++ .../camel/component/netty/NettyEndpoint.java | 4 ++ ...nentConfigurationAndDocumentationTest.java | 57 +++++++++++++++++++ 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentConfigurationAndDocumentationTest.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 a570df82634c8..62028e669c84d 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 @@ -24,24 +24,25 @@ import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; -import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.impl.UriEndpointComponent; 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; import org.jboss.netty.util.Timer; -public class NettyComponent extends DefaultComponent { +public class NettyComponent extends UriEndpointComponent { // use a shared timer for Netty (see javadoc for HashedWheelTimer) private static volatile Timer timer; private NettyConfiguration configuration; private OrderedMemoryAwareThreadPoolExecutor executorService; public NettyComponent() { + super(NettyEndpoint.class); } public NettyComponent(CamelContext context) { - super(context); + super(context, NettyEndpoint.class); } @Override diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java index 83ab62d4b4685..f61e12b4863c1 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java @@ -25,6 +25,8 @@ import org.apache.camel.LoggingLevel; import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; import org.apache.camel.util.EndpointHelper; import org.apache.camel.util.IntrospectionSupport; import org.apache.camel.util.ObjectHelper; @@ -36,33 +38,56 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@UriParams public class NettyConfiguration extends NettyServerBootstrapConfiguration implements Cloneable { private static final Logger LOG = LoggerFactory.getLogger(NettyConfiguration.class); + @UriParam private long requestTimeout; + @UriParam private boolean sync = true; + @UriParam private boolean textline; + @UriParam private TextLineDelimiter delimiter = TextLineDelimiter.LINE; + @UriParam private boolean autoAppendDelimiter = true; + @UriParam private int decoderMaxLineLength = 1024; + @UriParam private String encoding; private List encoders = new ArrayList(); private List decoders = new ArrayList(); + @UriParam private boolean disconnect; + @UriParam private boolean lazyChannelCreation = true; + @UriParam private boolean transferExchange; + @UriParam private boolean disconnectOnNoReply = true; + @UriParam private LoggingLevel noReplyLogLevel = LoggingLevel.WARN; + @UriParam private LoggingLevel serverExceptionCaughtLogLevel = LoggingLevel.WARN; + @UriParam private LoggingLevel serverClosedChannelExceptionCaughtLogLevel = LoggingLevel.DEBUG; + @UriParam private boolean allowDefaultCodec = true; private ClientPipelineFactory clientPipelineFactory; + @UriParam private int maximumPoolSize = 16; + @UriParam private boolean orderedThreadPoolExecutor = true; + @UriParam private int producerPoolMaxActive = -1; + @UriParam private int producerPoolMinIdle; + @UriParam private int producerPoolMaxIdle = 100; + @UriParam private long producerPoolMinEvictableIdle = 5 * 60 * 1000L; + @UriParam private boolean producerPoolEnabled = true; /** diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java index 7b464fa0a3d87..10c7acacd92ec 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java @@ -29,13 +29,17 @@ import org.apache.camel.Producer; import org.apache.camel.impl.DefaultEndpoint; import org.apache.camel.impl.SynchronousDelegateProducer; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; import org.apache.camel.util.ObjectHelper; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.handler.ssl.SslHandler; import org.jboss.netty.util.Timer; +@UriEndpoint(scheme = "netty", consumerClass = NettyConsumer.class) public class NettyEndpoint extends DefaultEndpoint { + @UriParam private NettyConfiguration configuration; private Timer timer; diff --git a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentConfigurationAndDocumentationTest.java b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentConfigurationAndDocumentationTest.java new file mode 100644 index 0000000000000..67b3ab0ec1bb2 --- /dev/null +++ b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentConfigurationAndDocumentationTest.java @@ -0,0 +1,57 @@ +/** + * 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; + +import org.apache.camel.CamelContext; +import org.apache.camel.ComponentConfiguration; +import org.apache.camel.EndpointConfiguration; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class NettyComponentConfigurationAndDocumentationTest extends CamelTestSupport { + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testComponentConfiguration() throws Exception { + NettyComponent comp = context.getComponent("netty", NettyComponent.class); + EndpointConfiguration conf = comp.createConfiguration("netty:tcp://localhost:5150?sync=true" + + "&maximumPoolSize=32&ssl=true&passphrase=#password"); + + assertEquals("true", conf.getParameter("sync")); + assertEquals("32", conf.getParameter("maximumPoolSize")); + + ComponentConfiguration compConf = comp.createComponentConfiguration(); + String json = compConf.createParameterJsonSchema(); + assertNotNull(json); + + assertTrue(json.contains("\"producerPoolMinEvictableIdle\": { \"type\": \"long\" }")); + assertTrue(json.contains("\"allowDefaultCodec\": { \"type\": \"boolean\" }")); + } + + @Test + public void testComponentDocumentation() throws Exception { + CamelContext context = new DefaultCamelContext(); + String html = context.getComponentDocumentation("netty"); + assertNotNull("Should have found some auto-generated HTML if on Java 7", html); + } + +}