Search in sources :

Example 76 with ServletServerHttpRequest

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

the class HttpRestartServerTests method sendClassLoaderFiles.

@Test
void sendClassLoaderFiles() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    ClassLoaderFiles files = new ClassLoaderFiles();
    files.addFile("name", new ClassLoaderFile(Kind.ADDED, new byte[0]));
    byte[] bytes = serialize(files);
    request.setContent(bytes);
    this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
    then(this.delegate).should().updateAndRestart(this.filesCaptor.capture());
    assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) Test(org.junit.jupiter.api.Test)

Example 77 with ServletServerHttpRequest

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

the class HttpTunnelServerTests method setup.

@BeforeEach
void setup() {
    this.server = new HttpTunnelServer(this.serverConnection);
    this.servletRequest = new MockHttpServletRequest();
    this.servletRequest.setAsyncSupported(true);
    this.servletResponse = new MockHttpServletResponse();
    this.request = new ServletServerHttpRequest(this.servletRequest);
    this.response = new ServletServerHttpResponse(this.servletResponse);
    this.serverChannel = new MockServerChannel();
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 78 with ServletServerHttpRequest

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

the class HttpStatusHandlerTests method setup.

@BeforeEach
void setup() {
    this.servletRequest = new MockHttpServletRequest();
    this.servletResponse = new MockHttpServletResponse();
    this.request = new ServletServerHttpRequest(this.servletRequest);
    this.response = new ServletServerHttpResponse(this.servletResponse);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 79 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest 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 80 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest in project CzechIdMng by bcvsolutions.

the class ExceptionControllerAdvice method createHttpHeaders.

/**
 * TODO: CorsProcessor should be registered before filters with exception => this method can be removed after.
 *
 * @param request
 * @param response
 * @return
 */
@SuppressWarnings("resource")
private HttpHeaders createHttpHeaders(HttpServletRequest request, HttpServletResponse response) {
    // cors is not required
    if (!CorsUtils.isCorsRequest(request)) {
        return new HttpHeaders();
    }
    // already filled
    ServletServerHttpResponse serverResponse = new ServletServerHttpResponse(response);
    HttpHeaders httpHeaders = serverResponse.getHeaders();
    if (responseHasCors(serverResponse)) {
        return httpHeaders;
    }
    // request is from same origin
    ServletServerHttpRequest serverRequest = new ServletServerHttpRequest(request);
    if (WebUtils.isSameOrigin(serverRequest)) {
        return httpHeaders;
    }
    // 
    String requestOrigin = serverRequest.getHeaders().getOrigin();
    String allowOrigin = corsConfiguration.checkOrigin(requestOrigin);
    if (allowOrigin == null) {
        return httpHeaders;
    }
    // 
    // append required cors headers
    httpHeaders.addAll(HttpHeaders.VARY, Arrays.asList(HttpHeaders.ORIGIN, HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS));
    httpHeaders.setAccessControlAllowOrigin(allowOrigin);
    if (Boolean.TRUE.equals(corsConfiguration.getAllowCredentials())) {
        httpHeaders.setAccessControlAllowCredentials(true);
    }
    // 
    return httpHeaders;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse)

Aggregations

ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)111 Test (org.junit.jupiter.api.Test)39 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)39 HttpRequest (org.springframework.http.HttpRequest)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)22 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)13 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)10 IOException (java.io.IOException)8 ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 HttpHeaders (org.springframework.http.HttpHeaders)7 MediaType (org.springframework.http.MediaType)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 HttpInputMessage (org.springframework.http.HttpInputMessage)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 URI (java.net.URI)4 ResponseEntity (org.springframework.http.ResponseEntity)4