Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
74de1a65
Commit
74de1a65
authored
Nov 27, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
邮件接受账号和标题配置,改为在配置文件中
parent
ab9088ef
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
23 deletions
+32
-23
GlobalExceptionHandler.java
...iaoqi/security/common/handler/GlobalExceptionHandler.java
+15
-15
PlatformExceptionHandler.java
...oqi/security/common/handler/PlatformExceptionHandler.java
+17
-8
No files found.
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/GlobalExceptionHandler.java
View file @
74de1a65
...
...
@@ -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
());
}
...
...
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/PlatformExceptionHandler.java
View file @
74de1a65
...
...
@@ -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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment