Java Code Examples for org.springframework.http.server.ServletServerHttpResponse#getBody()
The following examples show how to use
org.springframework.http.server.ServletServerHttpResponse#getBody() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpHeadersReturnValueHandler.java From spring-analysis-note with MIT License | 6 votes |
@Override @SuppressWarnings("resource") public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { mavContainer.setRequestHandled(true); Assert.state(returnValue instanceof HttpHeaders, "HttpHeaders expected"); HttpHeaders headers = (HttpHeaders) returnValue; if (!headers.isEmpty()) { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); Assert.state(servletResponse != null, "No HttpServletResponse"); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse); outputMessage.getHeaders().putAll(headers); outputMessage.getBody(); // flush headers } }
Example 2
Source File: HttpHeadersReturnValueHandler.java From java-technology-stack with MIT License | 6 votes |
@Override @SuppressWarnings("resource") public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { mavContainer.setRequestHandled(true); Assert.state(returnValue instanceof HttpHeaders, "HttpHeaders expected"); HttpHeaders headers = (HttpHeaders) returnValue; if (!headers.isEmpty()) { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); Assert.state(servletResponse != null, "No HttpServletResponse"); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse); outputMessage.getHeaders().putAll(headers); outputMessage.getBody(); // flush headers } }
Example 3
Source File: HttpHeadersReturnValueHandler.java From lams with GNU General Public License v2.0 | 6 votes |
@Override @SuppressWarnings("resource") public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { mavContainer.setRequestHandled(true); Assert.state(returnValue instanceof HttpHeaders, "HttpHeaders expected"); HttpHeaders headers = (HttpHeaders) returnValue; if (!headers.isEmpty()) { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse); outputMessage.getHeaders().putAll(headers); outputMessage.getBody(); // flush headers } }
Example 4
Source File: HttpHeadersReturnValueHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("resource") public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { mavContainer.setRequestHandled(true); Assert.isInstanceOf(HttpHeaders.class, returnValue); HttpHeaders headers = (HttpHeaders) returnValue; if (!headers.isEmpty()) { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse); outputMessage.getHeaders().putAll(headers); outputMessage.getBody(); // flush headers } }
Example 5
Source File: PropertiesHandlerMethodReturnValueHandler.java From SpringAll with MIT License | 5 votes |
@Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { Properties properties = (Properties) returnValue; ServletWebRequest servletWebRequest = (ServletWebRequest) webRequest; HttpServletResponse response = servletWebRequest.getResponse(); ServletServerHttpResponse servletServerHttpResponse = new ServletServerHttpResponse(response); // 获取请求头 HttpHeaders headers = servletServerHttpResponse.getHeaders(); MediaType contentType = headers.getContentType(); // 获取编码 Charset charset = null; if (contentType != null) { charset = contentType.getCharset(); } charset = charset == null ? Charset.forName("UTF-8") : charset; // 获取请求体 OutputStream body = servletServerHttpResponse.getBody(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(body, charset); properties.store(outputStreamWriter, "Serialized by PropertiesHandlerMethodReturnValueHandler#handleReturnValue"); // 告诉 Spring MVC 请求已经处理完毕 mavContainer.setRequestHandled(true); }
Example 6
Source File: AbstractWxMessageReturnValueHandler.java From FastBootWeixin with Apache License 2.0 | 5 votes |
@Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { // @WxAsyncMessage声明的Handler恒为null,这里提供支持 if (returnValue != null) { handlReturnValueInternal(returnValue); } mavContainer.setRequestHandled(true); HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse); outputMessage.getBody(); }
Example 7
Source File: WxMessageReturnValueHandler.java From FastBootWeixin with Apache License 2.0 | 5 votes |
@Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnType.hasMethodAnnotation(WxAsyncMessage.class)) { wxAsyncMessageTemplate.send(WxWebUtils.getWxMessageParameter(), returnValue); } else { wxMessageTemplate.sendMessage(WxWebUtils.getWxMessageParameter(), returnValue); } HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse); mavContainer.setRequestHandled(true); outputMessage.getBody(); }
Example 8
Source File: WxMappingReturnValueHandler.java From FastBootWeixin with Apache License 2.0 | 5 votes |
@Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class); ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse); if (WxMessageUtils.supportsXmlResponse(returnType.getParameterType()) && returnValue != null) { wxXmlMessageConverter.write(returnValue, MediaType.TEXT_XML, outputMessage); } else { wxAsyncMessageTemplate.send(WxWebUtils.getWxMessageParameter(), returnValue); } mavContainer.setRequestHandled(true); outputMessage.getBody(); }