|
@ -4,6 +4,20 @@ import com.netflix.zuul.FilterProcessor;
|
|
import com.netflix.zuul.ZuulFilter;
|
|
import com.netflix.zuul.ZuulFilter;
|
|
import com.netflix.zuul.context.RequestContext;
|
|
import com.netflix.zuul.context.RequestContext;
|
|
import com.netflix.zuul.exception.ZuulException;
|
|
import com.netflix.zuul.exception.ZuulException;
|
|
|
|
import com.yihu.jw.entity.base.dict.BaseExceptionLogDO;
|
|
|
|
import com.yihu.jw.gateway.methlog.BaseExceptionService;
|
|
|
|
import com.yihu.jw.gateway.methlog.dao.BaseExceptionDictDao;
|
|
|
|
import com.yihu.jw.gateway.methlog.dao.BaseExceptionLogDao;
|
|
|
|
import com.yihu.jw.gateway.methlog.dao.BaseExceptionServerDictDao;
|
|
|
|
import com.yihu.jw.gateway.security.BeanUtil;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created with IntelliJ IDEA.
|
|
* Created with IntelliJ IDEA.
|
|
@ -12,6 +26,7 @@ import com.netflix.zuul.exception.ZuulException;
|
|
* @Date: 2021/5/19
|
|
* @Date: 2021/5/19
|
|
* @Description:
|
|
* @Description:
|
|
*/
|
|
*/
|
|
|
|
@Component
|
|
public class DidiFilterProcessor extends FilterProcessor {
|
|
public class DidiFilterProcessor extends FilterProcessor {
|
|
@Override
|
|
@Override
|
|
public Object processZuulFilter(ZuulFilter filter) throws ZuulException {
|
|
public Object processZuulFilter(ZuulFilter filter) throws ZuulException {
|
|
@ -19,8 +34,38 @@ public class DidiFilterProcessor extends FilterProcessor {
|
|
return super.processZuulFilter(filter);
|
|
return super.processZuulFilter(filter);
|
|
} catch (ZuulException e) {
|
|
} catch (ZuulException e) {
|
|
if (e.nStatusCode==500){
|
|
if (e.nStatusCode==500){
|
|
|
|
String message="";
|
|
|
|
String cause="";
|
|
|
|
String serviceId="";
|
|
|
|
String responseCode="";
|
|
|
|
String exceptionType="";
|
|
|
|
BaseExceptionLogDao baseExceptionLogDao = BeanUtil.getBean(BaseExceptionLogDao.class);
|
|
|
|
//BaseExceptionDictDao baseExceptionDictDao = BeanUtil.getBean(BaseExceptionDictDao.class);
|
|
|
|
BaseExceptionService baseExceptionService = BeanUtil.getBean(BaseExceptionService.class);
|
|
|
|
List<Map<String,Object>> list = baseExceptionService.findExceptionDict("","110001","","1");
|
|
RequestContext ctx = RequestContext.getCurrentContext();
|
|
RequestContext ctx = RequestContext.getCurrentContext();
|
|
ZuulException e1 = new ZuulException("123456",10085,"10000");
|
|
|
|
|
|
List<Map<String,Object>> serviceList=baseExceptionService.findExceptionService("","","1","");
|
|
|
|
for (Map<String,Object> map:serviceList){
|
|
|
|
if (ctx.getRequest().getServletPath().contains(map.get("pathUrl").toString())){
|
|
|
|
serviceId=map.get("id").toString();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (list!=null&&list.size()>0){
|
|
|
|
message = list.get(0).get("remindContent").toString();
|
|
|
|
cause=list.get(0).get("exceptionMessage").toString();
|
|
|
|
responseCode=serviceId+list.get(0).get("code").toString();
|
|
|
|
exceptionType = list.get(0).get("exceptionType").toString();
|
|
|
|
}
|
|
|
|
ZuulException e1 = new ZuulException(message, StringUtils.isEmpty(responseCode)?99999999:Integer.valueOf(responseCode),cause);
|
|
|
|
BaseExceptionLogDO baseExceptionLogDO = new BaseExceptionLogDO();
|
|
|
|
baseExceptionLogDO.setCreateTime(new Date());
|
|
|
|
baseExceptionLogDO.setExceptionType(exceptionType);
|
|
|
|
baseExceptionLogDO.setServiceCode(serviceId);
|
|
|
|
baseExceptionLogDO.setExceptionCode(responseCode);
|
|
|
|
baseExceptionLogDO.setRequest(ctx.getRequest().toString());
|
|
|
|
baseExceptionLogDO.setResponse(ctx.toString());
|
|
|
|
baseExceptionLogDao.save(baseExceptionLogDO);
|
|
ctx.set("failed.exception", e1);
|
|
ctx.set("failed.exception", e1);
|
|
ctx.set("failed.filter", filter);
|
|
ctx.set("failed.filter", filter);
|
|
throw e1 ;
|
|
throw e1 ;
|