Commit 74de1a65 authored by jiaorz's avatar jiaorz

邮件接受账号和标题配置,改为在配置文件中

parent ab9088ef
...@@ -40,6 +40,15 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -40,6 +40,15 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Value("${spring.application.name}") @Value("${spring.application.name}")
private String applicationName; private String applicationName;
@Value("${email.log.account}")
private String emailLogAccount;
@Value("${email.log.title}")
private String emailLogTitle;
@Value("${email.log.host}")
private String emailLogHost;
/** /**
* 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的 * 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的
*/ */
...@@ -77,15 +86,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -77,15 +86,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
if(0 == ex.getStatus()) { if(0 == ex.getStatus()) {
response.setStatus(500); response.setStatus(500);
} }
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
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) {
logger.error(e.getMessage());
}
return new BaseResponse(ex.getStatus(), ex.getMessage()); return new BaseResponse(ex.getStatus(), ex.getMessage());
} }
...@@ -99,22 +99,22 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -99,22 +99,22 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
cause.printStackTrace(new PrintWriter(stringWriter)); cause.printStackTrace(new PrintWriter(stringWriter));
logger.error(cause.getMessage(), ex); logger.error(cause.getMessage(), ex);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com"); map.put("toUser", emailLogAccount);
map.put("subject", "服务器异常"); map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString()); map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try { try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map); HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
} }
return new BaseResponse(5000, "Server exception: " + ex.getMessage()); return new BaseResponse(5000, "Server exception: " + ex.getMessage());
} }
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com"); map.put("toUser", emailLogAccount);
map.put("subject", "服务器异常"); map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" + ex.toString() + ":" + ex.getMessage()); map.put("content", initCommonLogPrePart()+ ":" + ex.toString() + ":" + ex.getMessage());
try { try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map); HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
} }
......
...@@ -26,6 +26,15 @@ public class PlatformExceptionHandler { ...@@ -26,6 +26,15 @@ public class PlatformExceptionHandler {
@Value("${spring.application.name}") @Value("${spring.application.name}")
private String applicationName; private String applicationName;
@Value("${email.log.account}")
private String emailLogAccount;
@Value("${email.log.title}")
private String emailLogTitle;
@Value("${email.log.host}")
private String emailLogHost;
@ExceptionHandler(value = {BaseException.class}) @ExceptionHandler(value = {BaseException.class})
public BaseResponse baseExceptionHandler(Exception e) { public BaseResponse baseExceptionHandler(Exception e) {
if (e instanceof BaseException){ if (e instanceof BaseException){
...@@ -45,11 +54,11 @@ public class PlatformExceptionHandler { ...@@ -45,11 +54,11 @@ public class PlatformExceptionHandler {
cause.printStackTrace(new PrintWriter(stringWriter)); cause.printStackTrace(new PrintWriter(stringWriter));
log.error(cause.getMessage(), e); log.error(cause.getMessage(), e);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com"); map.put("toUser", emailLogAccount);
map.put("subject", "服务器异常"); map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString()); map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try { try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map); HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) { } catch (Exception ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
...@@ -57,11 +66,11 @@ public class PlatformExceptionHandler { ...@@ -57,11 +66,11 @@ public class PlatformExceptionHandler {
} }
log.error("Server exception: ", e); log.error("Server exception: ", e);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com"); map.put("toUser", emailLogAccount);
map.put("subject", "服务器异常"); map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" + e.toString() + ":" + e.getMessage()); map.put("content", initCommonLogPrePart()+ ":" + e.toString() + ":" + e.getMessage());
try { try {
HttpUtils.doPost("http://10.5.52.3:8765","/api/universal/mail/app/unauth/send", map); HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) { } catch (Exception ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
...@@ -83,7 +92,6 @@ public class PlatformExceptionHandler { ...@@ -83,7 +92,6 @@ public class PlatformExceptionHandler {
HttpServletRequest request = servletRequestAttributes.getRequest();//获取request HttpServletRequest request = servletRequestAttributes.getRequest();//获取request
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
//request 获得头部 //request 获得头部
stringBuilder.append(request.getHeader("app"));
LocalDateTime startTime= LocalDateTime.now();//开始时间 LocalDateTime startTime= LocalDateTime.now();//开始时间
stringBuilder.append("》》" +startTime.toString()); stringBuilder.append("》》" +startTime.toString());
stringBuilder.append("》》" +request.getServletPath()); stringBuilder.append("》》" +request.getServletPath());
...@@ -91,4 +99,5 @@ public class PlatformExceptionHandler { ...@@ -91,4 +99,5 @@ public class PlatformExceptionHandler {
return stringBuilder.toString(); 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