diff options
author | Joakim Erdfelt | 2014-03-31 21:18:37 +0000 |
---|---|---|
committer | Joakim Erdfelt | 2014-03-31 21:18:37 +0000 |
commit | 28d9df1dbbf1add8adbe18a068bb89b72f497735 (patch) | |
tree | 0002654e95f87d6e67cd727a4e7f21f369ca3164 /jetty-alpn | |
parent | 9bce638719834e43dadad7da81e441d78732f05c (diff) | |
download | org.eclipse.jetty.project-28d9df1dbbf1add8adbe18a068bb89b72f497735.tar.gz org.eclipse.jetty.project-28d9df1dbbf1add8adbe18a068bb89b72f497735.tar.xz org.eclipse.jetty.project-28d9df1dbbf1add8adbe18a068bb89b72f497735.zip |
Refactoring alpn stuff into jetty-alpn-server and jetty-alpn-client
Diffstat (limited to 'jetty-alpn')
8 files changed, 462 insertions, 0 deletions
diff --git a/jetty-alpn/jetty-alpn-client/pom.xml b/jetty-alpn/jetty-alpn-client/pom.xml new file mode 100644 index 0000000000..25eacb7e66 --- /dev/null +++ b/jetty-alpn/jetty-alpn-client/pom.xml @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-project</artifactId> + <version>9.1.4-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>jetty-alpn-client</artifactId> + <name>Jetty :: ALPN Client</name> + <description>Jetty ALPN client services</description> + <url>http://www.eclipse.org/jetty</url> + <properties> + <bundle-symbolic-name>${project.groupId}.alpn.client</bundle-symbolic-name> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <executions> + <execution> + <goals> + <goal>manifest</goal> + </goals> + <configuration> + <instructions> + <Import-Package>org.eclipse.jetty.alpn;resolution:=optional</Import-Package> + </instructions> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> + <!-- always include the sources to be able to prepare the eclipse-jetty-SDK feature + with a snapshot. --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>findbugs-maven-plugin</artifactId> + <configuration> + <onlyAnalyze>org.eclipse.jetty.alpn.*</onlyAnalyze> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-io</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.alpn</groupId> + <artifactId>alpn-api</artifactId> + <version>${alpn.api.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.toolchain</groupId> + <artifactId>jetty-test-helper</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnection.java b/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnection.java new file mode 100644 index 0000000000..1cc08abf90 --- /dev/null +++ b/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnection.java @@ -0,0 +1,87 @@ +// +// ======================================================================== +// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.alpn.client; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executor; +import javax.net.ssl.SSLEngine; + +import org.eclipse.jetty.alpn.ALPN; +import org.eclipse.jetty.io.ClientConnectionFactory; +import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.io.NegotiatingClientConnection; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; + +public class ALPNClientConnection extends NegotiatingClientConnection implements ALPN.ClientProvider +{ + private static final Logger LOG = Log.getLogger(ALPNClientConnection.class); + + private final String protocol; + + public ALPNClientConnection(EndPoint endPoint, Executor executor, ClientConnectionFactory connectionFactory, SSLEngine sslEngine, Map<String, Object> context, String protocol) + { + super(endPoint, executor, sslEngine, connectionFactory, context); + this.protocol = protocol; + ALPN.put(sslEngine, this); + } + + @Override + public boolean supports() + { + return true; + } + + @Override + public void unsupported() + { + ALPN.remove(getSSLEngine()); + completed(); + } + + @Override + public List<String> protocols() + { + return Arrays.asList(protocol); + } + + @Override + public void selected(String protocol) + { + if (this.protocol.equals(protocol)) + { + ALPN.remove(getSSLEngine()); + completed(); + } + else + { + LOG.info("Could not negotiate protocol: server {} - client {}", protocol, this.protocol); + close(); + } + } + + @Override + public void close() + { + ALPN.remove(getSSLEngine()); + super.close(); + } +} diff --git a/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java b/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java new file mode 100644 index 0000000000..881c6a5175 --- /dev/null +++ b/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java @@ -0,0 +1,51 @@ +// +// ======================================================================== +// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.alpn.client; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Executor; + +import javax.net.ssl.SSLEngine; + +import org.eclipse.jetty.io.ClientConnectionFactory; +import org.eclipse.jetty.io.Connection; +import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.io.NegotiatingClientConnectionFactory; +import org.eclipse.jetty.io.ssl.SslClientConnectionFactory; + +public class ALPNClientConnectionFactory extends NegotiatingClientConnectionFactory +{ + private final Executor executor; + private final String protocol; + + public ALPNClientConnectionFactory(Executor executor, ClientConnectionFactory connectionFactory, String protocol) + { + super(connectionFactory); + this.executor = executor; + this.protocol = protocol; + } + + @Override + public Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException + { + return new ALPNClientConnection(endPoint, executor, getClientConnectionFactory(), + (SSLEngine)context.get(SslClientConnectionFactory.SSL_ENGINE_CONTEXT_KEY), context, protocol); + } +} diff --git a/jetty-alpn/jetty-alpn-server/pom.xml b/jetty-alpn/jetty-alpn-server/pom.xml new file mode 100644 index 0000000000..180966e44d --- /dev/null +++ b/jetty-alpn/jetty-alpn-server/pom.xml @@ -0,0 +1,93 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-project</artifactId> + <version>9.1.4-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>jetty-alpn-server</artifactId> + <name>Jetty :: ALPN Server</name> + <description>Jetty ALPN server services</description> + <url>http://www.eclipse.org/jetty</url> + <properties> + <bundle-symbolic-name>${project.groupId}.alpn.server</bundle-symbolic-name> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <executions> + <execution> + <goals> + <goal>manifest</goal> + </goals> + <configuration> + <instructions> + <Import-Package>org.eclipse.jetty.alpn;resolution:=optional</Import-Package> + </instructions> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptorRefs> + <descriptorRef>config</descriptorRef> + </descriptorRefs> + </configuration> + </execution> + </executions> + </plugin> + <!-- always include the sources to be able to prepare the eclipse-jetty-SDK feature + with a snapshot. --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>findbugs-maven-plugin</artifactId> + <configuration> + <onlyAnalyze>org.eclipse.jetty.alpn.*</onlyAnalyze> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.alpn</groupId> + <artifactId>alpn-api</artifactId> + <version>${alpn.api.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.toolchain</groupId> + <artifactId>jetty-test-helper</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod diff --git a/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnection.java b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnection.java new file mode 100644 index 0000000000..509682eb64 --- /dev/null +++ b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnection.java @@ -0,0 +1,77 @@ +// +// ======================================================================== +// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.alpn.server; + +import java.util.Collections; +import java.util.List; +import javax.net.ssl.SSLEngine; + +import org.eclipse.jetty.alpn.ALPN; +import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.NegotiatingServerConnection; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; + +public class ALPNServerConnection extends NegotiatingServerConnection implements ALPN.ServerProvider +{ + private static final Logger LOG = Log.getLogger(ALPNServerConnection.class); + + public ALPNServerConnection(Connector connector, EndPoint endPoint, SSLEngine engine, List<String> protocols, String defaultProtocol) + { + super(connector, endPoint, engine, protocols, defaultProtocol); + ALPN.put(engine, this); + } + + @Override + public void unsupported() + { + select(Collections.<String>emptyList()); + } + + @Override + public String select(List<String> clientProtocols) + { + List<String> serverProtocols = getProtocols(); + String negotiated = null; + for (String clientProtocol : clientProtocols) + { + if (serverProtocols.contains(clientProtocol)) + { + negotiated = clientProtocol; + break; + } + } + if (negotiated == null) + { + negotiated = getDefaultProtocol(); + } + LOG.debug("{} protocol selected {}", this, negotiated); + setProtocol(negotiated); + ALPN.remove(getSSLEngine()); + return negotiated; + } + + @Override + public void close() + { + ALPN.remove(getSSLEngine()); + super.close(); + } +} diff --git a/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java new file mode 100644 index 0000000000..a6e386b7bd --- /dev/null +++ b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java @@ -0,0 +1,61 @@ +// +// ======================================================================== +// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.alpn.server; + +import java.util.List; +import javax.net.ssl.SSLEngine; + +import org.eclipse.jetty.alpn.ALPN; +import org.eclipse.jetty.io.AbstractConnection; +import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.NegotiatingServerConnectionFactory; +import org.eclipse.jetty.util.annotation.Name; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; + +public class ALPNServerConnectionFactory extends NegotiatingServerConnectionFactory +{ + private static final Logger LOG = Log.getLogger(ALPNServerConnectionFactory.class); + + public ALPNServerConnectionFactory(@Name("protocols") String... protocols) + { + super("alpn", protocols); + try + { + ClassLoader alpnClassLoader = ALPN.class.getClassLoader(); + if (alpnClassLoader != null) + { + LOG.warn("ALPN must be in the boot classloader, not in: " + alpnClassLoader); + throw new IllegalStateException("ALPN must be in the boot classloader"); + } + } + catch (Throwable x) + { + LOG.warn("ALPN not available", x); + throw new IllegalStateException("ALPN not available", x); + } + } + + @Override + protected AbstractConnection newServerConnection(Connector connector, EndPoint endPoint, SSLEngine engine, List<String> protocols, String defaultProtocol) + { + return new ALPNServerConnection(connector, endPoint, engine, protocols, defaultProtocol); + } +} diff --git a/jetty-alpn/pom.xml b/jetty-alpn/pom.xml new file mode 100644 index 0000000000..a4f6f5a940 --- /dev/null +++ b/jetty-alpn/pom.xml @@ -0,0 +1,17 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-project</artifactId> + <version>9.1.4-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>jetty-alpn-parent</artifactId> + <packaging>pom</packaging> + <name>Jetty :: ALPN :: Parent</name> + <description>Jetty ALPN services parent</description> + <url>http://www.eclipse.org/jetty</url> + <modules> + <module>jetty-alpn-server</module> + <module>jetty-alpn-client</module> + </modules> +</project> |