Updated Branches: refs/heads/master de9de108b -> 011002fd6
CAMEL-6453 put SSLSession instance into message header after netty endpoint Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/65f92eaa Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/65f92eaa Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/65f92eaa Branch: refs/heads/master Commit: 65f92eaade8c5f1a87bf5193fbb0d0f8cbae401e Parents: de9de10 Author: Willem Jiang <ningji...@apache.org> Authored: Thu Jun 13 15:20:37 2013 +0800 Committer: Willem Jiang <ningji...@apache.org> Committed: Thu Jun 13 15:30:42 2013 +0800 ---------------------------------------------------------------------- .../component/netty/http/NettyHttpEndpoint.java | 1 + .../component/netty/http/NettyHttpSSLTest.java | 16 +++++++++++++++- .../camel/component/netty/NettyConstants.java | 1 + .../apache/camel/component/netty/NettyEndpoint.java | 14 ++++++++++++++ .../apache/camel/component/netty/NettySSLTest.java | 9 ++++++++- 5 files changed, 39 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/65f92eaa/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 a010fb3..2794bcc 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 @@ -84,6 +84,7 @@ public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStra in.setHeader(NettyConstants.NETTY_MESSAGE_EVENT, messageEvent); in.setHeader(NettyConstants.NETTY_REMOTE_ADDRESS, messageEvent.getRemoteAddress()); in.setHeader(NettyConstants.NETTY_LOCAL_ADDRESS, messageEvent.getChannel().getLocalAddress()); + in.setHeader(NettyConstants.NETTY_SSL_SESSION, getSSLSession(ctx)); // honor the character encoding String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class); http://git-wip-us.apache.org/repos/asf/camel/blob/65f92eaa/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java index 62fbf54..28345c4 100644 --- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java +++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java @@ -19,7 +19,12 @@ package org.apache.camel.component.netty.http; import java.net.URL; import java.util.Properties; +import javax.net.ssl.SSLSession; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.netty.NettyConstants; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.After; import org.junit.Test; @@ -81,7 +86,16 @@ public class NettyHttpSSLTest extends BaseNettyTest { public void configure() { from("netty-http:https://localhost:{{port}}?ssl=true&passphrase=changeit&keyStoreResource=jsse/localhost.ks&trustStoreResource=jsse/localhost.ks") .to("mock:input") - .transform().constant("Bye World"); + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class); + if (session != null) { + exchange.getOut().setBody("Bye World"); + } else { + exchange.getOut().setBody("Cannot start conversion without SSLSession"); + } + } + }); } }); context.start(); http://git-wip-us.apache.org/repos/asf/camel/blob/65f92eaa/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConstants.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConstants.java index d84ce03..1ea260c 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConstants.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConstants.java @@ -28,6 +28,7 @@ public final class NettyConstants { public static final String NETTY_MESSAGE_EVENT = "CamelNettyMessageEvent"; public static final String NETTY_REMOTE_ADDRESS = "CamelNettyRemoteAddress"; public static final String NETTY_LOCAL_ADDRESS = "CamelNettyLocalAddress"; + public static final String NETTY_SSL_SESSION = "CamelNettySSLSession"; private NettyConstants() { // Utility class http://git-wip-us.apache.org/repos/asf/camel/blob/65f92eaa/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java ---------------------------------------------------------------------- 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 cf99549..ddcf638 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 @@ -16,6 +16,8 @@ */ package org.apache.camel.component.netty; +import javax.net.ssl.SSLSession; + import org.apache.camel.Consumer; import org.apache.camel.Exchange; import org.apache.camel.Processor; @@ -25,6 +27,7 @@ import org.apache.camel.impl.SynchronousDelegateProducer; 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; public class NettyEndpoint extends DefaultEndpoint { @@ -57,6 +60,8 @@ public class NettyEndpoint extends DefaultEndpoint { exchange.getIn().setHeader(NettyConstants.NETTY_MESSAGE_EVENT, messageEvent); exchange.getIn().setHeader(NettyConstants.NETTY_REMOTE_ADDRESS, messageEvent.getRemoteAddress()); exchange.getIn().setHeader(NettyConstants.NETTY_LOCAL_ADDRESS, messageEvent.getChannel().getLocalAddress()); + // setup the SslSession header + exchange.getIn().setHeader(NettyConstants.NETTY_SSL_SESSION, getSSLSession(ctx)); NettyPayloadHelper.setIn(exchange, messageEvent.getMessage()); return exchange; } @@ -96,5 +101,14 @@ public class NettyEndpoint extends DefaultEndpoint { protected void doStart() throws Exception { ObjectHelper.notNull(timer, "timer"); } + + protected SSLSession getSSLSession(ChannelHandlerContext ctx) { + final SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class); + SSLSession sslSession = null; + if (sslHandler != null) { + sslSession = sslHandler.getEngine().getSession(); + } + return sslSession; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/65f92eaa/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLTest.java b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLTest.java index 7e6785d..5196464 100644 --- a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLTest.java +++ b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLTest.java @@ -19,6 +19,8 @@ package org.apache.camel.component.netty; import java.io.File; +import javax.net.ssl.SSLSession; + import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; @@ -52,7 +54,12 @@ public class NettySSLTest extends BaseNettyTest { from("netty:tcp://localhost:{{port}}?sync=true&ssl=true&passphrase=changeit&keyStoreFile=#ksf&trustStoreFile=#tsf") .process(new Processor() { public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today."); + SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class); + if (session != null) { + exchange.getOut().setBody("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today."); + } else { + exchange.getOut().setBody("Cannot start conversion without SSLSession"); + } } }); }