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/01/24 17:36:28 UTC
svn commit: r1438065 - in /camel/branches/camel-2.10.x: ./
components/camel-netty/src/main/java/org/apache/camel/component/netty/
Author: davsclaus
Date: Thu Jan 24 16:36:27 2013
New Revision: 1438065
URL: http://svn.apache.org/viewvc?rev=1438065&view=rev
Log:
CAMEL-6008: Only need to init SSLContext once when using SslContextParameters
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientPipelineFactory.java
camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerPipelineFactory.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1438063
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientPipelineFactory.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientPipelineFactory.java?rev=1438065&r1=1438064&r2=1438065&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientPipelineFactory.java (original)
+++ camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientPipelineFactory.java Thu Jan 24 16:36:27 2013
@@ -22,6 +22,7 @@ import javax.net.ssl.SSLEngine;
import org.apache.camel.component.netty.handlers.ClientChannelHandler;
import org.apache.camel.component.netty.ssl.SSLEngineFactory;
+import org.apache.camel.util.ObjectHelper;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.Channels;
@@ -33,18 +34,24 @@ public class DefaultClientPipelineFactor
private static final transient Logger LOG = LoggerFactory.getLogger(DefaultClientPipelineFactory.class);
private final NettyProducer producer;
+ private SSLContext sslContext;
public DefaultClientPipelineFactory(NettyProducer producer) {
this.producer = producer;
+ try {
+ this.sslContext = createSSLContext(producer);
+ } catch (Exception e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
}
public ChannelPipeline getPipeline() throws Exception {
// create a new pipeline
ChannelPipeline channelPipeline = Channels.pipeline();
- SslHandler sslHandler = configureClientSSLOnDemand(producer);
+ SslHandler sslHandler = configureClientSSLOnDemand();
if (sslHandler != null) {
- LOG.debug("Client SSL handler configured and added to the ChannelPipeline");
+ LOG.debug("Client SSL handler configured and added to the ChannelPipeline: {}", sslHandler);
addToPipeline("ssl", channelPipeline, sslHandler);
}
@@ -79,16 +86,29 @@ public class DefaultClientPipelineFactor
pipeline.addLast(name, handler);
}
- private SslHandler configureClientSSLOnDemand(NettyProducer producer) throws Exception {
+ private SSLContext createSSLContext(NettyProducer producer) throws Exception {
+ if (!producer.getConfiguration().isSsl()) {
+ return null;
+ }
+
+ // create ssl context once
+ if (producer.getConfiguration().getSslContextParameters() != null) {
+ SSLContext context = producer.getConfiguration().getSslContextParameters().createSSLContext();
+ return context;
+ }
+
+ return null;
+ }
+
+ private SslHandler configureClientSSLOnDemand() throws Exception {
if (!producer.getConfiguration().isSsl()) {
return null;
}
if (producer.getConfiguration().getSslHandler() != null) {
return producer.getConfiguration().getSslHandler();
- } else if (producer.getConfiguration().getSslContextParameters() != null) {
- SSLContext context = producer.getConfiguration().getSslContextParameters().createSSLContext();
- SSLEngine engine = context.createSSLEngine();
+ } else if (sslContext != null) {
+ SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(true);
return new SslHandler(engine);
} else {
Modified: camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerPipelineFactory.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerPipelineFactory.java?rev=1438065&r1=1438064&r2=1438065&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerPipelineFactory.java (original)
+++ camel/branches/camel-2.10.x/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerPipelineFactory.java Thu Jan 24 16:36:27 2013
@@ -22,6 +22,7 @@ import javax.net.ssl.SSLEngine;
import org.apache.camel.component.netty.handlers.ServerChannelHandler;
import org.apache.camel.component.netty.ssl.SSLEngineFactory;
+import org.apache.camel.util.ObjectHelper;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.Channels;
@@ -34,18 +35,24 @@ public class DefaultServerPipelineFactor
private static final transient Logger LOG = LoggerFactory.getLogger(DefaultServerPipelineFactory.class);
private final NettyConsumer consumer;
+ private SSLContext sslContext;
public DefaultServerPipelineFactory(NettyConsumer consumer) {
this.consumer = consumer;
+ try {
+ this.sslContext = createSSLContext(consumer);
+ } catch (Exception e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
}
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline channelPipeline = Channels.pipeline();
- SslHandler sslHandler = configureServerSSLOnDemand(consumer);
+ SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
- LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline");
+ LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
addToPipeline("ssl", channelPipeline, sslHandler);
}
@@ -90,16 +97,29 @@ public class DefaultServerPipelineFactor
pipeline.addLast(name, handler);
}
- private SslHandler configureServerSSLOnDemand(NettyConsumer consumer) throws Exception {
+ private SSLContext createSSLContext(NettyConsumer consumer) throws Exception {
+ if (!consumer.getConfiguration().isSsl()) {
+ return null;
+ }
+
+ // create ssl context once
+ if (consumer.getConfiguration().getSslContextParameters() != null) {
+ SSLContext context = consumer.getConfiguration().getSslContextParameters().createSSLContext();
+ return context;
+ }
+
+ return null;
+ }
+
+ private SslHandler configureServerSSLOnDemand() throws Exception {
if (!consumer.getConfiguration().isSsl()) {
return null;
}
if (consumer.getConfiguration().getSslHandler() != null) {
return consumer.getConfiguration().getSslHandler();
- } else if (consumer.getConfiguration().getSslContextParameters() != null) {
- SSLContext context = consumer.getConfiguration().getSslContextParameters().createSSLContext();
- SSLEngine engine = context.createSSLEngine();
+ } else if (sslContext != null) {
+ SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
engine.setNeedClientAuth(consumer.getConfiguration().isNeedClientAuth());
return new SslHandler(engine);