Repository: qpid-jms Updated Branches: refs/heads/master a3aa7d038 -> 7596c7b7f
QPIDJMS-191: initialise the SslHandler before the connect attempt begins, ensures certain config issues fail fast without attempting a socket connection Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/0155e418 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/0155e418 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/0155e418 Branch: refs/heads/master Commit: 0155e418ac60fe8d5c084cb143dcbc9e68379012 Parents: a3aa7d0 Author: Robert Gemmell <[email protected]> Authored: Fri Jul 15 18:07:05 2016 +0100 Committer: Robert Gemmell <[email protected]> Committed: Fri Jul 15 18:07:05 2016 +0100 ---------------------------------------------------------------------- .../jms/transports/netty/NettyTcpTransport.java | 28 +++++++++++--------- .../jms/integration/SslIntegrationTest.java | 3 +++ 2 files changed, 18 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0155e418/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java index 5908508..d93fdb5 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java @@ -117,16 +117,27 @@ public class NettyTcpTransport implements Transport { throw new IllegalStateException("A transport listener must be set before connection attempts."); } + final SslHandler sslHandler; + if(isSecure()) { + try { + sslHandler = TransportSupport.createSslHandler(getRemoteLocation(), getSslOptions()); + } catch (Exception ex) { + // TODO: can we stop it throwing Exception? + throw IOExceptionSupport.create(ex); + } + } else { + sslHandler = null; + } + group = new NioEventLoopGroup(1); bootstrap = new Bootstrap(); bootstrap.group(group); bootstrap.channel(NioSocketChannel.class); bootstrap.handler(new ChannelInitializer<Channel>() { - @Override public void initChannel(Channel connectedChannel) throws Exception { - configureChannel(connectedChannel); + configureChannel(connectedChannel, sslHandler); } }); @@ -324,7 +335,7 @@ public class NettyTcpTransport implements Transport { * Called when the transport connection failed and an error should be returned. */ private void connectionFailed(Channel failedChannel, IOException cause) { - failureCause = IOExceptionSupport.create(cause); + failureCause = cause; channel = failedChannel; connected.set(false); connectLatch.countDown(); @@ -355,19 +366,10 @@ public class NettyTcpTransport implements Transport { } } - private void configureChannel(final Channel channel) throws Exception { + private void configureChannel(final Channel channel, final SslHandler sslHandler) throws Exception { channel.pipeline().addLast(new NettyDefaultHandler()); if (isSecure()) { - - SslHandler sslHandler = null; - try { - sslHandler = TransportSupport.createSslHandler(getRemoteLocation(), getSslOptions()); - } catch (Exception ex) { - handleException(channel, ex); - return; - } - sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(Future<Channel> future) throws Exception { http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0155e418/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SslIntegrationTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SslIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SslIntegrationTest.java index 19464e9..cfedb21 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SslIntegrationTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SslIntegrationTest.java @@ -21,6 +21,7 @@ package org.apache.qpid.jms.integration; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -187,6 +188,8 @@ public class SslIntegrationTest extends QpidJmsTestCase { } catch (JMSException jmse) { // Expected } + + assertNull("Attempt should have failed locally, peer should not have accepted any TCP connection", testPeer.getClientSocket()); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
