use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getURI.
@Test
public void getURI() throws Exception {
this.mockRequest.addFile(new MockMultipartFile("part", "", "application/json", "content".getBytes("UTF-8")));
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
URI uri = new URI("http://example.com/path?query");
this.mockRequest.setServerName(uri.getHost());
this.mockRequest.setServerPort(uri.getPort());
this.mockRequest.setRequestURI(uri.getPath());
this.mockRequest.setQueryString(uri.getQuery());
assertEquals(uri, request.getURI());
}
use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getMethod.
@Test
public void getMethod() throws Exception {
this.mockRequest.addFile(new MockMultipartFile("part", "", "", "content".getBytes("UTF-8")));
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
this.mockRequest.setMethod("POST");
assertEquals(HttpMethod.POST, request.getMethod());
}
use of org.springframework.http.server.ServerHttpRequest in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getBodyWithWrappedRequest.
// SPR-13317
@Test
public void getBodyWithWrappedRequest() throws Exception {
byte[] bytes = "content".getBytes("UTF-8");
MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes);
this.mockRequest.addFile(part);
HttpServletRequest wrapped = new HttpServletRequestWrapper(this.mockRequest);
ServerHttpRequest request = new RequestPartServletServerHttpRequest(wrapped, "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 getBodyViaRequestParameter.
// SPR-13096
@Test
public void getBodyViaRequestParameter() throws Exception {
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
@Override
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1));
return headers;
}
};
byte[] bytes = { (byte) 0xC4 };
mockRequest.setParameter("part", new String(bytes, StandardCharsets.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 WebUtilsTests method checkValidOrigin.
private boolean checkValidOrigin(String serverName, int port, String originHeader, List<String> allowed) {
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.isValidOrigin(request, allowed);
}
Aggregations