Example usage for org.springframework.http.server ServletServerHttpResponse getBody

List of usage examples for org.springframework.http.server ServletServerHttpResponse getBody

Introduction

In this page you can find the example usage for org.springframework.http.server ServletServerHttpResponse getBody.

Prototype

@Override
    public OutputStream getBody() throws IOException 

Source Link

Usage

From source file:com.zuoxiaolong.blog.common.web.JsonHandlerMethodReturnValueHandler.java

@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
        ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
    mavContainer.setRequestHandled(true);
    HttpServletResponse httpServletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
    httpServletResponse.setContentType(CONTENT_TYPE);
    ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(httpServletResponse);
    JsonResponse jsonResponse = new JsonResponse(returnValue);
    outputMessage.getBody().write(StringUtils.toBytes(JsonUtils.toJson(jsonResponse)));
    outputMessage.getBody().flush();//w  ww.j a  v  a 2  s .  co  m
}

From source file:com.iflytek.edu.cloud.frame.spring.RequestResponseBodyMethodProcessorExt.java

private void write(final String content, MediaType contentType, ServletServerHttpResponse outputMessage)
        throws IOException, HttpMessageNotWritableException {
    final HttpHeaders headers = outputMessage.getHeaders();
    headers.setContentType(contentType);
    if (headers.getContentLength() == -1) {
        Long contentLength = getContentLength(content, headers.getContentType());
        if (contentLength != null) {
            headers.setContentLength(contentLength);
        }//  w  w w.  ja  v a2  s  .  c  o m
    }

    StreamUtils.copy(content, charset, outputMessage.getBody());
    outputMessage.getBody().flush();
}