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
6960ff07
Commit
6960ff07
authored
Nov 20, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master-background-bug' into dev
parents
92bed955
d962307e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
6 deletions
+46
-6
GlobalExceptionHandler.java
...iaoqi/security/common/handler/GlobalExceptionHandler.java
+23
-4
PlatformExceptionHandler.java
...oqi/security/common/handler/PlatformExceptionHandler.java
+23
-2
No files found.
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/GlobalExceptionHandler.java
View file @
6960ff07
...
@@ -9,18 +9,23 @@ import com.github.wxiaoqi.security.common.msg.BaseResponse;
...
@@ -9,18 +9,23 @@ import com.github.wxiaoqi.security.common.msg.BaseResponse;
import
com.github.wxiaoqi.security.common.util.HttpUtils
;
import
com.github.wxiaoqi.security.common.util.HttpUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
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.context.request.WebRequest
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -33,7 +38,8 @@ import static org.springframework.http.HttpStatus.NOT_EXTENDED;
...
@@ -33,7 +38,8 @@ import static org.springframework.http.HttpStatus.NOT_EXTENDED;
@ResponseBody
@ResponseBody
public
class
GlobalExceptionHandler
extends
ResponseEntityExceptionHandler
{
public
class
GlobalExceptionHandler
extends
ResponseEntityExceptionHandler
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
GlobalExceptionHandler
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
GlobalExceptionHandler
.
class
);
@Value
(
"${spring.application.name}"
)
private
String
applicationName
;
/**
/**
* 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的
* 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的
*/
*/
...
@@ -74,7 +80,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
...
@@ -74,7 +80,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"content"
,
ex
.
getMessage
());
map
.
put
(
"content"
,
ex
.
toString
()
+
":"
+
ex
.
getMessage
());
try
{
try
{
HttpUtils
.
doPost
(
"http://10.5.52.3:8765"
,
"/api/universal/mail/app/unauth/send"
,
map
);
HttpUtils
.
doPost
(
"http://10.5.52.3:8765"
,
"/api/universal/mail/app/unauth/send"
,
map
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -95,7 +101,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
...
@@ -95,7 +101,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"content"
,
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
(
"http://10.5.52.3:8765"
,
"/api/universal/mail/app/unauth/send"
,
map
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -106,7 +112,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
...
@@ -106,7 +112,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"content"
,
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
(
"http://10.5.52.3:8765"
,
"/api/universal/mail/app/unauth/send"
,
map
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -114,4 +120,17 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
...
@@ -114,4 +120,17 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
}
}
return
new
BaseResponse
(
CommonConstants
.
EX_OTHER_CODE
,
ex
.
getMessage
());
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
();
}
}
}
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/PlatformExceptionHandler.java
View file @
6960ff07
...
@@ -7,17 +7,24 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
...
@@ -7,17 +7,24 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import
com.github.wxiaoqi.security.common.util.HttpUtils
;
import
com.github.wxiaoqi.security.common.util.HttpUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
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.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
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.PrintWriter
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
@RestControllerAdvice
(
"com.xxfc.platform"
)
@RestControllerAdvice
(
"com.xxfc.platform"
)
@Slf4j
@Slf4j
public
class
PlatformExceptionHandler
{
public
class
PlatformExceptionHandler
{
@Value
(
"${spring.application.name}"
)
private
String
applicationName
;
@ExceptionHandler
(
value
=
{
BaseException
.
class
})
@ExceptionHandler
(
value
=
{
BaseException
.
class
})
public
BaseResponse
baseExceptionHandler
(
Exception
e
)
{
public
BaseResponse
baseExceptionHandler
(
Exception
e
)
{
...
@@ -40,7 +47,7 @@ public class PlatformExceptionHandler {
...
@@ -40,7 +47,7 @@ public class PlatformExceptionHandler {
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"content"
,
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
(
"http://10.5.52.3:8765"
,
"/api/universal/mail/app/unauth/send"
,
map
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
...
@@ -52,7 +59,7 @@ public class PlatformExceptionHandler {
...
@@ -52,7 +59,7 @@ public class PlatformExceptionHandler {
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"toUser"
,
"jiaoruizhen@126.com"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"subject"
,
"服务器异常"
);
map
.
put
(
"content"
,
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
(
"http://10.5.52.3:8765"
,
"/api/universal/mail/app/unauth/send"
,
map
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
...
@@ -70,4 +77,18 @@ public class PlatformExceptionHandler {
...
@@ -70,4 +77,18 @@ public class PlatformExceptionHandler {
return
assembleResult
(
error
,
e
.
getClass
().
getSimpleName
()
+
": "
+
e
.
getMessage
());
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
();
}
}
}
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