mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Merge branch '2.5.x'
Closes gh-27383
This commit is contained in:
commit
0d1d637c73
@ -19,19 +19,5 @@ dependencies {
|
||||
runtimeOnly("org.eclipse.jetty.http2:http2-server")
|
||||
|
||||
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
|
||||
testImplementation("org.eclipse.jetty:jetty-client")
|
||||
testImplementation("org.eclipse.jetty.http2:http2-client")
|
||||
testImplementation("org.eclipse.jetty.http2:http2-http-client-transport")
|
||||
}
|
||||
|
||||
def buildingWithJava11OrLater() {
|
||||
return project.hasProperty("toolchainVersion") || JavaVersion.current().java11Compatible
|
||||
}
|
||||
|
||||
compileTestJava {
|
||||
enabled = buildingWithJava11OrLater()
|
||||
}
|
||||
|
||||
test {
|
||||
enabled = buildingWithJava11OrLater()
|
||||
testImplementation("org.apache.httpcomponents.client5:httpclient5")
|
||||
}
|
||||
|
@ -16,12 +16,19 @@
|
||||
|
||||
package smoketest.jetty10;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http2.client.HTTP2Client;
|
||||
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
|
||||
import org.eclipse.jetty.io.ClientConnector;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
|
||||
import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder;
|
||||
import org.apache.hc.client5.http.ssl.TrustAllStrategy;
|
||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
|
||||
import org.apache.hc.core5.ssl.SSLContexts;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
@ -29,7 +36,6 @@ import org.junit.jupiter.api.condition.JRE;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ -50,19 +56,30 @@ public class Jetty10Http2OverTlsTests {
|
||||
|
||||
@Test
|
||||
void httpOverTlsGetWhenHttp2AndSslAreEnabledSucceeds() throws Exception {
|
||||
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
|
||||
sslContextFactory.setTrustAll(true);
|
||||
ClientConnector clientConnector = new ClientConnector();
|
||||
clientConnector.setSslContextFactory(sslContextFactory);
|
||||
HttpClient client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client(clientConnector)));
|
||||
client.start();
|
||||
try {
|
||||
ContentResponse response = client.GET("https://localhost:" + this.port + "/");
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(response.getContentAsString()).isEqualTo("Hello World");
|
||||
}
|
||||
finally {
|
||||
client.stop();
|
||||
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(new TrustAllStrategy()).build();
|
||||
TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create().setSslContext(sslContext).build();
|
||||
try (CloseableHttpAsyncClient http2Client = HttpAsyncClients.customHttp2().setTlsStrategy(tlsStrategy)
|
||||
.build()) {
|
||||
http2Client.start();
|
||||
SimpleHttpRequest request = SimpleHttpRequests.get("https://localhost:" + this.port);
|
||||
request.setBody("Hello World", ContentType.TEXT_PLAIN);
|
||||
SimpleHttpResponse response = http2Client.execute(request, new FutureCallback<SimpleHttpResponse>() {
|
||||
|
||||
@Override
|
||||
public void failed(Exception ex) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(SimpleHttpResponse result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelled() {
|
||||
}
|
||||
|
||||
}).get();
|
||||
assertThat(response.getCode()).isEqualTo(200);
|
||||
assertThat(response.getBodyText()).isEqualTo("Hello World");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user