Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
b2077032
Commit
b2077032
authored
Mar 27, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加应用主题
parent
e2fed53f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
12 deletions
+9
-12
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/AccessLogFilter.java
...om/mortals/xhx/base/framework/filter/AccessLogFilter.java
+9
-12
No files found.
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/AccessLogFilter.java
View file @
b2077032
...
@@ -92,19 +92,21 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
...
@@ -92,19 +92,21 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
AccessLogPdu
accessLogPdu
=
new
AccessLogPdu
();
AccessLogPdu
accessLogPdu
=
new
AccessLogPdu
();
accessLogPdu
.
initAttrValue
();
accessLogPdu
.
initAttrValue
();
accessLogPdu
.
setAppName
(
appName
);
accessLogPdu
.
setAppName
(
appName
);
accessLogPdu
.
setTraceID
(
headers
.
getOrDefault
(
TRACE_ID
,
""
));
accessLogPdu
.
setTraceID
(
headers
.
getOrDefault
(
TRACE_ID
,
""
));
accessLogPdu
.
setPspanId
(
Integer
.
parseInt
(
headers
.
getOrDefault
(
PSPAN_ID
,
"0"
)));
accessLogPdu
.
setPspanId
(
Integer
.
parseInt
(
headers
.
getOrDefault
(
PSPAN_ID
,
"0"
)));
accessLogPdu
.
setSpanId
(
Integer
.
parseInt
(
headers
.
getOrDefault
(
SPAN_ID
,
"1"
)));
accessLogPdu
.
setSpanId
(
Integer
.
parseInt
(
headers
.
getOrDefault
(
SPAN_ID
,
"1"
)));
accessLogPdu
.
setSchemaData
(
request
.
getURI
().
getScheme
());
accessLogPdu
.
setSchemaData
(
request
.
getURI
().
getScheme
());
accessLogPdu
.
setHostName
(
NetUtil
.
getLocal
HostName
());
accessLogPdu
.
setHostName
(
request
.
getHeaders
().
getHost
().
get
HostName
());
accessLogPdu
.
setUri
(
requestPath
);
accessLogPdu
.
setUri
(
requestPath
);
accessLogPdu
.
setTargetServer
(
route
.
getId
());
accessLogPdu
.
setTargetServer
(
route
.
getId
());
accessLogPdu
.
setRequestIp
(
IpUtils
.
getRealIpAddress
(
exchange
.
getRequest
()));
accessLogPdu
.
setRequestIp
(
IpUtils
.
getRealIpAddress
(
exchange
.
getRequest
()));
accessLogPdu
.
setUa
(
headers
.
getOrDefault
(
"User-Agent"
,
""
));
accessLogPdu
.
setUa
(
headers
.
getOrDefault
(
"User-Agent"
,
""
));
accessLogPdu
.
setRequestTime
(
new
Date
());
accessLogPdu
.
setRequestTime
(
new
Date
());
accessLogPdu
.
setLogTime
(
new
Date
());
accessLogPdu
.
setLogTime
(
new
Date
());
accessLogPdu
.
setMethod
(
request
.
getMethodValue
());
accessLogPdu
.
setMethod
(
request
.
getMethodValue
());
log
.
info
(
"origin uri:{} host:{}"
,
requestPath
,
request
.
getHeaders
().
getHost
().
getHostName
());
MediaType
mediaType
=
request
.
getHeaders
().
getContentType
();
MediaType
mediaType
=
request
.
getHeaders
().
getContentType
();
if
(
MediaType
.
APPLICATION_FORM_URLENCODED
.
isCompatibleWith
(
mediaType
)
||
MediaType
.
APPLICATION_JSON
.
isCompatibleWith
(
mediaType
))
{
if
(
MediaType
.
APPLICATION_FORM_URLENCODED
.
isCompatibleWith
(
mediaType
)
||
MediaType
.
APPLICATION_JSON
.
isCompatibleWith
(
mediaType
))
{
return
writeBodyLog
(
exchange
,
chain
,
accessLogPdu
);
return
writeBodyLog
(
exchange
,
chain
,
accessLogPdu
);
...
@@ -161,12 +163,8 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
...
@@ -161,12 +163,8 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
BodyInserter
bodyInserter
=
BodyInserters
.
fromPublisher
(
modifiedBody
,
String
.
class
);
BodyInserter
bodyInserter
=
BodyInserters
.
fromPublisher
(
modifiedBody
,
String
.
class
);
HttpHeaders
headers
=
new
HttpHeaders
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
putAll
(
exchange
.
getRequest
().
getHeaders
());
headers
.
putAll
(
exchange
.
getRequest
().
getHeaders
());
// the new content type will be computed by bodyInserter
// and then set in the request decorator
headers
.
remove
(
HttpHeaders
.
CONTENT_LENGTH
);
headers
.
remove
(
HttpHeaders
.
CONTENT_LENGTH
);
CachedBodyOutputMessage
outputMessage
=
new
CachedBodyOutputMessage
(
exchange
,
headers
);
CachedBodyOutputMessage
outputMessage
=
new
CachedBodyOutputMessage
(
exchange
,
headers
);
return
bodyInserter
.
insert
(
outputMessage
,
new
BodyInserterContext
())
return
bodyInserter
.
insert
(
outputMessage
,
new
BodyInserterContext
())
.
then
(
Mono
.
defer
(()
->
{
.
then
(
Mono
.
defer
(()
->
{
// 重新封装请求
// 重新封装请求
...
@@ -183,7 +181,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
...
@@ -183,7 +181,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
}
}
private
void
writeAccessLog
(
AccessLogPdu
accessLogPdu
)
{
private
void
writeAccessLog
(
AccessLogPdu
accessLogPdu
)
{
// log.info("accessLog:{}",JSON.toJSONString(accessLogPdu));
// log.info("accessLog:{}",JSON.toJSONString(accessLogPdu));
messageProducer
.
syncAccessSend
(
accessLogPdu
);
messageProducer
.
syncAccessSend
(
accessLogPdu
);
}
}
...
@@ -234,7 +232,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
...
@@ -234,7 +232,6 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
private
ServerHttpResponseDecorator
recordResponseLog
(
ServerWebExchange
exchange
,
AccessLogPdu
accessLogPdu
)
{
private
ServerHttpResponseDecorator
recordResponseLog
(
ServerWebExchange
exchange
,
AccessLogPdu
accessLogPdu
)
{
ServerHttpResponse
response
=
exchange
.
getResponse
();
ServerHttpResponse
response
=
exchange
.
getResponse
();
DataBufferFactory
bufferFactory
=
response
.
bufferFactory
();
DataBufferFactory
bufferFactory
=
response
.
bufferFactory
();
return
new
ServerHttpResponseDecorator
(
response
)
{
return
new
ServerHttpResponseDecorator
(
response
)
{
@Override
@Override
public
Mono
<
Void
>
writeWith
(
Publisher
<?
extends
DataBuffer
>
body
)
{
public
Mono
<
Void
>
writeWith
(
Publisher
<?
extends
DataBuffer
>
body
)
{
...
@@ -264,7 +261,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
...
@@ -264,7 +261,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
//accessLogPdu.setResponseData(StrUtil.maxLength(responseResult,3000));
//accessLogPdu.setResponseData(StrUtil.maxLength(responseResult,3000));
return bufferFactory.wrap(content);
return bufferFactory.wrap(content);
}));*/
}));*/
}
else
{
}
else
{
accessLogPdu
.
setResponseData
(
JSON
.
toJSONString
(
Rest
.
fail
()));
accessLogPdu
.
setResponseData
(
JSON
.
toJSONString
(
Rest
.
fail
()));
}
}
}
}
...
...
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