Skip to content

Commit

Permalink
Add ALPN support; Configure maven to use ALPN on OpenJDK 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Apr 28, 2014
1 parent 743ae0c commit a5b7c3b
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 151 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ before_install:

jdk:
- oraclejdk7
- oraclejdk8
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Testing

### On the Desktop

Run OkHttp tests on the desktop with Maven. Running SPDY tests on the desktop uses
[Jetty-NPN][3] which requires OpenJDK 7.
Run OkHttp tests on the desktop with Maven. Running HTTP/2 and SPDY tests on the desktop uses
[Jetty-NPN][3] when running OpenJDK 7 or [Jetty-ALPN][4] when OpenJDK 8.

```
mvn clean test
Expand All @@ -46,7 +46,7 @@ mvn clean test
OkHttp's test suite creates an in-process HTTPS server. Prior to Android 2.3, SSL server sockets
were broken, and so HTTPS tests will time out when run on such devices.

Test on a USB-attached Android using [Vogar][4]. Unfortunately `dx` requires that you build with
Test on a USB-attached Android using [Vogar][5]. Unfortunately `dx` requires that you build with
Java 6, otherwise the test class will be silently omitted from the `.dex` file.

```
Expand All @@ -69,7 +69,7 @@ MockWebServer coupling with OkHttp is essential for proper testing of SPDY and H

### Download

Download [the latest JAR][5] or grab via Maven:
Download [the latest JAR][6] or grab via Maven:

```xml
<dependency>
Expand Down Expand Up @@ -102,5 +102,6 @@ License
[1]: http://square.github.io/okhttp
[2]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=okhttp&v=LATEST
[3]: https://github.com/jetty-project/jetty-npn
[4]: https://code.google.com/p/vogar/
[5]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=mockwebserver&v=LATEST
[4]: https://github.com/jetty-project/jetty-alpn
[5]: https://code.google.com/p/vogar/
[6]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=mockwebserver&v=LATEST
91 changes: 64 additions & 27 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down Expand Up @@ -71,28 +66,70 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xms512m</argument>
<argument>-Xmx512m</argument>
<commandlineArgs>-Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/npn/npn-boot/${npn.version}/npn-boot-${npn.version}.jar</commandlineArgs>
<argument>-classpath</argument>
<classpath/>
<argument>com.squareup.okhttp.benchmarks.Benchmark</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xms512m</argument>
<argument>-Xmx512m</argument>
<commandlineArgs>-Xbootclasspath/p:${bootclasspath}</commandlineArgs>
<argument>-classpath</argument>
<classpath/>
<argument>com.squareup.okhttp.benchmarks.Benchmark</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>npn-when-jdk7</id>
<activation>
<jdk>1.7</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>alpn-when-jdk8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Fails on caliper's ASM on OpenJDK 8. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<executions>
<execution>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
5 changes: 0 additions & 5 deletions mockwebserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public final class MockWebServer {

private int port = -1;
private boolean protocolNegotiationEnabled = true;
private List<Protocol> npnProtocols
private List<Protocol> protocols
= Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3, Protocol.HTTP_1_1);

public int getPort() {
Expand Down Expand Up @@ -209,7 +209,7 @@ public void setProtocols(List<Protocol> protocols) {
if (protocols.contains(null)) {
throw new IllegalArgumentException("protocols must not contain null");
}
this.npnProtocols = protocols;
this.protocols = protocols;
}

/**
Expand Down Expand Up @@ -351,7 +351,7 @@ public void processConnection() throws Exception {
openClientSockets.put(socket, true);

if (protocolNegotiationEnabled) {
Platform.get().setProtocols(sslSocket, npnProtocols);
Platform.get().setProtocols(sslSocket, protocols);
}

sslSocket.startHandshake();
Expand Down
5 changes: 0 additions & 5 deletions okhttp-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
<artifactId>okhttp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
44 changes: 22 additions & 22 deletions okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public final class CallTest {
}

@Test public void get_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
get();
}

@Test public void get_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
get();
}

Expand All @@ -123,12 +123,12 @@ public final class CallTest {
}

@Test public void head_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
head();
}

@Test public void head_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
head();
}

Expand All @@ -153,12 +153,12 @@ public final class CallTest {
}

@Test public void post_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
post();
}

@Test public void post_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
post();
}

Expand All @@ -183,12 +183,12 @@ public final class CallTest {
}

@Test public void postZeroLength_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
postZeroLength();
}

@Test public void postZerolength_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
postZeroLength();
}

Expand All @@ -213,12 +213,12 @@ public final class CallTest {
}

@Test public void delete_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
delete();
}

@Test public void delete_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
delete();
}

Expand All @@ -243,12 +243,12 @@ public final class CallTest {
}

@Test public void put_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
put();
}

@Test public void put_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
put();
}

Expand All @@ -273,12 +273,12 @@ public final class CallTest {
}

@Test public void patch_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
patch();
}

@Test public void patch_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
patch();
}

Expand Down Expand Up @@ -914,12 +914,12 @@ public final class CallTest {
}

@Test public void canceledBeforeIOSignalsOnFailure_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
canceledBeforeIOSignalsOnFailure();
}

@Test public void canceledBeforeIOSignalsOnFailure_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
canceledBeforeIOSignalsOnFailure();
}

Expand All @@ -940,12 +940,12 @@ public final class CallTest {
}

@Test public void canceledBeforeResponseReadSignalsOnFailure_HTTP_2() throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
canceledBeforeResponseReadSignalsOnFailure();
}

@Test public void canceledBeforeResponseReadSignalsOnFailure_SPDY_3() throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
canceledBeforeResponseReadSignalsOnFailure();
}

Expand Down Expand Up @@ -989,13 +989,13 @@ public final class CallTest {

@Test public void canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce_HTTP_2()
throws Exception {
enableNpn(Protocol.HTTP_2);
enableProtocol(Protocol.HTTP_2);
canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce();
}

@Test public void canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce_SPDY_3()
throws Exception {
enableNpn(Protocol.SPDY_3);
enableProtocol(Protocol.SPDY_3);
canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce();
}

Expand All @@ -1006,9 +1006,9 @@ private RecordedResponse executeSynchronously(Request request) throws IOExceptio

/**
* Tests that use this will fail unless boot classpath is set. Ex. {@code
* -Xbootclasspath/p:/tmp/npn-boot-1.1.7.v20140316.jar}
* -Xbootclasspath/p:/tmp/alpn-boot-8.0.0.v20140317}
*/
private void enableNpn(Protocol protocol) {
private void enableProtocol(Protocol protocol) {
client.setSslSocketFactory(sslContext.getSocketFactory());
client.setHostnameVerifier(new RecordingHostnameVerifier());
client.setProtocols(Arrays.asList(protocol, Protocol.HTTP_1_1));
Expand Down
Loading

0 comments on commit a5b7c3b

Please sign in to comment.