Browse Source

新增日志拦截切面

chenweida 8 years ago
parent
commit
c13eaaf326

+ 4 - 14
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/common/Envelop.java

@ -21,13 +21,13 @@ public class Envelop implements Serializable {
    private static final long serialVersionUID = 2076324875575488461L;
    private int pageSize = 10;
    private Integer pageSize = 10;
    private int currPage;
    private Integer currPage;
    private int totalPage;
    private Integer totalPage;
    private int totalCount;
    private Integer totalCount;
    private List detailModelList;
@ -37,8 +37,6 @@ public class Envelop implements Serializable {
    private String successMsg;
    private int errorCode;
    public Object getObj() {
        return obj;
    }
@ -71,13 +69,6 @@ public class Envelop implements Serializable {
        this.errorMsg = errorMsg;
    }
    public int getErrorCode() {
        return errorCode;
    }
    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }
    public int getPageSize() {
        return pageSize;
@ -141,7 +132,6 @@ public class Envelop implements Serializable {
    public static Envelop getError(String message,int errorCode) {
        Envelop envelop = new Envelop();
        envelop.setErrorMsg(message);
        envelop.setErrorCode(errorCode);
        return envelop;
    }

+ 2 - 1
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/gateway/GatewayContanrts.java

@ -8,6 +8,7 @@ public class GatewayContanrts {
    public static final class ZipkinElasticKey {
        static public String gateway_input_params = "gateway_input_params";
        static public String gateway_out_params = "gateway_out_params";
        static public String gateway_out_params = "gateway_output_params";
        static public String gateway_error_params = "gateway_error_params";
    }
}

+ 14 - 3
web-gateway/src/main/java/com/yihu/jw/config/mvc/GlobalHandlerExceptionResolver.java

@ -4,8 +4,12 @@ import com.yihu.jw.restmodel.exception.SecurityException;
import com.yihu.jw.restmodel.exception.SystemException;
import com.yihu.jw.restmodel.exception.business.JiWeiException;
import com.yihu.jw.restmodel.exception.business.ManageException;
import com.yihu.jw.restmodel.gateway.GatewayContanrts;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
@ -25,7 +29,8 @@ public class GlobalHandlerExceptionResolver implements HandlerExceptionResolver
    private static Integer status_500 = 500;//后台异常
    private static Integer status_510 = 510;//基卫系统异常
    private static Integer status_511 = 511;//后台管理系统异常
    @Autowired
    private Tracer tracer;
    /**
     * 在这里处理所有得异常信息
@ -43,7 +48,7 @@ public class GlobalHandlerExceptionResolver implements HandlerExceptionResolver
        } else if (ex instanceof JiWeiException) {
            //基卫系统异常
            printWrite(status_510, error, resp);
        }else{
        } else {
            //系统异常
            printWrite(status_500, error, resp);
        }
@ -53,8 +58,14 @@ public class GlobalHandlerExceptionResolver implements HandlerExceptionResolver
    /**
     * 将错误信息添加到response中
     */
    public static void printWrite(int status, String msg, HttpServletResponse response) {
    public  void printWrite(int status, String msg, HttpServletResponse response) {
        try {
            JSONObject jo=new JSONObject();
            jo.put("status",status);
            jo.put("msg",msg);
            tracer.getCurrentSpan().tag(GatewayContanrts.ZipkinElasticKey.gateway_error_params,jo.toString());
            response.setStatus(status);
            response.setCharacterEncoding("UTF-8");//设置编码
            response.setHeader("Cache-Control", "no-store");