List of usage examples for org.springframework.http.server ServletServerHttpResponse getServletResponse
public HttpServletResponse getServletResponse()
From source file:com.careerly.common.support.msgconverter.JsonpHttpMessageConverter.java
@Override protected void writeInternal(JsonpResponse t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { ServletServerHttpResponse response = (ServletServerHttpResponse) outputMessage; response.getServletResponse().setCharacterEncoding("UTF-8"); BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(outputMessage.getBody(), Charset.forName("UTF-8"))); try {/*from w w w. j a v a 2s.c om*/ if (StringUtils.isNotBlank(t.getCallback())) { bw.write(StringEscapeUtils.escapeHtml(t.getCallback())); bw.write("("); } bw.write(JsonUtils.marshalToString(t.getJson())); if (StringUtils.isNotBlank(t.getCallback())) { bw.write(")"); } } finally { bw.close(); } }
From source file:com.careerly.common.support.msgconverter.CsvHttpMessageConverter.java
@Override protected void writeInternal(CsvResponse t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { ServletServerHttpResponse response = (ServletServerHttpResponse) outputMessage; response.getServletResponse().setCharacterEncoding("UTF-8"); outputMessage.getHeaders().set("Content-Disposition", "attachment; filename=\"" + t.getFileName() + "\""); BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(outputMessage.getBody(), Charset.forName("UTF-8"))); try {//from www.jav a 2 s. c o m for (List<String> line : Iterables.concat(Collections.singleton(t.getHead()), t.getBody())) { for (int i = 0; i < line.size(); i++) { if (line.get(i) != null) { bw.write("\""); bw.write(line.get(i)); bw.write("\""); } if (i < line.size() - 1) { bw.write(seperator); } } bw.newLine(); } } finally { bw.close(); } }
From source file:org.makersoft.mvc.method.annotation.FormatHandlerMethodReturnValueHandler.java
protected <T extends Object> void writeWithJSONSerialize(T returnValue, MethodParameter returnType, NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException { ServletServerHttpRequest inputMessage = this.createInputMessage(webRequest); ServletServerHttpResponse outputMessage = this.createOutputMessage(webRequest); Format format = returnType.getMethodAnnotation(Format.class); JSONResult result = new JSONResult(); if (format.excludes().length > 0) { result.setExcludeProperties(StringUtils.join(format.excludes(), ",")); }// w w w .j av a2 s . c om if (format.includes().length > 0) { result.setIncludeProperties(StringUtils.join(format.includes(), ",")); } // default false result.setIgnoreHierarchy(format.ignoreHierarchy()); //settings result.setEncoding(encoding); result.setWrapWithComments(wrapWithComments); result.setPrefix(prefix); result.setEnableGZIP(enableGZIP); result.setEnumAsBean(enumAsBean); result.setNoCache(noCache); result.setExcludeNullProperties(excludeNullProperties); result.setCallbackParameter(callbackParameter); result.setWrapPrefix(wrapPrefix); result.setWrapSuffix(wrapSuffix); try { result.execute(inputMessage.getServletRequest(), outputMessage.getServletResponse(), returnValue); } catch (Exception e) { throw new RuntimeException(e); } }