Search in sources :

Example 11 with StringContentProvider

use of org.eclipse.jetty.client.util.StringContentProvider in project spring-framework by spring-projects.

the class JettyXhrTransport method executeRequest.

protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body) {
    Request httpRequest = this.httpClient.newRequest(url).method(method);
    addHttpHeaders(httpRequest, headers);
    if (body != null) {
        httpRequest.content(new StringContentProvider(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) StringContentProvider(org.eclipse.jetty.client.util.StringContentProvider) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpStatus(org.springframework.http.HttpStatus) Request(org.eclipse.jetty.client.api.Request) SockJsTransportFailureException(org.springframework.web.socket.sockjs.SockJsTransportFailureException) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) SockJsException(org.springframework.web.socket.sockjs.SockJsException)

Aggregations

StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)11 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)9 Test (org.junit.Test)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 IOException (java.io.IOException)5 InterruptedIOException (java.io.InterruptedIOException)5 ServletException (javax.servlet.ServletException)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 UncheckedIOException (java.io.UncheckedIOException)4 ReadListener (javax.servlet.ReadListener)4 HttpServlet (javax.servlet.http.HttpServlet)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AsyncContext (javax.servlet.AsyncContext)3 ServletInputStream (javax.servlet.ServletInputStream)3 HttpClient (org.eclipse.jetty.client.HttpClient)3 ServletOutputStream (javax.servlet.ServletOutputStream)2 Request (org.eclipse.jetty.client.api.Request)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 FileInputStream (java.io.FileInputStream)1 URI (java.net.URI)1