com.gitee.easyopen.ApiRespWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easyopen-mini Show documentation
Show all versions of easyopen-mini Show documentation
easyopen mini版,保留基本签名校验,文档功能。https://gitee.com/durcframework/easyopen
package com.gitee.easyopen;
import com.gitee.easyopen.bean.Consts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* 负责结果输出
*
* @author tanghc
*/
public class ApiRespWriter implements RespWriter {
private static Logger logger = LoggerFactory.getLogger(ApiRespWriter.class);
@Override
public void write(HttpServletRequest request, HttpServletResponse response, Object result) {
if (result == null) {
return;
}
ApiConfig apiConfig = ApiContext.getApiConfig();
String returnText = apiConfig.getJsonResultSerializer().serialize(result);
String contentType = MediaType.APPLICATION_JSON_UTF8_VALUE;
doWriter(response, contentType, returnText);
}
/**
* 发送内容
*
* @param response
* @param contentType
* @param text
*/
public static void doWriter(HttpServletResponse response, String contentType, String text) {
response.setContentType(contentType);
response.setCharacterEncoding(Consts.UTF8);
try {
response.getWriter().write(text);
} catch (IOException e) {
logger.error("doWriter", e);
}
}
}