16
16
17
17
package smoketest .jetty10 ;
18
18
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 ;
25
32
import org .junit .jupiter .api .Test ;
26
33
import org .junit .jupiter .api .condition .EnabledForJreRange ;
27
34
import org .junit .jupiter .api .condition .JRE ;
28
35
29
36
import org .springframework .boot .test .context .SpringBootTest ;
30
37
import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
31
38
import org .springframework .boot .web .server .LocalServerPort ;
32
- import org .springframework .http .HttpStatus ;
33
39
34
40
import static org .assertj .core .api .Assertions .assertThat ;
35
41
@@ -50,19 +56,30 @@ public class Jetty10Http2OverTlsTests {
50
56
51
57
@ Test
52
58
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" );
66
83
}
67
84
}
68
85
0 commit comments