Skip to content

Commit c9ccfcc

Browse files
committed
Rework Jetty10Http2OverTlsTests so they compile with Java 8
Closes gh-27382
1 parent 46b3d1e commit c9ccfcc

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/build.gradle

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,5 @@ dependencies {
1919
runtimeOnly("org.eclipse.jetty.http2:http2-server")
2020

2121
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
22-
testImplementation("org.eclipse.jetty:jetty-client")
23-
testImplementation("org.eclipse.jetty.http2:http2-client")
24-
testImplementation("org.eclipse.jetty.http2:http2-http-client-transport")
25-
}
26-
27-
def buildingWithJava11OrLater() {
28-
return project.hasProperty("toolchainVersion") || JavaVersion.current().java11Compatible
29-
}
30-
31-
compileTestJava {
32-
enabled = buildingWithJava11OrLater()
33-
}
34-
35-
test {
36-
enabled = buildingWithJava11OrLater()
22+
testImplementation("org.apache.httpcomponents.client5:httpclient5")
3723
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jetty10/src/test/java/smoketest/jetty10/Jetty10Http2OverTlsTests.java

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,26 @@
1616

1717
package smoketest.jetty10;
1818

19-
import org.eclipse.jetty.client.HttpClient;
20-
import org.eclipse.jetty.client.api.ContentResponse;
21-
import org.eclipse.jetty.http2.client.HTTP2Client;
22-
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
23-
import org.eclipse.jetty.io.ClientConnector;
24-
import org.eclipse.jetty.util.ssl.SslContextFactory;
19+
import javax.net.ssl.SSLContext;
20+
21+
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
22+
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
23+
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
24+
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
25+
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
26+
import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder;
27+
import org.apache.hc.client5.http.ssl.TrustAllStrategy;
28+
import org.apache.hc.core5.concurrent.FutureCallback;
29+
import org.apache.hc.core5.http.ContentType;
30+
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
31+
import org.apache.hc.core5.ssl.SSLContexts;
2532
import org.junit.jupiter.api.Test;
2633
import org.junit.jupiter.api.condition.EnabledForJreRange;
2734
import org.junit.jupiter.api.condition.JRE;
2835

2936
import org.springframework.boot.test.context.SpringBootTest;
3037
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
3138
import org.springframework.boot.web.server.LocalServerPort;
32-
import org.springframework.http.HttpStatus;
3339

3440
import static org.assertj.core.api.Assertions.assertThat;
3541

@@ -50,19 +56,30 @@ public class Jetty10Http2OverTlsTests {
5056

5157
@Test
5258
void httpOverTlsGetWhenHttp2AndSslAreEnabledSucceeds() throws Exception {
53-
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
54-
sslContextFactory.setTrustAll(true);
55-
ClientConnector clientConnector = new ClientConnector();
56-
clientConnector.setSslContextFactory(sslContextFactory);
57-
HttpClient client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client(clientConnector)));
58-
client.start();
59-
try {
60-
ContentResponse response = client.GET("https://localhost:" + this.port + "/");
61-
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
62-
assertThat(response.getContentAsString()).isEqualTo("Hello World");
63-
}
64-
finally {
65-
client.stop();
59+
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(new TrustAllStrategy()).build();
60+
TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create().setSslContext(sslContext).build();
61+
try (CloseableHttpAsyncClient http2Client = HttpAsyncClients.customHttp2().setTlsStrategy(tlsStrategy)
62+
.build()) {
63+
http2Client.start();
64+
SimpleHttpRequest request = SimpleHttpRequests.get("https://localhost:" + this.port);
65+
request.setBody("Hello World", ContentType.TEXT_PLAIN);
66+
SimpleHttpResponse response = http2Client.execute(request, new FutureCallback<SimpleHttpResponse>() {
67+
68+
@Override
69+
public void failed(Exception ex) {
70+
}
71+
72+
@Override
73+
public void completed(SimpleHttpResponse result) {
74+
}
75+
76+
@Override
77+
public void cancelled() {
78+
}
79+
80+
}).get();
81+
assertThat(response.getCode()).isEqualTo(200);
82+
assertThat(response.getBodyText()).isEqualTo("Hello World");
6683
}
6784
}
6885

0 commit comments

Comments
 (0)