Search in sources :

Example 11 with ServerHttpResponse

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

the class DispatcherFilter method doFilter.

private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    ServerHttpRequest serverRequest = new ServletServerHttpRequest(request);
    ServerHttpResponse serverResponse = new ServletServerHttpResponse(response);
    if (!this.dispatcher.handle(serverRequest, serverResponse)) {
        chain.doFilter(request, response);
    }
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) 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 12 with ServerHttpResponse

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

the class AbstractHttpSockJsSession method writeFrameInternal.

@Override
protected void writeFrameInternal(SockJsFrame frame) throws IOException {
    if (isActive()) {
        SockJsFrameFormat frameFormat = this.frameFormat;
        ServerHttpResponse response = this.response;
        if (frameFormat != null && response != null) {
            String formattedFrame = frameFormat.format(frame);
            if (logger.isTraceEnabled()) {
                logger.trace("Writing to HTTP response: " + formattedFrame);
            }
            response.getBody().write(formattedFrame.getBytes(SockJsFrame.CHARSET));
            response.flush();
        }
    }
}
Also used : SockJsFrameFormat(org.springframework.web.socket.sockjs.frame.SockJsFrameFormat) ServerHttpResponse(org.springframework.http.server.ServerHttpResponse)

Example 13 with ServerHttpResponse

use of org.springframework.http.server.ServerHttpResponse 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);
    } catch (HandshakeFailureException ex) {
        failure = ex;
    } catch (Exception ex) {
        failure = new HandshakeFailureException("Uncaught failure for request " + request.getURI(), ex);
    } finally {
        if (failure != null) {
            chain.applyAfterHandshake(request, response, failure);
            response.close();
            throw failure;
        }
        response.close();
    }
}
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) ServletException(jakarta.servlet.ServletException) IOException(java.io.IOException) HandshakeFailureException(org.springframework.web.socket.server.HandshakeFailureException)

Example 14 with ServerHttpResponse

use of org.springframework.http.server.ServerHttpResponse 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 (Exception 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) SockJsException(org.springframework.web.socket.sockjs.SockJsException) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException)

Aggregations

ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)14 ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)9 ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)9 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)8 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)4 IOException (java.io.IOException)3 Test (org.junit.jupiter.api.Test)3 ResponseEntity (org.springframework.http.ResponseEntity)3 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)3 ServletException (jakarta.servlet.ServletException)2 ServletRequest (jakarta.servlet.ServletRequest)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)2 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)1 InstanceRegistry (de.codecentric.boot.admin.server.services.InstanceRegistry)1 AdminController (de.codecentric.boot.admin.server.web.AdminController)1 HttpHeaderFilter (de.codecentric.boot.admin.server.web.HttpHeaderFilter)1 InstanceWebProxy (de.codecentric.boot.admin.server.web.InstanceWebProxy)1