Commit 74de1a65 authored by jiaorz's avatar jiaorz

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

parent ab9088ef
......@@ -40,6 +40,15 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Value("${spring.application.name}")
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方法不对啊之类的
*/
......@@ -77,15 +86,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
if(0 == ex.getStatus()) {
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());
}
......@@ -99,22 +99,22 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
cause.printStackTrace(new PrintWriter(stringWriter));
logger.error(cause.getMessage(), ex);
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
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) {
logger.error(e.getMessage());
}
return new BaseResponse(5000, "Server exception: " + ex.getMessage());
}
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" + ex.toString() + ":" + ex.getMessage());
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) {
logger.error(e.getMessage());
}
......
......@@ -26,6 +26,15 @@ public class PlatformExceptionHandler {
@Value("${spring.application.name}")
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})
public BaseResponse baseExceptionHandler(Exception e) {
if (e instanceof BaseException){
......@@ -45,11 +54,11 @@ public class PlatformExceptionHandler {
cause.printStackTrace(new PrintWriter(stringWriter));
log.error(cause.getMessage(), e);
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
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) {
log.error(ex.getMessage());
}
......@@ -57,11 +66,11 @@ public class PlatformExceptionHandler {
}
log.error("Server exception: ", e);
Map<String, String> map = new HashMap<>();
map.put("toUser", "jiaoruizhen@126.com");
map.put("subject", "服务器异常");
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" + e.toString() + ":" + e.getMessage());
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) {
log.error(ex.getMessage());
}
......@@ -83,7 +92,6 @@ public class PlatformExceptionHandler {
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());
......@@ -91,4 +99,5 @@ public class PlatformExceptionHandler {
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