Repository: camel Updated Branches: refs/heads/master 8cd7ceb7b -> 00b64c8ad
http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultServerPipelineFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultServerPipelineFactory.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultServerPipelineFactory.java deleted file mode 100644 index 92c1b21..0000000 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/DefaultServerPipelineFactory.java +++ /dev/null @@ -1,191 +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.netty4; - -import java.util.List; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelPipeline; -import io.netty.handler.ssl.SslHandler; -import io.netty.util.concurrent.EventExecutorGroup; - -import org.apache.camel.CamelContext; -import org.apache.camel.component.netty4.handlers.ServerChannelHandler; -import org.apache.camel.component.netty4.ssl.SSLEngineFactory; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DefaultServerPipelineFactory extends ServerPipelineFactory { - private static final Logger LOG = LoggerFactory.getLogger(DefaultServerPipelineFactory.class); - - private NettyConsumer consumer; - private SSLContext sslContext; - - @Deprecated - public DefaultServerPipelineFactory(NettyServerBootstrapConfiguration configuration) { - this.consumer = null; - try { - this.sslContext = createSSLContext(null, configuration); - } catch (Exception e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } - - if (sslContext != null) { - LOG.info("Created SslContext {}", sslContext); - } - } - - public DefaultServerPipelineFactory(NettyConsumer consumer) { - this.consumer = consumer; - try { - this.sslContext = createSSLContext(consumer.getContext(), consumer.getConfiguration()); - } catch (Exception e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } - - if (sslContext != null) { - LOG.info("Created SslContext {}", sslContext); - } - } - - @Override - protected void initChannel(Channel ch) throws Exception { - // create a new pipeline - ChannelPipeline channelPipeline = ch.pipeline(); - - SslHandler sslHandler = configureServerSSLOnDemand(); - if (sslHandler != null) { - //TODO must close on SSL exception - //sslHandler.setCloseOnSSLException(true); - LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler); - addToPipeline("ssl", channelPipeline, sslHandler); - } - - List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders(); - for (int x = 0; x < encoders.size(); x++) { - ChannelHandler encoder = encoders.get(x); - if (encoder instanceof ChannelHandlerFactory) { - // use the factory to create a new instance of the channel as it may not be shareable - encoder = ((ChannelHandlerFactory) encoder).newChannelHandler(); - } - addToPipeline("encoder-" + x, channelPipeline, encoder); - } - - List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders(); - for (int x = 0; x < decoders.size(); x++) { - ChannelHandler decoder = decoders.get(x); - if (decoder instanceof ChannelHandlerFactory) { - // use the factory to create a new instance of the channel as it may not be shareable - decoder = ((ChannelHandlerFactory) decoder).newChannelHandler(); - } - addToPipeline("decoder-" + x, channelPipeline, decoder); - } - - if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) { - // Just use EventExecutorGroup from the Netty Component - EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService(); - addToPipeline("handler", channelPipeline, applicationExecutor, new ServerChannelHandler(consumer)); - - } else { - // still use the worker event loop group here - addToPipeline("handler", channelPipeline, new ServerChannelHandler(consumer)); - - } - LOG.trace("Created ChannelPipeline: {}", channelPipeline); - - } - - private void addToPipeline(String name, ChannelPipeline pipeline, ChannelHandler handler) { - pipeline.addLast(name, handler); - } - - private void addToPipeline(String name, ChannelPipeline pipeline, EventExecutorGroup executor, ChannelHandler handler) { - pipeline.addLast(executor, name, handler); - } - - private SSLContext createSSLContext(CamelContext camelContext, NettyServerBootstrapConfiguration configuration) throws Exception { - if (!configuration.isSsl()) { - return null; - } - - SSLContext answer; - - // create ssl context once - if (configuration.getSslContextParameters() != null) { - answer = configuration.getSslContextParameters().createSSLContext(); - } else { - if (configuration.getKeyStoreFile() == null && configuration.getKeyStoreResource() == null) { - LOG.debug("keystorefile is null"); - } - if (configuration.getTrustStoreFile() == null && configuration.getTrustStoreResource() == null) { - LOG.debug("truststorefile is null"); - } - if (configuration.getPassphrase().toCharArray() == null) { - LOG.debug("passphrase is null"); - } - - SSLEngineFactory sslEngineFactory; - if (configuration.getKeyStoreFile() != null || configuration.getTrustStoreFile() != null) { - sslEngineFactory = new SSLEngineFactory(); - answer = sslEngineFactory.createSSLContext(camelContext.getClassResolver(), - configuration.getKeyStoreFormat(), - configuration.getSecurityProvider(), - "file:" + configuration.getKeyStoreFile().getPath(), - "file:" + configuration.getTrustStoreFile().getPath(), - configuration.getPassphrase().toCharArray()); - } else { - sslEngineFactory = new SSLEngineFactory(); - answer = sslEngineFactory.createSSLContext(camelContext.getClassResolver(), - configuration.getKeyStoreFormat(), - configuration.getSecurityProvider(), - configuration.getKeyStoreResource(), - configuration.getTrustStoreResource(), - configuration.getPassphrase().toCharArray()); - } - } - - return answer; - } - - private SslHandler configureServerSSLOnDemand() throws Exception { - if (!consumer.getConfiguration().isSsl()) { - return null; - } - - if (consumer.getConfiguration().getSslHandler() != null) { - return consumer.getConfiguration().getSslHandler(); - } else if (sslContext != null) { - SSLEngine engine = sslContext.createSSLEngine(); - engine.setUseClientMode(false); - engine.setNeedClientAuth(consumer.getConfiguration().isNeedClientAuth()); - return new SslHandler(engine); - } - - return null; - } - - @Override - public ServerPipelineFactory createPipelineFactory(NettyConsumer consumer) { - return new DefaultServerPipelineFactory(consumer); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConfiguration.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConfiguration.java index 2912a46..dbcab81 100644 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConfiguration.java +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConfiguration.java @@ -75,7 +75,7 @@ public class NettyConfiguration extends NettyServerBootstrapConfiguration implem @UriParam private boolean allowDefaultCodec = true; @UriParam - private ClientPipelineFactory clientPipelineFactory; + private ClientInitializerFactory clientPipelineFactory; @UriParam private int maximumPoolSize = 16; @UriParam @@ -167,8 +167,8 @@ public class NettyConfiguration extends NettyServerBootstrapConfiguration implem trustStoreFile = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreFile", File.class, trustStoreFile); keyStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreResource", String.class, keyStoreResource); trustStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreResource", String.class, trustStoreResource); - clientPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "clientPipelineFactory", ClientPipelineFactory.class, clientPipelineFactory); - serverPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "serverPipelineFactory", ServerPipelineFactory.class, serverPipelineFactory); + clientPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "clientPipelineFactory", ClientInitializerFactory.class, clientPipelineFactory); + serverPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "serverPipelineFactory", ServerInitializerFactory.class, serverPipelineFactory); // set custom encoders and decoders first List<ChannelHandler> referencedEncoders = component.resolveAndRemoveReferenceListParameter(parameters, "encoders", ChannelHandler.class, null); @@ -389,11 +389,11 @@ public class NettyConfiguration extends NettyServerBootstrapConfiguration implem this.allowDefaultCodec = allowDefaultCodec; } - public void setClientPipelineFactory(ClientPipelineFactory clientPipelineFactory) { + public void setClientPipelineFactory(ClientInitializerFactory clientPipelineFactory) { this.clientPipelineFactory = clientPipelineFactory; } - public ClientPipelineFactory getClientPipelineFactory() { + public ClientInitializerFactory getClientPipelineFactory() { return clientPipelineFactory; } http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConsumer.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConsumer.java index 2714bcc..82e95ed 100644 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConsumer.java +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConsumer.java @@ -50,12 +50,12 @@ public class NettyConsumer extends DefaultConsumer { if (nettyServerBootstrapFactory == null) { // setup pipeline factory - ServerPipelineFactory pipelineFactory; - ServerPipelineFactory factory = configuration.getServerPipelineFactory(); + ServerInitializerFactory pipelineFactory; + ServerInitializerFactory factory = configuration.getServerPipelineFactory(); if (factory != null) { pipelineFactory = factory.createPipelineFactory(this); } else { - pipelineFactory = new DefaultServerPipelineFactory(this); + pipelineFactory = new DefaultServerInitializerFactory(this); } if (isTcp()) { http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java index 2183f6f..53b777f 100644 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyProducer.java @@ -59,7 +59,7 @@ public class NettyProducer extends DefaultAsyncProducer { private final ChannelGroup allChannels = new DefaultChannelGroup("NettyProducer", ImmediateEventExecutor.INSTANCE); private CamelContext context; private NettyConfiguration configuration; - private ClientPipelineFactory pipelineFactory; + private ClientInitializerFactory pipelineFactory; private CamelLogger noReplyLogger; private EventLoopGroup workerGroup; private ObjectPool<Channel> pool; @@ -125,11 +125,11 @@ public class NettyProducer extends DefaultAsyncProducer { timer = new HashedWheelTimer(); // setup pipeline factory - ClientPipelineFactory factory = configuration.getClientPipelineFactory(); + ClientInitializerFactory factory = configuration.getClientPipelineFactory(); if (factory != null) { pipelineFactory = factory.createPipelineFactory(this); } else { - pipelineFactory = new DefaultClientPipelineFactory(this); + pipelineFactory = new DefaultClientInitializerFactory(this); } if (!configuration.isLazyChannelCreation()) { http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java index bf55073..8380849 100644 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyServerBootstrapConfiguration.java @@ -40,7 +40,7 @@ public class NettyServerBootstrapConfiguration implements Cloneable { protected boolean reuseAddress = true; protected int connectTimeout = 10000; protected int backlog; - protected ServerPipelineFactory serverPipelineFactory; + protected ServerInitializerFactory serverPipelineFactory; protected NettyServerBootstrapFactory nettyServerBootstrapFactory; protected Map<String, Object> options; // SSL options is also part of the server bootstrap as the server listener on port X is either plain or SSL @@ -280,11 +280,11 @@ public class NettyServerBootstrapConfiguration implements Cloneable { this.passphrase = passphrase; } - public ServerPipelineFactory getServerPipelineFactory() { + public ServerInitializerFactory getServerPipelineFactory() { return serverPipelineFactory; } - public void setServerPipelineFactory(ServerPipelineFactory serverPipelineFactory) { + public void setServerPipelineFactory(ServerInitializerFactory serverPipelineFactory) { this.serverPipelineFactory = serverPipelineFactory; } http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerInitializerFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerInitializerFactory.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerInitializerFactory.java new file mode 100644 index 0000000..3fea1b2 --- /dev/null +++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerInitializerFactory.java @@ -0,0 +1,43 @@ +/** + * 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.netty4; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; + + +/** + * Factory to create {@link ChannelPipeline} for servers, eg {@link NettyConsumer}. + * <p/> + * Implementators must support creating a new instance of this factory which is associated + * to the given {@link NettyConsumer} using the {@link #createPipelineFactory(NettyConsumer)} + * method. + * + * @see ChannelPipelineFactory + */ +public abstract class ServerInitializerFactory extends ChannelInitializer<Channel> { + + /** + * Creates a new {@link ServerInitializerFactory} using the given {@link NettyConsumer} + * + * @param consumer the associated consumer + * @return the {@link ServerInitializerFactory} associated to the given consumer. + */ + public abstract ServerInitializerFactory createPipelineFactory(NettyConsumer consumer); + +} http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerPipelineFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerPipelineFactory.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerPipelineFactory.java deleted file mode 100644 index 9d731e0..0000000 --- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/ServerPipelineFactory.java +++ /dev/null @@ -1,43 +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.netty4; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; - - -/** - * Factory to create {@link ChannelPipeline} for servers, eg {@link NettyConsumer}. - * <p/> - * Implementators must support creating a new instance of this factory which is associated - * to the given {@link NettyConsumer} using the {@link #createPipelineFactory(NettyConsumer)} - * method. - * - * @see ChannelPipelineFactory - */ -public abstract class ServerPipelineFactory extends ChannelInitializer<Channel> { - - /** - * Creates a new {@link ServerPipelineFactory} using the given {@link NettyConsumer} - * - * @param consumer the associated consumer - * @return the {@link ServerPipelineFactory} associated to the given consumer. - */ - public abstract ServerPipelineFactory createPipelineFactory(NettyConsumer consumer); - -} http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactoryAsynchTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactoryAsynchTest.java b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactoryAsynchTest.java index df7f49d..d920699 100644 --- a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactoryAsynchTest.java +++ b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactoryAsynchTest.java @@ -70,7 +70,7 @@ public class NettyCustomPipelineFactoryAsynchTest extends BaseNettyTest { assertEquals(true, serverInvoked); } - public class TestClientChannelPipelineFactory extends ClientPipelineFactory { + public class TestClientChannelPipelineFactory extends ClientInitializerFactory { private int maxLineSize = 1024; private NettyProducer producer; @@ -90,12 +90,12 @@ public class NettyCustomPipelineFactoryAsynchTest extends BaseNettyTest { } @Override - public ClientPipelineFactory createPipelineFactory(NettyProducer producer) { + public ClientInitializerFactory createPipelineFactory(NettyProducer producer) { return new TestClientChannelPipelineFactory(producer); } } - public class TestServerChannelPipelineFactory extends ServerPipelineFactory { + public class TestServerChannelPipelineFactory extends ServerInitializerFactory { private int maxLineSize = 1024; private NettyConsumer consumer; @@ -113,7 +113,7 @@ public class NettyCustomPipelineFactoryAsynchTest extends BaseNettyTest { } @Override - public ServerPipelineFactory createPipelineFactory(NettyConsumer consumer) { + public ServerInitializerFactory createPipelineFactory(NettyConsumer consumer) { return new TestServerChannelPipelineFactory(consumer); } } http://git-wip-us.apache.org/repos/asf/camel/blob/00b64c8a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactorySynchTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactorySynchTest.java b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactorySynchTest.java index ebfa262..19be9c2 100644 --- a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactorySynchTest.java +++ b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCustomPipelineFactorySynchTest.java @@ -70,7 +70,7 @@ public class NettyCustomPipelineFactorySynchTest extends BaseNettyTest { assertEquals(true, serverInvoked); } - public class TestClientChannelPipelineFactory extends ClientPipelineFactory { + public class TestClientChannelPipelineFactory extends ClientInitializerFactory { private int maxLineSize = 1024; private NettyProducer producer; @@ -91,12 +91,12 @@ public class NettyCustomPipelineFactorySynchTest extends BaseNettyTest { } @Override - public ClientPipelineFactory createPipelineFactory(NettyProducer producer) { + public ClientInitializerFactory createPipelineFactory(NettyProducer producer) { return new TestClientChannelPipelineFactory(producer); } } - public class TestServerChannelPipelineFactory extends ServerPipelineFactory { + public class TestServerChannelPipelineFactory extends ServerInitializerFactory { private int maxLineSize = 1024; private NettyConsumer consumer; @@ -116,7 +116,7 @@ public class NettyCustomPipelineFactorySynchTest extends BaseNettyTest { } @Override - public ServerPipelineFactory createPipelineFactory(NettyConsumer consumer) { + public ServerInitializerFactory createPipelineFactory(NettyConsumer consumer) { return new TestServerChannelPipelineFactory(consumer); } }
