use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.
the class WebUtilsTests method checkSameOrigin.
private boolean checkSameOrigin(String serverName, int port, String originHeader) {
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
servletRequest.setServerName(serverName);
if (port != -1) {
servletRequest.setServerPort(port);
}
request.getHeaders().set(HttpHeaders.ORIGIN, originHeader);
return WebUtils.isSameOrigin(request);
}
use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getContentType.
@Test
public void getContentType() throws Exception {
MultipartFile part = new MockMultipartFile("part", "", "application/json", "content".getBytes("UTF-8"));
this.mockRequest.addFile(part);
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
HttpHeaders headers = request.getHeaders();
assertNotNull(headers);
assertEquals(MediaType.APPLICATION_JSON, headers.getContentType());
}
use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getBody.
@Test
public void getBody() throws Exception {
byte[] bytes = "content".getBytes("UTF-8");
MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes);
this.mockRequest.addFile(part);
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
assertArrayEquals(bytes, result);
}
use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getBodyViaRequestParameterWithRequestEncoding.
@Test
public void getBodyViaRequestParameterWithRequestEncoding() throws Exception {
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
@Override
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return headers;
}
};
byte[] bytes = { (byte) 0xC4 };
mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1));
mockRequest.setCharacterEncoding("iso-8859-1");
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
assertArrayEquals(bytes, result);
}
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;
}
}
}
Aggregations