diff --git a/spdy-jetty-http/pom.xml b/spdy-jetty-http/pom.xml index 7c14c744b5a..5b9ec2adb6d 100644 --- a/spdy-jetty-http/pom.xml +++ b/spdy-jetty-http/pom.xml @@ -12,6 +12,19 @@ spdy-jetty-http SPDY :: Jetty HTTP Layer + + + + maven-surefire-plugin + + + -Xbootclasspath/p:${settings.localRepository}/org/eclipse/jetty/npn-boot/${npn.version}/npn-boot-${npn.version}.jar + + + + + + org.eclipse.jetty diff --git a/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/HTTPSPDYServerConnector.java b/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/HTTPSPDYServerConnector.java index 593ab637172..ec723d9c69f 100644 --- a/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/HTTPSPDYServerConnector.java +++ b/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/HTTPSPDYServerConnector.java @@ -16,15 +16,34 @@ package org.eclipse.jetty.spdy.http; +import org.eclipse.jetty.spdy.AsyncConnectionFactory; import org.eclipse.jetty.spdy.SPDYServerConnector; import org.eclipse.jetty.spdy.api.SPDY; +import org.eclipse.jetty.util.ssl.SslContextFactory; public class HTTPSPDYServerConnector extends SPDYServerConnector { + private final AsyncConnectionFactory defaultConnectionFactory; + public HTTPSPDYServerConnector() { - super(null); + this(null); + } + + public HTTPSPDYServerConnector(SslContextFactory sslContextFactory) + { + super(null, sslContextFactory); + // Override the "spdy/2" protocol by handling HTTP over SPDY putAsyncConnectionFactory("spdy/2", new ServerHTTPSPDYAsyncConnectionFactory(SPDY.V2, this)); - setDefaultProtocol("http/1.1"); + // Add the "http/1.1" protocol for browsers that do not support NPN + putAsyncConnectionFactory("http/1.1", new ServerHTTPAsyncConnectionFactory(this)); + // Override the default connection factory for non-SSL connections + defaultConnectionFactory = new ServerHTTPAsyncConnectionFactory(this); + } + + @Override + protected AsyncConnectionFactory getDefaultAsyncConnectionFactory() + { + return defaultConnectionFactory; } } diff --git a/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ProtocolNegotiationTest.java b/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ProtocolNegotiationTest.java index 8697469564d..e9cca9d33b5 100644 --- a/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ProtocolNegotiationTest.java +++ b/spdy-jetty-http/src/test/java/org/eclipse/jetty/spdy/http/ProtocolNegotiationTest.java @@ -27,8 +27,8 @@ import javax.net.ssl.SSLSocket; import org.eclipse.jetty.npn.NextProtoNego; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.spdy.AsyncConnectionFactory; import org.eclipse.jetty.spdy.SPDYServerConnector; -import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Rule; @@ -54,12 +54,13 @@ public class ProtocolNegotiationTest protected Server server; protected SPDYServerConnector connector; - protected InetSocketAddress startServer(ServerSessionFrameListener listener) throws Exception + protected InetSocketAddress startServer(SPDYServerConnector connector) throws Exception { server = new Server(); - SslContextFactory sslContextFactory = newSslContextFactory(); - connector = new SPDYServerConnector(listener, sslContextFactory); + if (connector == null) + connector = new SPDYServerConnector(null, newSslContextFactory()); connector.setPort(0); + this.connector = connector; server.addConnector(connector); server.start(); return new InetSocketAddress("localhost", connector.getLocalPort()); @@ -197,9 +198,15 @@ public class ProtocolNegotiationTest @Test public void testServerAdvertisingSPDYAndHTTPSpeaksDefaultProtocolWhenNPNMissing() throws Exception { - InetSocketAddress address = startServer(null); + InetSocketAddress address = startServer(new SPDYServerConnector(null, newSslContextFactory()) + { + @Override + protected AsyncConnectionFactory getDefaultAsyncConnectionFactory() + { + return new ServerHTTPAsyncConnectionFactory(connector); + } + }); connector.putAsyncConnectionFactory("http/1.1", new ServerHTTPAsyncConnectionFactory(connector)); - connector.setDefaultProtocol("http/1.1"); SslContextFactory sslContextFactory = newSslContextFactory(); sslContextFactory.start(); diff --git a/spdy-jetty/pom.xml b/spdy-jetty/pom.xml index 360ce965241..a9df1a97f18 100644 --- a/spdy-jetty/pom.xml +++ b/spdy-jetty/pom.xml @@ -16,7 +16,6 @@ maven-surefire-plugin - 2.11 -Xbootclasspath/p:${settings.localRepository}/org/eclipse/jetty/npn-boot/${npn.version}/npn-boot-${npn.version}.jar diff --git a/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java b/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java index 39ea7f90d8c..c4e73c3e579 100644 --- a/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java +++ b/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java @@ -38,7 +38,7 @@ public class SPDYServerConnector extends SelectChannelConnector // Order is important on server side, so we use a LinkedHashMap private final Map factories = new LinkedHashMap<>(); private final SslContextFactory sslContextFactory; - private volatile String defaultProtocol = "spdy/2"; + private final AsyncConnectionFactory defaultConnectionFactory; public SPDYServerConnector(ServerSessionFrameListener listener) { @@ -50,7 +50,8 @@ public class SPDYServerConnector extends SelectChannelConnector this.sslContextFactory = sslContextFactory; if (sslContextFactory != null) addBean(sslContextFactory); - putAsyncConnectionFactory("spdy/2", new ServerSPDYAsyncConnectionFactory(SPDY.V2, listener)); + defaultConnectionFactory = new ServerSPDYAsyncConnectionFactory(SPDY.V2, listener); + putAsyncConnectionFactory("spdy/2", defaultConnectionFactory); } public AsyncConnectionFactory getAsyncConnectionFactory(String protocol) @@ -93,14 +94,9 @@ public class SPDYServerConnector extends SelectChannelConnector } } - public String getDefaultProtocol() + protected AsyncConnectionFactory getDefaultAsyncConnectionFactory() { - return defaultProtocol; - } - - public void setDefaultProtocol(String defaultProtocol) - { - this.defaultProtocol = defaultProtocol; + return defaultConnectionFactory; } @Override @@ -118,7 +114,9 @@ public class SPDYServerConnector extends SelectChannelConnector @Override public void unsupported() { - protocolSelected(getDefaultProtocol()); + AsyncConnectionFactory connectionFactory = getDefaultAsyncConnectionFactory(); + AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, null); + sslEndPoint.setConnection(connection); } @Override @@ -145,7 +143,7 @@ public class SPDYServerConnector extends SelectChannelConnector } else { - AsyncConnectionFactory connectionFactory = getAsyncConnectionFactory("spdy/2"); + AsyncConnectionFactory connectionFactory = getDefaultAsyncConnectionFactory(); AsyncConnection connection = connectionFactory.newAsyncConnection(channel, endPoint, null); endPoint.setConnection(connection); return connection;