Skip to content

Commit c9fcdc9

Browse files
authored
Merge pull request javaee-samples#17 from MattGill98/http2-test-failure
HTTP/2 Test Failure
2 parents c1bb269 + a9e4be7 commit c9fcdc9

2 files changed

Lines changed: 92 additions & 32 deletions

File tree

servlet/http2/pom.xml

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<version>${jetty-version}</version>
2626
<scope>test</scope>
2727
</dependency>
28+
<dependency>
29+
<groupId>org.eclipse.jetty.http2</groupId>
30+
<artifactId>http2-http-client-transport</artifactId>
31+
<version>${jetty-version}</version>
32+
<scope>test</scope>
33+
</dependency>
2834
<dependency>
2935
<groupId>org.eclipse.jetty.http2</groupId>
3036
<artifactId>http2-common</artifactId>
@@ -432,7 +438,78 @@
432438
<alpn.version>8.1.13.v20181017</alpn.version>
433439
</properties>
434440
</profile>
435-
441+
<profile>
442+
<id>alpn-when-jdk8_211</id>
443+
<activation>
444+
<jdk>1.8.0_211</jdk>
445+
</activation>
446+
<properties>
447+
<alpn.version>8.1.13.v20181017</alpn.version>
448+
</properties>
449+
</profile>
450+
<profile>
451+
<id>alpn-when-jdk8_212</id>
452+
<activation>
453+
<jdk>1.8.0_212</jdk>
454+
</activation>
455+
<properties>
456+
<alpn.version>8.1.13.v20181017</alpn.version>
457+
</properties>
458+
</profile>
459+
<profile>
460+
<id>alpn-when-jdk8_221</id>
461+
<activation>
462+
<jdk>1.8.0_221</jdk>
463+
</activation>
464+
<properties>
465+
<alpn.version>8.1.13.v20181017</alpn.version>
466+
</properties>
467+
</profile>
468+
<profile>
469+
<id>alpn-when-jdk8_222</id>
470+
<activation>
471+
<jdk>1.8.0_222</jdk>
472+
</activation>
473+
<properties>
474+
<alpn.version>8.1.13.v20181017</alpn.version>
475+
</properties>
476+
</profile>
477+
<profile>
478+
<id>alpn-when-jdk8_231</id>
479+
<activation>
480+
<jdk>1.8.0_231</jdk>
481+
</activation>
482+
<properties>
483+
<alpn.version>8.1.13.v20181017</alpn.version>
484+
</properties>
485+
</profile>
486+
<profile>
487+
<id>alpn-when-jdk8_232</id>
488+
<activation>
489+
<jdk>1.8.0_232</jdk>
490+
</activation>
491+
<properties>
492+
<alpn.version>8.1.13.v20181017</alpn.version>
493+
</properties>
494+
</profile>
495+
<profile>
496+
<id>alpn-when-jdk8_241</id>
497+
<activation>
498+
<jdk>1.8.0_241</jdk>
499+
</activation>
500+
<properties>
501+
<alpn.version>8.1.13.v20181017</alpn.version>
502+
</properties>
503+
</profile>
504+
<profile>
505+
<id>alpn-when-jdk8_242</id>
506+
<activation>
507+
<jdk>1.8.0_242</jdk>
508+
</activation>
509+
<properties>
510+
<alpn.version>8.1.13.v20181017</alpn.version>
511+
</properties>
512+
</profile>
436513
</profiles>
437514

438515
</project>
Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package org.javaee8.servlet.http2;
22

33
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
4-
import static org.junit.Assert.assertNotNull;
5-
import static org.junit.Assert.assertThat;
4+
import static org.junit.Assert.assertEquals;
65

76
import java.io.File;
87
import java.net.URI;
98
import java.net.URL;
9+
import java.util.concurrent.ExecutionException;
10+
import java.util.concurrent.TimeoutException;
1011

11-
import javax.ws.rs.client.Client;
12-
import javax.ws.rs.client.ClientBuilder;
13-
import javax.ws.rs.core.Response;
14-
15-
import org.glassfish.jersey.client.ClientConfig;
16-
import org.hamcrest.Matchers;
12+
import org.eclipse.jetty.client.HttpClient;
13+
import org.eclipse.jetty.http.HttpVersion;
1714
import org.jboss.arquillian.container.test.api.Deployment;
18-
import org.jboss.arquillian.container.test.api.RunAsClient;
1915
import org.jboss.arquillian.junit.Arquillian;
2016
import org.jboss.arquillian.test.api.ArquillianResource;
2117
import org.jboss.shrinkwrap.api.spec.WebArchive;
@@ -24,7 +20,6 @@
2420
import org.junit.Test;
2521
import org.junit.runner.RunWith;
2622

27-
2823
/**
2924
* Test for the HTTP/2 and the JAX-RS client
3025
*/
@@ -33,10 +28,9 @@ public class Http2Test {
3328

3429
@ArquillianResource
3530
private URL basicUrl;
36-
private Client jaxrsClient;
31+
private HttpClient client;
3732

38-
39-
@Deployment
33+
@Deployment(testable = false)
4034
public static WebArchive createDeployment() {
4135
final WebArchive war = create(WebArchive.class).addClasses(Servlet.class)
4236
.addAsWebResource(new File("src/main/webapp/images/payara-logo.jpg"), "images/payara-logo.jpg")
@@ -48,27 +42,23 @@ public static WebArchive createDeployment() {
4842

4943
@Before
5044
public void setup() throws Exception {
51-
ClientConfig config = new ClientConfig();
52-
config.connectorProvider(JettyConnector::new);
53-
jaxrsClient = ClientBuilder.newClient(config);
45+
client = new HttpClient();
46+
client.start();
5447
}
5548

5649
@After
5750
public void cleanUp() throws Exception {
58-
jaxrsClient.close();
51+
client.stop();
5952
}
6053

61-
6254
/**
6355
* This test runs against the public website supporting HTTP/2
6456
*
6557
* @throws Exception
6658
*/
6759
@Test(timeout = 10000L)
68-
@RunAsClient
6960
public void testHttp2ControlGroup() throws Exception {
70-
Response response = testUri(new URI("https://http2.akamai.com/"));
71-
assertThat("myproto header", response.getHeaderString("myproto"), Matchers.equalTo("h2"));
61+
testHttp2(new URI("https://http2.akamai.com/"));
7262
}
7363

7464
/**
@@ -77,18 +67,11 @@ public void testHttp2ControlGroup() throws Exception {
7767
* @throws Exception
7868
*/
7969
@Test(timeout = 10000L)
80-
@RunAsClient
8170
public void testServerHttp2() throws Exception {
82-
Response response = testUri(basicUrl.toURI());
83-
// the header 'protocol' is set in the Servlet class.
84-
assertThat(
85-
"Request wasn't over HTTP/2. Either the wrong servlet was returned, or the server doesn't support HTTP/2.",
86-
response.getHeaderString("protocol"), Matchers.equalTo("HTTP/2"));
71+
testHttp2(basicUrl.toURI());
8772
}
8873

89-
private Response testUri(URI uri) {
90-
Response response = jaxrsClient.target(uri).request().get();
91-
assertNotNull("response", response);
92-
return response;
74+
private void testHttp2(URI uri) throws InterruptedException, ExecutionException, TimeoutException {
75+
assertEquals("Request wasn't over HTTP/2", HttpVersion.HTTP_2, client.GET(uri).getVersion());
9376
}
9477
}

0 commit comments

Comments
 (0)