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);
}
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();
}
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);
}
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);
}
}
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;
}
Aggregations