@Override @Nullable protected String[] readMessages(ServerHttpRequest request) throws IOException { return getServiceConfig().getMessageCodec().decodeInputStream(request.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); }
@Test // SPR-13317 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); }
@Test // SPR-13096 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); }
@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); }
/** * Returns the body of the request. * * @return will never be {@literal null}. * @throws IOException */ public InputStream getBody() throws IOException { return request.getBody(); }
/** * Handle a server request. * @param request the request * @param response the response * @throws IOException in case of I/O errors */ public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException { try { Assert.state(request.getHeaders().getContentLength() > 0, "No content"); ObjectInputStream objectInputStream = new ObjectInputStream( request.getBody()); ClassLoaderFiles files = (ClassLoaderFiles) objectInputStream.readObject(); objectInputStream.close(); this.server.updateAndRestart(files); response.setStatusCode(HttpStatus.OK); } catch (Exception ex) { logger.warn("Unable to handler restart server HTTP request", ex); response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); } }
/** * Returns the body of the request. * * @return will never be {@literal null}. * @throws IOException */ public InputStream getBody() throws IOException { return request.getBody(); }
@Override @Nullable protected String[] readMessages(ServerHttpRequest request) throws IOException { return getServiceConfig().getMessageCodec().decodeInputStream(request.getBody()); }
@Override @Nullable protected String[] readMessages(ServerHttpRequest request) throws IOException { return getServiceConfig().getMessageCodec().decodeInputStream(request.getBody()); }
@Override @Nullable protected String[] readMessages(ServerHttpRequest request) throws IOException { SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec(); MediaType contentType = request.getHeaders().getContentType(); if (contentType != null && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) { MultiValueMap<String, String> map = this.formConverter.read(null, request); String d = map.getFirst("d"); return (StringUtils.hasText(d) ? messageCodec.decode(d) : null); } else { return messageCodec.decodeInputStream(request.getBody()); } }