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).
This commit is contained in:
parent
1a2266b1b8
commit
c2095d7170
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <C> Future<C> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue