whycxzp
2022-06-08 9197c93e9a5b2c184004e9919ec91712824f10e3
src/com/fgkj/interceptor/ExceptionInterceptor.java
@@ -1,10 +1,18 @@
package com.fgkj.interceptor;
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.UinfDaoFactory;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_log;
import com.fgkj.services.User_logService;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import org.apache.struts2.ServletActionContext;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ExceptionInterceptor extends AbstractInterceptor {
    private static final long serialVersionUID = 4153142432948747854L;
@@ -15,20 +23,32 @@
    }
    @Override
    public String intercept(ActionInvocation actionInvocation) {
    public String intercept(ActionInvocation actionInvocation) throws IOException {
        String result = null;
        try {
            result = actionInvocation.invoke();
        } catch (Exception e) {
            String actionName = actionInvocation.getProxy().getActionName();
            String errorMsg = e.toString();
            String msg = "接口调用异常:调用接口"+actionName+"发生错误:"+errorMsg;
            String msg = "接口调用异常:调用接口" + actionName + "发生错误:" + errorMsg;
            //日志记录
            {
                User_log ulog = UinfDaoFactory.CreateULog(UinfDaoFactory.EXCEPTION, msg);
                new User_logService().addAbnormal(ulog);
            }
            return "error";
            ServiceModel model = new ServiceModel();
            HttpServletResponse response = ServletActionContext.getResponse();
            response.setContentType("application/json;charset=utf-8");
            model.setMsg("接口调用无数据返回");
            Map<String, ServiceModel> map = new HashMap<>();
            map.put("result", model);
            String resultJson = ActionUtil.tojson(map);
            response.getWriter().write(resultJson);
            return "none";
        }
        return result;