Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2014-03-31 21:18:37 +0000
committerJoakim Erdfelt2014-03-31 21:18:37 +0000
commit28d9df1dbbf1add8adbe18a068bb89b72f497735 (patch)
tree0002654e95f87d6e67cd727a4e7f21f369ca3164 /jetty-alpn/jetty-alpn-client
parent9bce638719834e43dadad7da81e441d78732f05c (diff)
downloadorg.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/jetty-alpn-client')
-rw-r--r--jetty-alpn/jetty-alpn-client/pom.xml76
-rw-r--r--jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnection.java87
-rw-r--r--jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java51
3 files changed, 214 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);
+ }
+}

Back to the top