use of org.eclipse.jetty.client.util.StringRequestContent in project spring-boot by spring-projects.
the class AbstractReactiveWebServerFactoryTests method whenHttp2IsEnabledAndSslIsDisabledThenH2cCanBeUsed.
@Test
protected void whenHttp2IsEnabledAndSslIsDisabledThenH2cCanBeUsed() throws Exception {
AbstractReactiveWebServerFactory factory = getFactory();
Http2 http2 = new Http2();
http2.setEnabled(true);
factory.setHttp2(http2);
this.webServer = factory.getWebServer(new EchoHandler());
this.webServer.start();
org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client()));
client.start();
try {
ContentResponse response = client.POST("http://localhost:" + this.webServer.getPort()).body(new StringRequestContent("text/plain", "Hello World")).send();
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(response.getContentAsString()).isEqualTo("Hello World");
} finally {
client.stop();
}
}
use of org.eclipse.jetty.client.util.StringRequestContent in project spring-framework by spring-projects.
the class JettyXhrTransport method executeRequest.
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, @Nullable String body) {
Request httpRequest = this.httpClient.newRequest(url).method(method);
addHttpHeaders(httpRequest, headers);
if (body != null) {
httpRequest.body(new StringRequestContent(body));
}
ContentResponse response;
try {
response = httpRequest.send();
} catch (Exception ex) {
throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
}
HttpStatus status = HttpStatus.valueOf(response.getStatus());
HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
return (response.getContent() != null ? new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) : new ResponseEntity<>(responseHeaders, status));
}
Aggregations