Search in sources :

Example 1 with StringRequestContent

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();
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Http2(org.springframework.boot.web.server.Http2) HttpClientTransportOverHTTP2(org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2) HttpClient(reactor.netty.http.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) StringRequestContent(org.eclipse.jetty.client.util.StringRequestContent) Test(org.junit.jupiter.api.Test)

Example 2 with StringRequestContent

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));
}
Also used : SockJsTransportFailureException(org.springframework.web.socket.sockjs.SockJsTransportFailureException) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpStatus(org.springframework.http.HttpStatus) Request(org.eclipse.jetty.client.api.Request) StringRequestContent(org.eclipse.jetty.client.util.StringRequestContent) SockJsTransportFailureException(org.springframework.web.socket.sockjs.SockJsTransportFailureException) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) SockJsException(org.springframework.web.socket.sockjs.SockJsException)

Aggregations

ContentResponse (org.eclipse.jetty.client.api.ContentResponse)2 StringRequestContent (org.eclipse.jetty.client.util.StringRequestContent)2 Request (org.eclipse.jetty.client.api.Request)1 HTTP2Client (org.eclipse.jetty.http2.client.HTTP2Client)1 HttpClientTransportOverHTTP2 (org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2)1 Test (org.junit.jupiter.api.Test)1 Http2 (org.springframework.boot.web.server.Http2)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpStatus (org.springframework.http.HttpStatus)1 ResponseEntity (org.springframework.http.ResponseEntity)1 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)1 SockJsException (org.springframework.web.socket.sockjs.SockJsException)1 SockJsTransportFailureException (org.springframework.web.socket.sockjs.SockJsTransportFailureException)1 HttpClient (reactor.netty.http.client.HttpClient)1