From c2095d71700a421e160b7aab6dc7ff4ab9eac5e1 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 27 Aug 2012 17:07:00 +0200 Subject: [PATCH] Jetty9 - Moved wiring of SslConnection out of HttpServerConnectionFactory. The wiring of SslConnection in HttpServerConnectionFactory was not the right place because a ConnectionFactory should just create the Connection instances, not also wiring them up. It is responsibility of the connector to wire the SslConnection in. Moving the wiring outside HttpServerConnectionFactory fixed also a few SPDY tests, where the wiring was already done outside (and therefore was done twice). --- .../server/HttpServerConnectionFactory.java | 19 +--------- .../eclipse/jetty/server/LocalConnector.java | 35 +++++++++++++++---- .../jetty/server/SelectChannelConnector.java | 24 +++++++++++-- 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnectionFactory.java index 5f3cf042dfe..09784704d9a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpServerConnectionFactory.java @@ -20,12 +20,9 @@ package org.eclipse.jetty.server; import java.nio.channels.SocketChannel; -import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.io.ssl.SslConnection; -import org.eclipse.jetty.util.ssl.SslContextFactory; public class HttpServerConnectionFactory implements ConnectionFactory { @@ -55,20 +52,6 @@ public class HttpServerConnectionFactory implements ConnectionFactory @Override public Connection newConnection(SocketChannel channel, EndPoint endPoint, Object attachment) { - SslContextFactory sslContextFactory = connector.getSslContextFactory(); - if (sslContextFactory != null) - { - SSLEngine engine = sslContextFactory.newSSLEngine(endPoint.getRemoteAddress()); - engine.setUseClientMode(false); - SslConnection sslConnection = new SslConnection(connector.getByteBufferPool(), connector.getExecutor(), endPoint, engine); - Connection httpConnection = new HttpConnection(getHttpConfiguration(), connector, sslConnection.getDecryptedEndPoint()); - sslConnection.getDecryptedEndPoint().setConnection(httpConnection); - httpConnection.onOpen(); - return sslConnection; - } - else - { - return new HttpConnection(getHttpConfiguration(), getConnector(), endPoint); - } + return new HttpConnection(getHttpConfiguration(), getConnector(), endPoint); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java index be58581a78d..c265a7ea48d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java @@ -26,10 +26,13 @@ import java.util.concurrent.Executor; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.ByteArrayEndPoint; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.Connection; +import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.ssl.SslContextFactory; @@ -153,12 +156,32 @@ public class LocalConnector extends AbstractConnector protected void accept(int acceptorID) throws IOException, InterruptedException { LOG.debug("accepting {}", acceptorID); - LocalEndPoint endp = _connects.take(); - Connection connection = getDefaultConnectionFactory().newConnection(null, endp, null); - endp.setConnection(connection); - endp.onOpen(); - connectionOpened(connection); - connection.onOpen(); + LocalEndPoint endPoint = _connects.take(); + endPoint.onOpen(); + + SslContextFactory sslContextFactory = getSslContextFactory(); + if (sslContextFactory != null) + { + SSLEngine engine = sslContextFactory.newSSLEngine(endPoint.getRemoteAddress()); + engine.setUseClientMode(false); + + SslConnection sslConnection = new SslConnection(getByteBufferPool(), getExecutor(), endPoint, engine); + endPoint.setConnection(sslConnection); + connectionOpened(sslConnection); + sslConnection.onOpen(); + + EndPoint appEndPoint = sslConnection.getDecryptedEndPoint(); + Connection connection = getDefaultConnectionFactory().newConnection(null, appEndPoint, null); + appEndPoint.setConnection(connection); + connection.onOpen(); + } + else + { + Connection connection = getDefaultConnectionFactory().newConnection(null, endPoint, null); + endPoint.setConnection(connection); + connectionOpened(connection); + connection.onOpen(); + } } public class LocalEndPoint extends ByteArrayEndPoint diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java index 2a0ccf53e95..cf6eb5971b9 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java @@ -30,6 +30,7 @@ import java.nio.channels.SocketChannel; import java.util.concurrent.Executor; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; +import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.Connection; @@ -37,6 +38,7 @@ import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectorManager; import org.eclipse.jetty.io.SelectorManager.ManagedSelector; +import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.Name; import org.eclipse.jetty.util.ssl.SslContextFactory; @@ -161,7 +163,7 @@ public class SelectChannelConnector extends AbstractNetworkConnector _acceptChannel = serverChannel; } } - + @Override public Future shutdown(C c) { @@ -255,7 +257,25 @@ public class SelectChannelConnector extends AbstractNetworkConnector protected Connection newConnection(SocketChannel channel, EndPoint endPoint, Object attachment) { - return getDefaultConnectionFactory().newConnection(channel, endPoint, attachment); + SslContextFactory sslContextFactory = getSslContextFactory(); + if (sslContextFactory != null) + { + SSLEngine engine = sslContextFactory.newSSLEngine(endPoint.getRemoteAddress()); + engine.setUseClientMode(false); + + SslConnection sslConnection = new SslConnection(getByteBufferPool(), getExecutor(), endPoint, engine); + + EndPoint appEndPoint = sslConnection.getDecryptedEndPoint(); + Connection connection = getDefaultConnectionFactory().newConnection(channel, appEndPoint, attachment); + appEndPoint.setConnection(connection); + connection.onOpen(); + + return sslConnection; + } + else + { + return getDefaultConnectionFactory().newConnection(channel, endPoint, attachment); + } } /**