1. 增加了WebSocket请求与异常调试控制台
This commit is contained in:
parent
35cf18019d
commit
d1d5c0f54d
@ -0,0 +1,76 @@
|
||||
package cn.com.tenlion.systemcard.filter;
|
||||
|
||||
import cn.com.tenlion.systemcard.socket.CardLogSocket;
|
||||
import ink.wgink.common.component.SecurityComponent;
|
||||
import ink.wgink.pojo.app.AppTokenUser;
|
||||
import ink.wgink.util.ReflectUtil;
|
||||
import ink.wgink.util.date.DateUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ControllerAdvice
|
||||
public class CardAppException {
|
||||
|
||||
@Autowired
|
||||
CardLogSocket cardLogSocket;
|
||||
|
||||
@Autowired
|
||||
protected SecurityComponent securityComponent;
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ModelAndView customException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) httpServletRequest;
|
||||
String token = httpRequest.getHeader("token");
|
||||
String url = httpRequest.getRequestURI();
|
||||
if(!url.contains("/app/")) {
|
||||
return null;
|
||||
}
|
||||
if(!StringUtils.isEmpty(token) && !StringUtils.isEmpty(cardLogSocket.selectUser)) {
|
||||
AppTokenUser appTokenUser = null;
|
||||
try {
|
||||
appTokenUser = securityComponent.getAppTokenUser(token);
|
||||
} catch (ReflectUtil.ReflectException e1) {
|
||||
}
|
||||
if(appTokenUser == null || !cardLogSocket.selectUser.equals(appTokenUser.getId())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 此方式支持form-data传参方式参数获取,其他传参方式请自行研究
|
||||
Map<String, String[]> parameterMap = httpRequest.getParameterMap();
|
||||
List<String> parameterList = new ArrayList<>();
|
||||
parameterMap.forEach((key, value) -> {
|
||||
parameterList.add(key + ":" + Arrays.toString(value));
|
||||
});
|
||||
String clientIp = httpRequest.getHeader("x-forwarded-for");
|
||||
if (clientIp == null) {
|
||||
clientIp = httpRequest.getRemoteAddr();
|
||||
}
|
||||
if(cardLogSocket.exceptionDescription) {
|
||||
StringWriter trace = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(trace));
|
||||
String log = "Exception:" + e.getMessage() + "\r\n" + trace.toString();
|
||||
cardLogSocket.sendAll(log);
|
||||
}else{
|
||||
String log = "Exception:" + e.getMessage();
|
||||
cardLogSocket.sendAll(log);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user