Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
YZG
yzg-util
Commits
97dd0710
Commit
97dd0710
authored
Aug 12, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常处理显示
parent
88b98773
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
19 deletions
+37
-19
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+33
-13
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+4
-6
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
97dd0710
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.alibaba.fastjson.JSON
;
import
com.yanzuoguang.cloud.CloudContans
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
...
...
@@ -91,17 +90,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
logInterVo
.
setLogSources
(
applicationName
);
//请求URL
logInterVo
.
setInterUrl
(
url
);
List
<
Object
>
para
=
new
ArrayList
<>();
for
(
Object
item
:
joinPoint
.
getArgs
())
{
if
(
item
instanceof
HttpServlet
||
item
instanceof
HttpServletResponse
||
item
instanceof
HttpServletRequest
)
{
continue
;
}
para
.
add
(
item
);
}
Object
paraTo
=
para
;
if
(
para
.
size
()
==
1
)
{
paraTo
=
para
.
get
(
0
);
}
Object
paraTo
=
getFirstDataParameter
(
joinPoint
.
getArgs
());
//请求参数
logInterVo
.
setContent
(
JSON
.
toJSONString
(
paraTo
));
//返回参数
...
...
@@ -110,6 +99,37 @@ public class BaseRequestAspect implements ThreadNext.Next {
return
logInterVo
;
}
/**
* 获取请求的参数
*
* @param args
* @return
*/
protected
Object
getFirstDataParameter
(
Object
[]
args
)
{
List
<
Object
>
para
=
getDataParameters
(
args
);
Object
paraTo
=
para
;
if
(
para
.
size
()
==
1
)
{
paraTo
=
para
.
get
(
0
);
}
return
paraTo
;
}
/**
* 获取数据参数
* @param args
* @return
*/
protected
List
<
Object
>
getDataParameters
(
Object
[]
args
)
{
List
<
Object
>
para
=
new
ArrayList
<>();
for
(
Object
item
:
args
)
{
if
(
item
instanceof
HttpServlet
||
item
instanceof
HttpServletResponse
||
item
instanceof
HttpServletRequest
)
{
continue
;
}
para
.
add
(
item
);
}
return
para
;
}
/**
* 获取JSON,当Json过长时,截断
*
...
...
@@ -147,7 +167,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
try
{
String
name
=
joinPoint
.
getSignature
().
getName
();
Log
.
info
(
joinPoint
.
getSignature
().
getDeclaringType
(),
" %s [ %s ] request: %s"
,
tag
,
name
,
this
.
getMaxString
(
JsonHelper
.
serialize
(
joinPoint
.
getArgs
(
))));
tag
,
name
,
this
.
getMaxString
(
JsonHelper
.
serialize
(
getFirstDataParameter
(
joinPoint
.
getArgs
()
))));
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
97dd0710
...
...
@@ -16,10 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Type
;
import
java.util.List
;
/**
* LogsAspect(接口请求日志切面)
...
...
@@ -148,9 +147,8 @@ public class WebAspect extends BaseRequestAspect {
* @throws Throwable
*/
private
Object
executeMethod
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
boolean
dataArgs
=
joinPoint
.
getArgs
().
length
!=
1
||
joinPoint
.
getArgs
().
length
==
1
&&
(
joinPoint
.
getArgs
()[
0
]
instanceof
ServletResponse
||
joinPoint
.
getArgs
()[
0
]
instanceof
ServletRequest
);
List
<
Object
>
dataParas
=
this
.
getDataParameters
(
joinPoint
.
getArgs
());
boolean
dataArgs
=
dataParas
.
isEmpty
();
Method
method
=
getMethod
(
joinPoint
);
boolean
isUrl
=
false
;
if
(!
StringHelper
.
isEmpty
(
reqUrl
))
{
...
...
@@ -166,7 +164,7 @@ public class WebAspect extends BaseRequestAspect {
return
joinPoint
.
proceed
();
}
else
{
// 获取请求编号
Object
firstArgs
=
joinPoint
.
getArgs
().
length
>
0
?
joinPoint
.
getArgs
()[
0
]
:
null
;
Object
firstArgs
=
dataParas
.
size
()
>
0
?
dataParas
.
get
(
0
)
:
null
;
String
reqId
=
StringHelper
.
md5
(
JsonHelper
.
serialize
(
firstArgs
));
String
reqFull
=
StringHelper
.
getId
(
reqId
,
HttpAspectUtil
.
getHttpRequestUrl
());
RequestCacheResult
req
=
cacheResult
.
get
(
reqFull
,
new
RequestCacheResult
(
reqFull
));
...
...
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