Commit 6960ff07 authored by jiaorz's avatar jiaorz

Merge branch 'master-background-bug' into dev

parents 92bed955 d962307e
......@@ -9,18 +9,23 @@ import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.util.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
......@@ -33,7 +38,8 @@ import static org.springframework.http.HttpStatus.NOT_EXTENDED;
@ResponseBody
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Value("${spring.application.name}")
private String applicationName;
/**
* 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的
*/
......@@ -74,7 +80,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", ex.getMessage());
map.put("content", ex.toString() + ":" +ex.getMessage());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
......@@ -95,7 +101,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", stringWriter.toString());
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
......@@ -106,7 +112,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", ex.getMessage());
map.put("content", initCommonLogPrePart()+ ":" + ex.toString() + ":" + ex.getMessage());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
......@@ -114,4 +120,17 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
}
return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage());
}
public String initCommonLogPrePart() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();//获取request
StringBuilder stringBuilder = new StringBuilder();
//request 获得头部
stringBuilder.append(request.getHeader("app"));
LocalDateTime startTime= LocalDateTime.now();//开始时间
stringBuilder.append("》》" +startTime.toString());
stringBuilder.append("》》" +request.getServletPath());
stringBuilder.append("》》" +applicationName + ":" + request.getServletPath());
return stringBuilder.toString();
}
}
......@@ -7,17 +7,24 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
@RestControllerAdvice("com.xxfc.platform")
@Slf4j
public class PlatformExceptionHandler {
@Value("${spring.application.name}")
private String applicationName;
@ExceptionHandler(value = {BaseException.class})
public BaseResponse baseExceptionHandler(Exception e) {
......@@ -40,7 +47,7 @@ public class PlatformExceptionHandler {
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", stringWriter.toString());
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) {
......@@ -52,7 +59,7 @@ public class PlatformExceptionHandler {
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("content", e.getMessage());
map.put("content", initCommonLogPrePart()+ ":" + e.toString() + ":" + e.getMessage());
try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) {
......@@ -70,4 +77,18 @@ public class PlatformExceptionHandler {
return assembleResult(error, e.getClass().getSimpleName() + ": " + e.getMessage());
}
public String initCommonLogPrePart() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();//获取request
StringBuilder stringBuilder = new StringBuilder();
//request 获得头部
stringBuilder.append(request.getHeader("app"));
LocalDateTime startTime= LocalDateTime.now();//开始时间
stringBuilder.append("》》" +startTime.toString());
stringBuilder.append("》》" +request.getServletPath());
stringBuilder.append("》》" +applicationName + ":" + request.getServletPath());
return stringBuilder.toString();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment