Introduced default AsyncConnectionFactory in SPDYServerConnector, to fallback
to a default protocol in case of A) non-SSL connection, and B) no NPN.
This commit is contained in:
parent
94d5bccbd3
commit
2640e80101
|
@ -12,6 +12,19 @@
|
||||||
<artifactId>spdy-jetty-http</artifactId>
|
<artifactId>spdy-jetty-http</artifactId>
|
||||||
<name>SPDY :: Jetty HTTP Layer</name>
|
<name>SPDY :: Jetty HTTP Layer</name>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<argLine>
|
||||||
|
-Xbootclasspath/p:${settings.localRepository}/org/eclipse/jetty/npn-boot/${npn.version}/npn-boot-${npn.version}.jar
|
||||||
|
</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
|
|
@ -16,15 +16,34 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.spdy.http;
|
package org.eclipse.jetty.spdy.http;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.spdy.AsyncConnectionFactory;
|
||||||
import org.eclipse.jetty.spdy.SPDYServerConnector;
|
import org.eclipse.jetty.spdy.SPDYServerConnector;
|
||||||
import org.eclipse.jetty.spdy.api.SPDY;
|
import org.eclipse.jetty.spdy.api.SPDY;
|
||||||
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
|
|
||||||
public class HTTPSPDYServerConnector extends SPDYServerConnector
|
public class HTTPSPDYServerConnector extends SPDYServerConnector
|
||||||
{
|
{
|
||||||
|
private final AsyncConnectionFactory defaultConnectionFactory;
|
||||||
|
|
||||||
public HTTPSPDYServerConnector()
|
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));
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ import javax.net.ssl.SSLSocket;
|
||||||
|
|
||||||
import org.eclipse.jetty.npn.NextProtoNego;
|
import org.eclipse.jetty.npn.NextProtoNego;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.spdy.AsyncConnectionFactory;
|
||||||
import org.eclipse.jetty.spdy.SPDYServerConnector;
|
import org.eclipse.jetty.spdy.SPDYServerConnector;
|
||||||
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
|
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -54,12 +54,13 @@ public class ProtocolNegotiationTest
|
||||||
protected Server server;
|
protected Server server;
|
||||||
protected SPDYServerConnector connector;
|
protected SPDYServerConnector connector;
|
||||||
|
|
||||||
protected InetSocketAddress startServer(ServerSessionFrameListener listener) throws Exception
|
protected InetSocketAddress startServer(SPDYServerConnector connector) throws Exception
|
||||||
{
|
{
|
||||||
server = new Server();
|
server = new Server();
|
||||||
SslContextFactory sslContextFactory = newSslContextFactory();
|
if (connector == null)
|
||||||
connector = new SPDYServerConnector(listener, sslContextFactory);
|
connector = new SPDYServerConnector(null, newSslContextFactory());
|
||||||
connector.setPort(0);
|
connector.setPort(0);
|
||||||
|
this.connector = connector;
|
||||||
server.addConnector(connector);
|
server.addConnector(connector);
|
||||||
server.start();
|
server.start();
|
||||||
return new InetSocketAddress("localhost", connector.getLocalPort());
|
return new InetSocketAddress("localhost", connector.getLocalPort());
|
||||||
|
@ -197,9 +198,15 @@ public class ProtocolNegotiationTest
|
||||||
@Test
|
@Test
|
||||||
public void testServerAdvertisingSPDYAndHTTPSpeaksDefaultProtocolWhenNPNMissing() throws Exception
|
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.putAsyncConnectionFactory("http/1.1", new ServerHTTPAsyncConnectionFactory(connector));
|
||||||
connector.setDefaultProtocol("http/1.1");
|
|
||||||
|
|
||||||
SslContextFactory sslContextFactory = newSslContextFactory();
|
SslContextFactory sslContextFactory = newSslContextFactory();
|
||||||
sslContextFactory.start();
|
sslContextFactory.start();
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.11</version>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<argLine>
|
<argLine>
|
||||||
-Xbootclasspath/p:${settings.localRepository}/org/eclipse/jetty/npn-boot/${npn.version}/npn-boot-${npn.version}.jar
|
-Xbootclasspath/p:${settings.localRepository}/org/eclipse/jetty/npn-boot/${npn.version}/npn-boot-${npn.version}.jar
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class SPDYServerConnector extends SelectChannelConnector
|
||||||
// Order is important on server side, so we use a LinkedHashMap
|
// Order is important on server side, so we use a LinkedHashMap
|
||||||
private final Map<String, AsyncConnectionFactory> factories = new LinkedHashMap<>();
|
private final Map<String, AsyncConnectionFactory> factories = new LinkedHashMap<>();
|
||||||
private final SslContextFactory sslContextFactory;
|
private final SslContextFactory sslContextFactory;
|
||||||
private volatile String defaultProtocol = "spdy/2";
|
private final AsyncConnectionFactory defaultConnectionFactory;
|
||||||
|
|
||||||
public SPDYServerConnector(ServerSessionFrameListener listener)
|
public SPDYServerConnector(ServerSessionFrameListener listener)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,8 @@ public class SPDYServerConnector extends SelectChannelConnector
|
||||||
this.sslContextFactory = sslContextFactory;
|
this.sslContextFactory = sslContextFactory;
|
||||||
if (sslContextFactory != null)
|
if (sslContextFactory != null)
|
||||||
addBean(sslContextFactory);
|
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)
|
public AsyncConnectionFactory getAsyncConnectionFactory(String protocol)
|
||||||
|
@ -93,14 +94,9 @@ public class SPDYServerConnector extends SelectChannelConnector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultProtocol()
|
protected AsyncConnectionFactory getDefaultAsyncConnectionFactory()
|
||||||
{
|
{
|
||||||
return defaultProtocol;
|
return defaultConnectionFactory;
|
||||||
}
|
|
||||||
|
|
||||||
public void setDefaultProtocol(String defaultProtocol)
|
|
||||||
{
|
|
||||||
this.defaultProtocol = defaultProtocol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,7 +114,9 @@ public class SPDYServerConnector extends SelectChannelConnector
|
||||||
@Override
|
@Override
|
||||||
public void unsupported()
|
public void unsupported()
|
||||||
{
|
{
|
||||||
protocolSelected(getDefaultProtocol());
|
AsyncConnectionFactory connectionFactory = getDefaultAsyncConnectionFactory();
|
||||||
|
AsyncConnection connection = connectionFactory.newAsyncConnection(channel, sslEndPoint, null);
|
||||||
|
sslEndPoint.setConnection(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,7 +143,7 @@ public class SPDYServerConnector extends SelectChannelConnector
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AsyncConnectionFactory connectionFactory = getAsyncConnectionFactory("spdy/2");
|
AsyncConnectionFactory connectionFactory = getDefaultAsyncConnectionFactory();
|
||||||
AsyncConnection connection = connectionFactory.newAsyncConnection(channel, endPoint, null);
|
AsyncConnection connection = connectionFactory.newAsyncConnection(channel, endPoint, null);
|
||||||
endPoint.setConnection(connection);
|
endPoint.setConnection(connection);
|
||||||
return connection;
|
return connection;
|
||||||
|
|
Loading…
Reference in New Issue