Search in sources :

Example 16 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.

the class WebSocketHttpRequestHandler method handleRequest.

@Override
public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
    ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    ServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
    HandshakeInterceptorChain chain = new HandshakeInterceptorChain(this.interceptors, this.wsHandler);
    HandshakeFailureException failure = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug(servletRequest.getMethod() + " " + servletRequest.getRequestURI());
        }
        Map<String, Object> attributes = new HashMap<>();
        if (!chain.applyBeforeHandshake(request, response, attributes)) {
            return;
        }
        this.handshakeHandler.doHandshake(request, response, this.wsHandler, attributes);
        chain.applyAfterHandshake(request, response, null);
        response.close();
    } catch (HandshakeFailureException ex) {
        failure = ex;
    } catch (Throwable ex) {
        failure = new HandshakeFailureException("Uncaught failure for request " + request.getURI(), ex);
    } finally {
        if (failure != null) {
            chain.applyAfterHandshake(request, response, failure);
            throw failure;
        }
    }
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) HashMap(java.util.HashMap) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) HandshakeFailureException(org.springframework.web.socket.server.HandshakeFailureException) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse)

Example 17 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.

the class SockJsHttpRequestHandler method handleRequest.

@Override
public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
    ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    ServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
    try {
        this.sockJsService.handleRequest(request, response, getSockJsPath(servletRequest), this.webSocketHandler);
    } catch (Throwable ex) {
        throw new SockJsException("Uncaught failure in SockJS request, uri=" + request.getURI(), ex);
    }
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) SockJsException(org.springframework.web.socket.sockjs.SockJsException) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse)

Example 18 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-boot by spring-projects.

the class HttpTunnelServerTests method httpConnectionAsync.

@Test
public void httpConnectionAsync() throws Exception {
    ServerHttpAsyncRequestControl async = mock(ServerHttpAsyncRequestControl.class);
    ServerHttpRequest request = mock(ServerHttpRequest.class);
    given(request.getAsyncRequestControl(this.response)).willReturn(async);
    HttpConnection connection = new HttpConnection(request, this.response);
    connection.waitForResponse();
    verify(async).start();
    connection.respond(HttpStatus.NO_CONTENT);
    verify(async).complete();
}
Also used : HttpConnection(org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServerHttpAsyncRequestControl(org.springframework.http.server.ServerHttpAsyncRequestControl) Test(org.junit.Test)

Example 19 with ServerHttpRequest

use of org.springframework.http.server.ServerHttpRequest in project spring-boot by spring-projects.

the class UrlHandlerMapperTests method ignoresDifferentUrl.

@Test
public void ignoresDifferentUrl() throws Exception {
    UrlHandlerMapper mapper = new UrlHandlerMapper("/tunnel", this.handler);
    HttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/tunnel/other");
    ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    assertThat(mapper.getHandler(request)).isNull();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServerHttpRequest(org.springframework.http.server.ServerHttpRequest) Test(org.junit.Test)

Aggregations

ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)19 Test (org.junit.Test)13 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)10 ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)6 MockMultipartFile (org.springframework.mock.web.test.MockMultipartFile)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)4 HttpHeaders (org.springframework.http.HttpHeaders)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockMultipartHttpServletRequest (org.springframework.mock.web.test.MockMultipartHttpServletRequest)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 HttpConnection (org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection)2 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)2 URI (java.net.URI)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MediaType (org.springframework.http.MediaType)1 ServerHttpAsyncRequestControl (org.springframework.http.server.ServerHttpAsyncRequestControl)1