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:
Simone Bordet 2012-08-27 17:07:00 +02:00
parent 1a2266b1b8
commit c2095d7170
3 changed files with 52 additions and 26 deletions

View File

@ -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
{
@ -54,21 +51,7 @@ 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);
}
}
}

View File

@ -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,13 +156,33 @@ 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();
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
{

View File

@ -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;
@ -254,9 +256,27 @@ public class SelectChannelConnector extends AbstractNetworkConnector
}
protected Connection newConnection(SocketChannel channel, EndPoint endPoint, Object 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);
}
}
/**
* @return the linger time