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
db8a61d7
Commit
db8a61d7
authored
Aug 19, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改网关日志
parent
356c858d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1363 additions
and
549 deletions
+1363
-549
common-lib/src/main/java/com/mortals/xhx/common/pdu/access/AccessLogPdu.java
.../java/com/mortals/xhx/common/pdu/access/AccessLogPdu.java
+1022
-510
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/AccessLogFilter.java
...om/mortals/xhx/base/framework/filter/AccessLogFilter.java
+296
-0
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GatewayResponseFilter.java
...tals/xhx/base/framework/filter/GatewayResponseFilter.java
+1
-1
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalCacheRequestFilter.java
...s/xhx/base/framework/filter/GlobalCacheRequestFilter.java
+2
-2
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalLogFilter.java
...om/mortals/xhx/base/framework/filter/GlobalLogFilter.java
+42
-36
No files found.
common-lib/src/main/java/com/mortals/xhx/common/pdu/access/AccessLogPdu.java
View file @
db8a61d7
package
com.mortals.xhx.common.pdu.access
;
import
com.mortals.framework.model.BaseEntityLong
;
import
java.util.Date
;
import
java.util.List
;
import
com.mortals.framework.model.BaseEntityLong
;
/**
* 访问日志Pdu对象
*
* @author zxfei
* @date 2022-08-17
*/
* 访问日志Pdu对象
*
* @author zxfei
* @date 2022-08-19
*/
public
class
AccessLogPdu
extends
BaseEntityLong
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 追踪
Id
* Trace
Id
*/
private
String
traceID
;
/**
* 父服务调用id
*/
private
Integer
pspanId
;
/**
* 当前服务跨度Id
*/
private
Integer
spanId
;
/**
* 应用名称
*/
...
...
@@ -27,6 +33,10 @@ public class AccessLogPdu extends BaseEntityLong {
* 实例IP
*/
private
String
hostName
;
/**
* 目标服务
*/
private
String
targetServer
;
/**
* 日志等级
*/
...
...
@@ -39,6 +49,10 @@ public class AccessLogPdu extends BaseEntityLong {
* 请求方式
*/
private
String
method
;
/**
* 协议
*/
private
String
schema
;
/**
* 用户浏览器UA
*/
...
...
@@ -50,41 +64,76 @@ public class AccessLogPdu extends BaseEntityLong {
/**
* 请求参数,json序列化
*/
private
String
request
Param
;
private
String
request
Data
;
/**
* 响应结果
* 响应结果,
*/
private
String
response
;
private
String
response
Data
;
/**
* 日志产生时间
*/
private
Date
logTime
;
/**
* 请求时间
*/
private
Date
requestTime
;
/**
* 响应时间
*/
private
Date
responseTime
;
/**
* 持续时间,单位毫秒
*/
private
Integer
duration
;
private
Long
duration
;
/** 开始 主键ID
,主键,自增长
*/
/** 开始 主键ID */
private
Long
idStart
;
/** 结束 主键ID
,主键,自增长
*/
/** 结束 主键ID */
private
Long
idEnd
;
/** 增加 主键ID
,主键,自增长
*/
/** 增加 主键ID */
private
Long
idIncrement
;
/** 主键ID
,主键,自增长
列表 */
/** 主键ID列表 */
private
List
<
Long
>
idList
;
/**
追踪
Id */
/**
Trace
Id */
private
List
<
String
>
traceIDList
;
/** 开始 父服务调用id */
private
Integer
pspanIdStart
;
/** 结束 父服务调用id */
private
Integer
pspanIdEnd
;
/** 增加 父服务调用id */
private
Integer
pspanIdIncrement
;
/** 父服务调用id列表 */
private
List
<
Integer
>
pspanIdList
;
/** 开始 当前服务跨度Id */
private
Integer
spanIdStart
;
/** 结束 当前服务跨度Id */
private
Integer
spanIdEnd
;
/** 增加 当前服务跨度Id */
private
Integer
spanIdIncrement
;
/** 当前服务跨度Id列表 */
private
List
<
Integer
>
spanIdList
;
/** 应用名称 */
private
List
<
String
>
appNameList
;
/** 实例IP */
private
List
<
String
>
hostNameList
;
/** 目标服务 */
private
List
<
String
>
targetServerList
;
/** 日志等级 */
private
List
<
String
>
logLevelList
;
...
...
@@ -94,6 +143,9 @@ public class AccessLogPdu extends BaseEntityLong {
/** 请求方式 */
private
List
<
String
>
methodList
;
/** 协议 */
private
List
<
String
>
schemaList
;
/** 用户浏览器UA */
private
List
<
String
>
uaList
;
...
...
@@ -101,10 +153,10 @@ public class AccessLogPdu extends BaseEntityLong {
private
List
<
String
>
uriList
;
/** 请求参数,json序列化 */
private
List
<
String
>
request
Param
List
;
private
List
<
String
>
request
Data
List
;
/** 响应结果 */
private
List
<
String
>
responseList
;
/** 响应结果
,
*/
private
List
<
String
>
response
Data
List
;
/** 开始 日志产生时间 */
private
String
logTimeStart
;
...
...
@@ -112,17 +164,29 @@ public class AccessLogPdu extends BaseEntityLong {
/** 结束 日志产生时间 */
private
String
logTimeEnd
;
/** 开始 请求时间 */
private
String
requestTimeStart
;
/** 结束 请求时间 */
private
String
requestTimeEnd
;
/** 开始 响应时间 */
private
String
responseTimeStart
;
/** 结束 响应时间 */
private
String
responseTimeEnd
;
/** 开始 持续时间,单位毫秒 */
private
Integer
durationStart
;
private
Long
durationStart
;
/** 结束 持续时间,单位毫秒 */
private
Integer
durationEnd
;
private
Long
durationEnd
;
/** 增加 持续时间,单位毫秒 */
private
Integer
durationIncrement
;
private
Long
durationIncrement
;
/** 持续时间,单位毫秒列表 */
private
List
<
Integer
>
durationList
;
private
List
<
Long
>
durationList
;
/** 开始 创建用户 */
private
Long
createUserIdStart
;
...
...
@@ -151,19 +215,47 @@ public class AccessLogPdu extends BaseEntityLong {
public
AccessLogPdu
(){}
/**
* 获取 追踪
Id
* 获取 Trace
Id
* @return String
*/
public
String
getTraceID
(){
return
traceID
;
}
/**
* 设置 追踪
Id
* 设置 Trace
Id
* @param traceID
*/
public
void
setTraceID
(
String
traceID
){
this
.
traceID
=
traceID
;
}
/**
* 获取 父服务调用id
* @return Integer
*/
public
Integer
getPspanId
(){
return
pspanId
;
}
/**
* 设置 父服务调用id
* @param pspanId
*/
public
void
setPspanId
(
Integer
pspanId
){
this
.
pspanId
=
pspanId
;
}
/**
* 获取 当前服务跨度Id
* @return Integer
*/
public
Integer
getSpanId
(){
return
spanId
;
}
/**
* 设置 当前服务跨度Id
* @param spanId
*/
public
void
setSpanId
(
Integer
spanId
){
this
.
spanId
=
spanId
;
}
/**
* 获取 应用名称
* @return String
...
...
@@ -192,6 +284,20 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setHostName
(
String
hostName
){
this
.
hostName
=
hostName
;
}
/**
* 获取 目标服务
* @return String
*/
public
String
getTargetServer
(){
return
targetServer
;
}
/**
* 设置 目标服务
* @param targetServer
*/
public
void
setTargetServer
(
String
targetServer
){
this
.
targetServer
=
targetServer
;
}
/**
* 获取 日志等级
* @return String
...
...
@@ -234,6 +340,20 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setMethod
(
String
method
){
this
.
method
=
method
;
}
/**
* 获取 协议
* @return String
*/
public
String
getSchema
(){
return
schema
;
}
/**
* 设置 协议
* @param schema
*/
public
void
setSchema
(
String
schema
){
this
.
schema
=
schema
;
}
/**
* 获取 用户浏览器UA
* @return String
...
...
@@ -266,29 +386,29 @@ public class AccessLogPdu extends BaseEntityLong {
* 获取 请求参数,json序列化
* @return String
*/
public
String
getRequest
Param
(){
return
request
Param
;
public
String
getRequest
Data
(){
return
request
Data
;
}
/**
* 设置 请求参数,json序列化
* @param requestParam
* @param requestData
*/
public
void
setRequest
Param
(
String
requestParam
){
this
.
request
Param
=
requestParam
;
public
void
setRequest
Data
(
String
requestData
){
this
.
request
Data
=
requestData
;
}
/**
* 获取 响应结果
* 获取 响应结果,
* @return String
*/
public
String
getResponse
(){
return
response
;
public
String
getResponse
Data
(){
return
response
Data
;
}
/**
* 设置 响应结果
* @param response
* 设置 响应结果,
* @param responseData
*/
public
void
setResponse
(
String
response
){
this
.
response
=
response
;
public
void
setResponse
Data
(
String
responseData
){
this
.
response
Data
=
responseData
;
}
/**
* 获取 日志产生时间
...
...
@@ -304,23 +424,51 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setLogTime
(
Date
logTime
){
this
.
logTime
=
logTime
;
}
/**
* 获取 请求时间
* @return Date
*/
public
Date
getRequestTime
(){
return
requestTime
;
}
/**
* 设置 请求时间
* @param requestTime
*/
public
void
setRequestTime
(
Date
requestTime
){
this
.
requestTime
=
requestTime
;
}
/**
* 获取 响应时间
* @return Date
*/
public
Date
getResponseTime
(){
return
responseTime
;
}
/**
* 设置 响应时间
* @param responseTime
*/
public
void
setResponseTime
(
Date
responseTime
){
this
.
responseTime
=
responseTime
;
}
/**
* 获取 持续时间,单位毫秒
* @return Integer
* @return Long
*/
public
Integer
getDuration
(){
public
Long
getDuration
(){
return
duration
;
}
/**
* 设置 持续时间,单位毫秒
* @param duration
*/
public
void
setDuration
(
Integer
duration
){
public
void
setDuration
(
Long
duration
){
this
.
duration
=
duration
;
}
/**
* 获取 开始 主键ID,主键,自增长
* 获取 开始 主键ID
* @return idStart
*/
public
Long
getIdStart
(){
...
...
@@ -328,7 +476,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 开始 主键ID,主键,自增长
* 设置 开始 主键ID
* @param idStart
*/
public
void
setIdStart
(
Long
idStart
){
...
...
@@ -336,7 +484,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 获取 结束 主键ID,主键,自增长
* 获取 结束 主键ID
* @return $idEnd
*/
public
Long
getIdEnd
(){
...
...
@@ -344,7 +492,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 结束 主键ID,主键,自增长
* 设置 结束 主键ID
* @param idEnd
*/
public
void
setIdEnd
(
Long
idEnd
){
...
...
@@ -352,7 +500,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 获取 增加 主键ID,主键,自增长
* 获取 增加 主键ID
* @return idIncrement
*/
public
Long
getIdIncrement
(){
...
...
@@ -360,7 +508,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 增加 主键ID,主键,自增长
* 设置 增加 主键ID
* @param idIncrement
*/
public
void
setIdIncrement
(
Long
idIncrement
){
...
...
@@ -368,7 +516,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 获取 主键ID,主键,自增长
* 获取 主键ID
* @return idList
*/
public
List
<
Long
>
getIdList
(){
...
...
@@ -376,7 +524,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 主键ID,主键,自增长
* 设置 主键ID
* @param idList
*/
public
void
setIdList
(
List
<
Long
>
idList
){
...
...
@@ -384,7 +532,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 获取 追踪
Id
* 获取 Trace
Id
* @return traceIDList
*/
public
List
<
String
>
getTraceIDList
(){
...
...
@@ -392,12 +540,140 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 追踪
Id
* 设置 Trace
Id
* @param traceIDList
*/
public
void
setTraceIDList
(
List
<
String
>
traceIDList
){
this
.
traceIDList
=
traceIDList
;
}
/**
* 获取 开始 父服务调用id
* @return pspanIdStart
*/
public
Integer
getPspanIdStart
(){
return
this
.
pspanIdStart
;
}
/**
* 设置 开始 父服务调用id
* @param pspanIdStart
*/
public
void
setPspanIdStart
(
Integer
pspanIdStart
){
this
.
pspanIdStart
=
pspanIdStart
;
}
/**
* 获取 结束 父服务调用id
* @return $pspanIdEnd
*/
public
Integer
getPspanIdEnd
(){
return
this
.
pspanIdEnd
;
}
/**
* 设置 结束 父服务调用id
* @param pspanIdEnd
*/
public
void
setPspanIdEnd
(
Integer
pspanIdEnd
){
this
.
pspanIdEnd
=
pspanIdEnd
;
}
/**
* 获取 增加 父服务调用id
* @return pspanIdIncrement
*/
public
Integer
getPspanIdIncrement
(){
return
this
.
pspanIdIncrement
;
}
/**
* 设置 增加 父服务调用id
* @param pspanIdIncrement
*/
public
void
setPspanIdIncrement
(
Integer
pspanIdIncrement
){
this
.
pspanIdIncrement
=
pspanIdIncrement
;
}
/**
* 获取 父服务调用id
* @return pspanIdList
*/
public
List
<
Integer
>
getPspanIdList
(){
return
this
.
pspanIdList
;
}
/**
* 设置 父服务调用id
* @param pspanIdList
*/
public
void
setPspanIdList
(
List
<
Integer
>
pspanIdList
){
this
.
pspanIdList
=
pspanIdList
;
}
/**
* 获取 开始 当前服务跨度Id
* @return spanIdStart
*/
public
Integer
getSpanIdStart
(){
return
this
.
spanIdStart
;
}
/**
* 设置 开始 当前服务跨度Id
* @param spanIdStart
*/
public
void
setSpanIdStart
(
Integer
spanIdStart
){
this
.
spanIdStart
=
spanIdStart
;
}
/**
* 获取 结束 当前服务跨度Id
* @return $spanIdEnd
*/
public
Integer
getSpanIdEnd
(){
return
this
.
spanIdEnd
;
}
/**
* 设置 结束 当前服务跨度Id
* @param spanIdEnd
*/
public
void
setSpanIdEnd
(
Integer
spanIdEnd
){
this
.
spanIdEnd
=
spanIdEnd
;
}
/**
* 获取 增加 当前服务跨度Id
* @return spanIdIncrement
*/
public
Integer
getSpanIdIncrement
(){
return
this
.
spanIdIncrement
;
}
/**
* 设置 增加 当前服务跨度Id
* @param spanIdIncrement
*/
public
void
setSpanIdIncrement
(
Integer
spanIdIncrement
){
this
.
spanIdIncrement
=
spanIdIncrement
;
}
/**
* 获取 当前服务跨度Id
* @return spanIdList
*/
public
List
<
Integer
>
getSpanIdList
(){
return
this
.
spanIdList
;
}
/**
* 设置 当前服务跨度Id
* @param spanIdList
*/
public
void
setSpanIdList
(
List
<
Integer
>
spanIdList
){
this
.
spanIdList
=
spanIdList
;
}
/**
* 获取 应用名称
* @return appNameList
...
...
@@ -428,6 +704,21 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setHostNameList
(
List
<
String
>
hostNameList
){
this
.
hostNameList
=
hostNameList
;
}
/**
* 获取 目标服务
* @return targetServerList
*/
public
List
<
String
>
getTargetServerList
(){
return
this
.
targetServerList
;
}
/**
* 设置 目标服务
* @param targetServerList
*/
public
void
setTargetServerList
(
List
<
String
>
targetServerList
){
this
.
targetServerList
=
targetServerList
;
}
/**
* 获取 日志等级
* @return logLevelList
...
...
@@ -473,6 +764,21 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setMethodList
(
List
<
String
>
methodList
){
this
.
methodList
=
methodList
;
}
/**
* 获取 协议
* @return schemaList
*/
public
List
<
String
>
getSchemaList
(){
return
this
.
schemaList
;
}
/**
* 设置 协议
* @param schemaList
*/
public
void
setSchemaList
(
List
<
String
>
schemaList
){
this
.
schemaList
=
schemaList
;
}
/**
* 获取 用户浏览器UA
* @return uaList
...
...
@@ -505,33 +811,33 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 获取 请求参数,json序列化
* @return requestParam
List
* @return requestData
List
*/
public
List
<
String
>
getRequest
Param
List
(){
return
this
.
request
Param
List
;
public
List
<
String
>
getRequest
Data
List
(){
return
this
.
request
Data
List
;
}
/**
* 设置 请求参数,json序列化
* @param requestParam
List
* @param requestData
List
*/
public
void
setRequest
ParamList
(
List
<
String
>
requestParam
List
){
this
.
request
ParamList
=
requestParam
List
;
public
void
setRequest
DataList
(
List
<
String
>
requestData
List
){
this
.
request
DataList
=
requestData
List
;
}
/**
* 获取 响应结果
* @return response
List
* 获取 响应结果,
* @return responseData
List
*/
public
List
<
String
>
getResponseList
(){
return
this
.
responseList
;
public
List
<
String
>
getResponse
Data
List
(){
return
this
.
response
Data
List
;
}
/**
* 设置 响应结果
* @param response
List
* 设置 响应结果,
* @param responseData
List
*/
public
void
setResponse
List
(
List
<
String
>
response
List
){
this
.
response
List
=
response
List
;
public
void
setResponse
DataList
(
List
<
String
>
responseData
List
){
this
.
response
DataList
=
responseData
List
;
}
/**
* 获取 开始 日志产生时间
...
...
@@ -565,11 +871,75 @@ public class AccessLogPdu extends BaseEntityLong {
this
.
logTimeEnd
=
logTimeEnd
;
}
/**
* 获取 开始 请求时间
* @return requestTimeStart
*/
public
String
getRequestTimeStart
(){
return
this
.
requestTimeStart
;
}
/**
* 设置 开始 请求时间
* @param requestTimeStart
*/
public
void
setRequestTimeStart
(
String
requestTimeStart
){
this
.
requestTimeStart
=
requestTimeStart
;
}
/**
* 获取 结束 请求时间
* @return requestTimeEnd
*/
public
String
getRequestTimeEnd
(){
return
this
.
requestTimeEnd
;
}
/**
* 设置 结束 请求时间
* @param requestTimeEnd
*/
public
void
setRequestTimeEnd
(
String
requestTimeEnd
){
this
.
requestTimeEnd
=
requestTimeEnd
;
}
/**
* 获取 开始 响应时间
* @return responseTimeStart
*/
public
String
getResponseTimeStart
(){
return
this
.
responseTimeStart
;
}
/**
* 设置 开始 响应时间
* @param responseTimeStart
*/
public
void
setResponseTimeStart
(
String
responseTimeStart
){
this
.
responseTimeStart
=
responseTimeStart
;
}
/**
* 获取 结束 响应时间
* @return responseTimeEnd
*/
public
String
getResponseTimeEnd
(){
return
this
.
responseTimeEnd
;
}
/**
* 设置 结束 响应时间
* @param responseTimeEnd
*/
public
void
setResponseTimeEnd
(
String
responseTimeEnd
){
this
.
responseTimeEnd
=
responseTimeEnd
;
}
/**
* 获取 开始 持续时间,单位毫秒
* @return durationStart
*/
public
Integer
getDurationStart
(){
public
Long
getDurationStart
(){
return
this
.
durationStart
;
}
...
...
@@ -577,7 +947,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 开始 持续时间,单位毫秒
* @param durationStart
*/
public
void
setDurationStart
(
Integer
durationStart
){
public
void
setDurationStart
(
Long
durationStart
){
this
.
durationStart
=
durationStart
;
}
...
...
@@ -585,7 +955,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 获取 结束 持续时间,单位毫秒
* @return $durationEnd
*/
public
Integer
getDurationEnd
(){
public
Long
getDurationEnd
(){
return
this
.
durationEnd
;
}
...
...
@@ -593,7 +963,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 结束 持续时间,单位毫秒
* @param durationEnd
*/
public
void
setDurationEnd
(
Integer
durationEnd
){
public
void
setDurationEnd
(
Long
durationEnd
){
this
.
durationEnd
=
durationEnd
;
}
...
...
@@ -601,7 +971,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 获取 增加 持续时间,单位毫秒
* @return durationIncrement
*/
public
Integer
getDurationIncrement
(){
public
Long
getDurationIncrement
(){
return
this
.
durationIncrement
;
}
...
...
@@ -609,7 +979,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 增加 持续时间,单位毫秒
* @param durationIncrement
*/
public
void
setDurationIncrement
(
Integer
durationIncrement
){
public
void
setDurationIncrement
(
Long
durationIncrement
){
this
.
durationIncrement
=
durationIncrement
;
}
...
...
@@ -617,7 +987,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 获取 持续时间,单位毫秒
* @return durationList
*/
public
List
<
Integer
>
getDurationList
(){
public
List
<
Long
>
getDurationList
(){
return
this
.
durationList
;
}
...
...
@@ -625,7 +995,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 持续时间,单位毫秒
* @param durationList
*/
public
void
setDurationList
(
List
<
Integer
>
durationList
){
public
void
setDurationList
(
List
<
Long
>
durationList
){
this
.
durationList
=
durationList
;
}
...
...
@@ -726,7 +1096,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 主键ID,主键,自增长
* 设置 主键ID
* @param id
*/
public
AccessLogPdu
id
(
Long
id
){
...
...
@@ -735,7 +1105,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 开始 主键ID,主键,自增长
* 设置 开始 主键ID
* @param idStart
*/
public
AccessLogPdu
idStart
(
Long
idStart
){
...
...
@@ -744,7 +1114,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 结束 主键ID,主键,自增长
* 设置 结束 主键ID
* @param idEnd
*/
public
AccessLogPdu
idEnd
(
Long
idEnd
){
...
...
@@ -753,7 +1123,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 增加 主键ID,主键,自增长
* 设置 增加 主键ID
* @param idIncrement
*/
public
AccessLogPdu
idIncrement
(
Long
idIncrement
){
...
...
@@ -762,7 +1132,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 主键ID,主键,自增长
* 设置 主键ID
* @param idList
*/
public
AccessLogPdu
idList
(
List
<
Long
>
idList
){
...
...
@@ -772,7 +1142,7 @@ public class AccessLogPdu extends BaseEntityLong {
/**
* 设置 追踪
Id
* 设置 Trace
Id
* @param traceID
*/
public
AccessLogPdu
traceID
(
String
traceID
){
...
...
@@ -781,7 +1151,7 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 追踪
Id
* 设置 Trace
Id
* @param traceIDList
*/
public
AccessLogPdu
traceIDList
(
List
<
String
>
traceIDList
){
...
...
@@ -789,6 +1159,96 @@ public class AccessLogPdu extends BaseEntityLong {
return
this
;
}
/**
* 设置 父服务调用id
* @param pspanId
*/
public
AccessLogPdu
pspanId
(
Integer
pspanId
){
setPspanId
(
pspanId
);
return
this
;
}
/**
* 设置 开始 父服务调用id
* @param pspanIdStart
*/
public
AccessLogPdu
pspanIdStart
(
Integer
pspanIdStart
){
this
.
pspanIdStart
=
pspanIdStart
;
return
this
;
}
/**
* 设置 结束 父服务调用id
* @param pspanIdEnd
*/
public
AccessLogPdu
pspanIdEnd
(
Integer
pspanIdEnd
){
this
.
pspanIdEnd
=
pspanIdEnd
;
return
this
;
}
/**
* 设置 增加 父服务调用id
* @param pspanIdIncrement
*/
public
AccessLogPdu
pspanIdIncrement
(
Integer
pspanIdIncrement
){
this
.
pspanIdIncrement
=
pspanIdIncrement
;
return
this
;
}
/**
* 设置 父服务调用id
* @param pspanIdList
*/
public
AccessLogPdu
pspanIdList
(
List
<
Integer
>
pspanIdList
){
this
.
pspanIdList
=
pspanIdList
;
return
this
;
}
/**
* 设置 当前服务跨度Id
* @param spanId
*/
public
AccessLogPdu
spanId
(
Integer
spanId
){
setSpanId
(
spanId
);
return
this
;
}
/**
* 设置 开始 当前服务跨度Id
* @param spanIdStart
*/
public
AccessLogPdu
spanIdStart
(
Integer
spanIdStart
){
this
.
spanIdStart
=
spanIdStart
;
return
this
;
}
/**
* 设置 结束 当前服务跨度Id
* @param spanIdEnd
*/
public
AccessLogPdu
spanIdEnd
(
Integer
spanIdEnd
){
this
.
spanIdEnd
=
spanIdEnd
;
return
this
;
}
/**
* 设置 增加 当前服务跨度Id
* @param spanIdIncrement
*/
public
AccessLogPdu
spanIdIncrement
(
Integer
spanIdIncrement
){
this
.
spanIdIncrement
=
spanIdIncrement
;
return
this
;
}
/**
* 设置 当前服务跨度Id
* @param spanIdList
*/
public
AccessLogPdu
spanIdList
(
List
<
Integer
>
spanIdList
){
this
.
spanIdList
=
spanIdList
;
return
this
;
}
/**
* 设置 应用名称
...
...
@@ -828,6 +1288,25 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 目标服务
* @param targetServer
*/
public
AccessLogPdu
targetServer
(
String
targetServer
){
setTargetServer
(
targetServer
);
return
this
;
}
/**
* 设置 目标服务
* @param targetServerList
*/
public
AccessLogPdu
targetServerList
(
List
<
String
>
targetServerList
){
this
.
targetServerList
=
targetServerList
;
return
this
;
}
/**
* 设置 日志等级
* @param logLevel
...
...
@@ -885,6 +1364,25 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 协议
* @param schema
*/
public
AccessLogPdu
schema
(
String
schema
){
setSchema
(
schema
);
return
this
;
}
/**
* 设置 协议
* @param schemaList
*/
public
AccessLogPdu
schemaList
(
List
<
String
>
schemaList
){
this
.
schemaList
=
schemaList
;
return
this
;
}
/**
* 设置 用户浏览器UA
* @param ua
...
...
@@ -925,47 +1423,49 @@ public class AccessLogPdu extends BaseEntityLong {
/**
* 设置 请求参数,json序列化
* @param requestParam
* @param requestData
*/
public
AccessLogPdu
request
Param
(
String
requestParam
){
setRequest
Param
(
requestParam
);
public
AccessLogPdu
request
Data
(
String
requestData
){
setRequest
Data
(
requestData
);
return
this
;
}
/**
* 设置 请求参数,json序列化
* @param requestParam
List
* @param requestData
List
*/
public
AccessLogPdu
request
ParamList
(
List
<
String
>
requestParam
List
){
this
.
request
ParamList
=
requestParam
List
;
public
AccessLogPdu
request
DataList
(
List
<
String
>
requestData
List
){
this
.
request
DataList
=
requestData
List
;
return
this
;
}
/**
* 设置 响应结果
* @param response
* 设置 响应结果,
* @param responseData
*/
public
AccessLogPdu
response
(
String
response
){
setResponse
(
response
);
public
AccessLogPdu
response
Data
(
String
responseData
){
setResponse
Data
(
responseData
);
return
this
;
}
/**
* 设置 响应结果
* @param response
List
* 设置 响应结果,
* @param responseData
List
*/
public
AccessLogPdu
response
List
(
List
<
String
>
response
List
){
this
.
response
List
=
response
List
;
public
AccessLogPdu
response
DataList
(
List
<
String
>
responseData
List
){
this
.
response
DataList
=
responseData
List
;
return
this
;
}
/**
* 设置 持续时间,单位毫秒
* @param duration
*/
public
AccessLogPdu
duration
(
Integer
duration
){
public
AccessLogPdu
duration
(
Long
duration
){
setDuration
(
duration
);
return
this
;
}
...
...
@@ -974,7 +1474,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 开始 持续时间,单位毫秒
* @param durationStart
*/
public
AccessLogPdu
durationStart
(
Integer
durationStart
){
public
AccessLogPdu
durationStart
(
Long
durationStart
){
this
.
durationStart
=
durationStart
;
return
this
;
}
...
...
@@ -983,7 +1483,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 结束 持续时间,单位毫秒
* @param durationEnd
*/
public
AccessLogPdu
durationEnd
(
Integer
durationEnd
){
public
AccessLogPdu
durationEnd
(
Long
durationEnd
){
this
.
durationEnd
=
durationEnd
;
return
this
;
}
...
...
@@ -992,7 +1492,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 增加 持续时间,单位毫秒
* @param durationIncrement
*/
public
AccessLogPdu
durationIncrement
(
Integer
durationIncrement
){
public
AccessLogPdu
durationIncrement
(
Long
durationIncrement
){
this
.
durationIncrement
=
durationIncrement
;
return
this
;
}
...
...
@@ -1001,7 +1501,7 @@ public class AccessLogPdu extends BaseEntityLong {
* 设置 持续时间,单位毫秒
* @param durationList
*/
public
AccessLogPdu
durationList
(
List
<
Integer
>
durationList
){
public
AccessLogPdu
durationList
(
List
<
Long
>
durationList
){
this
.
durationList
=
durationList
;
return
this
;
}
...
...
@@ -1053,7 +1553,7 @@ public class AccessLogPdu extends BaseEntityLong {
/**
/**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList
*/
...
...
@@ -1105,26 +1605,38 @@ public class AccessLogPdu extends BaseEntityLong {
this
.
traceID
=
""
;
this
.
pspanId
=
0
;
this
.
spanId
=
null
;
this
.
appName
=
""
;
this
.
hostName
=
""
;
this
.
logLevel
=
""
;
this
.
targetServer
=
""
;
this
.
logLevel
=
"INFO"
;
this
.
requestIp
=
""
;
this
.
method
=
""
;
this
.
schema
=
"http"
;
this
.
ua
=
""
;
this
.
uri
=
""
;
this
.
requestParam
=
""
;
this
.
requestData
=
""
;
this
.
response
=
""
;
this
.
responseData
=
""
;
this
.
logTime
=
null
;
this
.
requestTime
=
null
;
this
.
responseTime
=
null
;
this
.
duration
=
null
;
}
}
\ No newline at end of file
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/AccessLogFilter.java
0 → 100644
View file @
db8a61d7
package
com.mortals.xhx.base.framework.filter
;
import
cn.hutool.core.net.NetUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.xhx.base.framework.service.MessageProducer
;
import
com.mortals.xhx.common.pdu.access.AccessLogPdu
;
import
com.mortals.xhx.common.utils.IpUtils
;
import
jodd.util.StringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.reactivestreams.Publisher
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage
;
import
org.springframework.cloud.gateway.route.Route
;
import
org.springframework.cloud.gateway.support.BodyInserterContext
;
import
org.springframework.cloud.gateway.support.ServerWebExchangeUtils
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.io.buffer.DataBuffer
;
import
org.springframework.core.io.buffer.DataBufferFactory
;
import
org.springframework.core.io.buffer.DataBufferUtils
;
import
org.springframework.core.io.buffer.DefaultDataBufferFactory
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.codec.HttpMessageReader
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.http.server.reactive.ServerHttpRequestDecorator
;
import
org.springframework.http.server.reactive.ServerHttpResponse
;
import
org.springframework.http.server.reactive.ServerHttpResponseDecorator
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.reactive.function.BodyInserter
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
org.springframework.web.reactive.function.server.HandlerStrategies
;
import
org.springframework.web.reactive.function.server.ServerRequest
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.util.WebUtils
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author: zxfei
* @date: 2022/8/18 23:52
* @description:
**/
@Slf4j
@Component
public
class
AccessLogFilter
implements
GlobalFilter
,
Ordered
{
// @Autowired
// private AccessLogService accessLogService;
@Value
(
"${spring.application.name:gateway}"
)
private
String
appName
;
@Autowired
private
MessageProducer
messageProducer
;
private
static
final
String
TRACE_ID
=
"traceId"
;
private
static
final
String
SPAN_ID
=
"spanId"
;
private
static
final
String
PSPAN_ID
=
"pspanId"
;
private
final
List
<
HttpMessageReader
<?>>
messageReaders
=
HandlerStrategies
.
withDefaults
().
messageReaders
();
/**
* 顺序必须是<-1,否则标准的NettyWriteResponseFilter将在您的过滤器得到一个被调用的机会之前发送响应
* 也就是说如果不小于 -1 ,将不会执行获取后端响应的逻辑
*
* @return
*/
@Override
public
int
getOrder
()
{
return
-
2
;
}
@Override
@SuppressWarnings
(
"unchecked"
)
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
ServerHttpRequest
request
=
exchange
.
getRequest
();
// 请求路径
String
requestPath
=
request
.
getPath
().
pathWithinApplication
().
value
();
Route
route
=
getGatewayRoute
(
exchange
);
// String ipAddress = WebUtils.get(request);
String
ipAddress
=
IpUtils
.
getRealIpAddress
(
exchange
.
getRequest
());
Map
<
String
,
String
>
headers
=
exchange
.
getRequest
().
getHeaders
().
toSingleValueMap
();
AccessLogPdu
accessLogPdu
=
new
AccessLogPdu
();
accessLogPdu
.
initAttrValue
();
accessLogPdu
.
setAppName
(
appName
);
accessLogPdu
.
setTraceID
(
headers
.
getOrDefault
(
TRACE_ID
,
""
));
accessLogPdu
.
setPspanId
(
Integer
.
parseInt
(
headers
.
getOrDefault
(
PSPAN_ID
,
"0"
)));
accessLogPdu
.
setSpanId
(
Integer
.
parseInt
(
headers
.
getOrDefault
(
SPAN_ID
,
"0"
)));
accessLogPdu
.
setSchema
(
request
.
getURI
().
getScheme
());
accessLogPdu
.
setHostName
(
NetUtil
.
getLocalHostName
());
accessLogPdu
.
setUri
(
requestPath
);
accessLogPdu
.
setTargetServer
(
route
.
getId
());
accessLogPdu
.
setRequestIp
(
IpUtils
.
getRealIpAddress
(
exchange
.
getRequest
()));
accessLogPdu
.
setRequestTime
(
new
Date
());
accessLogPdu
.
setLogTime
(
new
Date
());
accessLogPdu
.
setMethod
(
request
.
getMethodValue
());
//accessLogPdu.setRequestData(paramStr);
// GatewayLog gatewayLog = new GatewayLog();
// gatewayLog.setSchema(request.getURI().getScheme());
// gatewayLog.setRequestMethod(request.getMethodValue());
// gatewayLog.setRequestPath(requestPath);
// gatewayLog.setTargetServer(route.getId());
// gatewayLog.setRequestTime(new Date());
// gatewayLog.setIp(ipAddress);
MediaType
mediaType
=
request
.
getHeaders
().
getContentType
();
if
(
MediaType
.
APPLICATION_FORM_URLENCODED
.
isCompatibleWith
(
mediaType
)
||
MediaType
.
APPLICATION_JSON
.
isCompatibleWith
(
mediaType
))
{
return
writeBodyLog
(
exchange
,
chain
,
accessLogPdu
);
}
else
{
return
writeBasicLog
(
exchange
,
chain
,
accessLogPdu
);
}
}
/**
* form参数形式
*
* @param exchange
* @param chain
* @param accessLog
* @return
*/
private
Mono
<
Void
>
writeBasicLog
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
,
AccessLogPdu
accessLog
)
{
StringBuilder
builder
=
new
StringBuilder
();
MultiValueMap
<
String
,
String
>
queryParams
=
exchange
.
getRequest
().
getQueryParams
();
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
queryParams
.
entrySet
())
{
builder
.
append
(
entry
.
getKey
()).
append
(
"="
).
append
(
StringUtils
.
join
(
entry
.
getValue
(),
","
));
}
accessLog
.
setRequestData
(
builder
.
toString
());
//获取响应体
ServerHttpResponseDecorator
decoratedResponse
=
recordResponseLog
(
exchange
,
accessLog
);
return
chain
.
filter
(
exchange
.
mutate
().
response
(
decoratedResponse
).
build
())
.
then
(
Mono
.
fromRunnable
(()
->
{
// 打印日志 发送
writeAccessLog
(
accessLog
);
}));
}
/**
* 解决 request body 只能读取一次问题,
* 参考: org.springframework.cloud.gateway.filter.factory.rewrite.ModifyRequestBodyGatewayFilterFactory
*
* @param exchange
* @param chain
* @param accessLogPdu
* @return
*/
@SuppressWarnings
(
"unchecked"
)
private
Mono
writeBodyLog
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
,
AccessLogPdu
accessLogPdu
)
{
ServerRequest
serverRequest
=
ServerRequest
.
create
(
exchange
,
messageReaders
);
Mono
<
String
>
modifiedBody
=
serverRequest
.
bodyToMono
(
String
.
class
)
.
flatMap
(
body
->
{
accessLogPdu
.
setRequestData
(
body
);
return
Mono
.
just
(
body
);
});
// 通过 BodyInserter 插入 body(支持修改body), 避免 request body 只能获取一次
BodyInserter
bodyInserter
=
BodyInserters
.
fromPublisher
(
modifiedBody
,
String
.
class
);
HttpHeaders
headers
=
new
HttpHeaders
();
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
);
CachedBodyOutputMessage
outputMessage
=
new
CachedBodyOutputMessage
(
exchange
,
headers
);
return
bodyInserter
.
insert
(
outputMessage
,
new
BodyInserterContext
())
.
then
(
Mono
.
defer
(()
->
{
// 重新封装请求
ServerHttpRequest
decoratedRequest
=
requestDecorate
(
exchange
,
headers
,
outputMessage
);
// 记录响应日志
ServerHttpResponseDecorator
decoratedResponse
=
recordResponseLog
(
exchange
,
accessLogPdu
);
// 记录普通的
return
chain
.
filter
(
exchange
.
mutate
().
request
(
decoratedRequest
).
response
(
decoratedResponse
).
build
())
.
then
(
Mono
.
fromRunnable
(()
->
{
// 打印日志 并发送
writeAccessLog
(
accessLogPdu
);
}));
}));
}
private
void
writeAccessLog
(
AccessLogPdu
accessLogPdu
)
{
// log.info("accessLog:{}",JSON.toJSONString(accessLogPdu));
messageProducer
.
syncAccessSend
(
accessLogPdu
);
}
private
Route
getGatewayRoute
(
ServerWebExchange
exchange
)
{
return
exchange
.
getAttribute
(
ServerWebExchangeUtils
.
GATEWAY_ROUTE_ATTR
);
}
/**
* 请求装饰器,重新计算 headers
*
* @param exchange
* @param headers
* @param outputMessage
* @return
*/
private
ServerHttpRequestDecorator
requestDecorate
(
ServerWebExchange
exchange
,
HttpHeaders
headers
,
CachedBodyOutputMessage
outputMessage
)
{
return
new
ServerHttpRequestDecorator
(
exchange
.
getRequest
())
{
@Override
public
HttpHeaders
getHeaders
()
{
long
contentLength
=
headers
.
getContentLength
();
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
httpHeaders
.
putAll
(
super
.
getHeaders
());
if
(
contentLength
>
0
)
{
httpHeaders
.
setContentLength
(
contentLength
);
}
else
{
// TODO: this causes a 'HTTP/1.1 411 Length Required' // on
// httpbin.org
httpHeaders
.
set
(
HttpHeaders
.
TRANSFER_ENCODING
,
"chunked"
);
}
return
httpHeaders
;
}
@Override
public
Flux
<
DataBuffer
>
getBody
()
{
return
outputMessage
.
getBody
();
}
};
}
/**
* 记录响应日志
* 通过 DataBufferFactory 解决响应体分段传输问题。
*/
private
ServerHttpResponseDecorator
recordResponseLog
(
ServerWebExchange
exchange
,
AccessLogPdu
accessLogPdu
)
{
ServerHttpResponse
response
=
exchange
.
getResponse
();
DataBufferFactory
bufferFactory
=
response
.
bufferFactory
();
return
new
ServerHttpResponseDecorator
(
response
)
{
@Override
public
Mono
<
Void
>
writeWith
(
Publisher
<?
extends
DataBuffer
>
body
)
{
if
(
body
instanceof
Flux
)
{
Date
responseTime
=
new
Date
();
// accessLogPdu.setResponseTime(responseTime);
// 计算执行时间
long
executeTime
=
(
responseTime
.
getTime
()
-
accessLogPdu
.
getRequestTime
().
getTime
());
accessLogPdu
.
setDuration
(
executeTime
);
// 获取响应类型,如果是 json 就打印
String
originalResponseContentType
=
exchange
.
getAttribute
(
ServerWebExchangeUtils
.
ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR
);
if
(
ObjectUtil
.
equal
(
this
.
getStatusCode
(),
HttpStatus
.
OK
)
&&
StringUtil
.
isNotBlank
(
originalResponseContentType
)
&&
originalResponseContentType
.
contains
(
"application/json"
))
{
Flux
<?
extends
DataBuffer
>
fluxBody
=
Flux
.
from
(
body
);
return
super
.
writeWith
(
fluxBody
.
buffer
().
map
(
dataBuffers
->
{
// 合并多个流集合,解决返回体分段传输
DataBufferFactory
dataBufferFactory
=
new
DefaultDataBufferFactory
();
DataBuffer
join
=
dataBufferFactory
.
join
(
dataBuffers
);
byte
[]
content
=
new
byte
[
join
.
readableByteCount
()];
join
.
read
(
content
);
// 释放掉内存
DataBufferUtils
.
release
(
join
);
String
responseResult
=
new
String
(
content
,
StandardCharsets
.
UTF_8
);
accessLogPdu
.
setResponseData
(
responseResult
);
return
bufferFactory
.
wrap
(
content
);
}));
}
}
// if body is not a flux. never got there.
return
super
.
writeWith
(
body
);
}
};
}
}
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GatewayResponseFilter.java
View file @
db8a61d7
...
...
@@ -39,7 +39,7 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.O
* @date: 2022/8/18 13:48
* @description:
**/
@Component
//
@Component
@Slf4j
public
class
GatewayResponseFilter
implements
GlobalFilter
,
Ordered
{
...
...
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalCacheRequestFilter.java
View file @
db8a61d7
...
...
@@ -21,7 +21,7 @@ import reactor.core.publisher.Mono;
* @author: zxfei
* @date: 2022/6/20 16:59
*/
@Component
//
@Component
@Slf4j
public
class
GlobalCacheRequestFilter
implements
GlobalFilter
,
Ordered
{
...
...
@@ -51,6 +51,6 @@ public class GlobalCacheRequestFilter implements GlobalFilter, Ordered {
@Override
public
int
getOrder
()
{
return
HIGHEST_PRECEDENCE
;
return
-
3
;
}
}
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalLogFilter.java
View file @
db8a61d7
...
...
@@ -61,57 +61,63 @@ public class GlobalLogFilter implements GlobalFilter, Ordered {
private
static
final
String
START_TIME
=
"startTime"
;
private
static
final
String
TRACE_ID
=
"traceId"
;
private
static
final
String
SPAN_ID
=
"spanId"
;
private
static
final
String
PSPAN_ID
=
"pspanId"
;
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
log
.
info
(
"GlobalLogFilter:{}"
,
getOrder
());
MDC
.
put
(
"startTime"
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
//保存请求链路,设置数据追踪id到header中
if
(!
customGatewayProperties
.
getRequestLog
())
{
return
chain
.
filter
(
exchange
);
}
ServerHttpRequest
request
=
exchange
.
getRequest
();
String
path
=
request
.
getPath
().
toString
();
String
method
=
request
.
getMethod
().
name
();
//判断请求类型
String
paramStr
=
""
;
if
(
isJsonRequest
(
request
))
{
//读取请求体后 内容需要重新设置进去
paramStr
=
resolveBodyFromRequest
(
request
);
}
else
{
//非json类型,
MultiValueMap
<
String
,
String
>
parameterMap
=
request
.
getQueryParams
();
paramStr
=
JSON
.
toJSONString
(
parameterMap
);
}
Integer
pspanId
=
0
;
Integer
spanId
=
1
;
String
traceId
=
IdUtil
.
objectId
();
AccessLogPdu
accessLogPdu
=
new
AccessLogPdu
();
accessLogPdu
.
initAttrValue
();
accessLogPdu
.
setAppName
(
appName
);
accessLogPdu
.
setHostName
(
NetUtil
.
getLocalHostName
());
accessLogPdu
.
setLogLevel
(
"INFO"
);
accessLogPdu
.
setRequestIp
(
IpUtils
.
getRealIpAddress
(
exchange
.
getRequest
()));
accessLogPdu
.
setRequestParam
(
paramStr
);
accessLogPdu
.
setLogTime
(
new
Date
());
accessLogPdu
.
setMethod
(
method
);
accessLogPdu
.
setUri
(
path
);
accessLogPdu
.
setTraceID
(
traceId
);
messageProducer
.
syncAccessSend
(
accessLogPdu
);
exchange
.
getAttributes
().
put
(
START_TIME
,
System
.
currentTimeMillis
());
ServerHttpRequest
newRequest
=
exchange
.
getRequest
().
mutate
()
.
header
(
TRACE_ID
,
traceId
)
.
header
(
SPAN_ID
,
pspanId
.
toString
())
.
header
(
PSPAN_ID
,
spanId
.
toString
())
.
build
();
return
chain
.
filter
(
exchange
.
mutate
().
request
(
newRequest
).
build
());
//判断请求类型
// String paramStr ="";
// if (isJsonRequest(request)) {
// //读取请求体后 内容需要重新设置进去
// paramStr = resolveBodyFromRequest(request);
// } else {
// //非json类型,
// MultiValueMap<String, String> parameterMap = request.getQueryParams();
// paramStr=JSON.toJSONString(parameterMap);
// }
// AccessLogPdu accessLogPdu = new AccessLogPdu();
// accessLogPdu.initAttrValue();
// accessLogPdu.setAppName(appName);
// accessLogPdu.setHostName(NetUtil.getLocalHostName());
// accessLogPdu.setLogLevel("INFO");
// accessLogPdu.setRequestIp(IpUtils.getRealIpAddress(exchange.getRequest()));
// accessLogPdu.setRequestData(paramStr);
// accessLogPdu.setLogTime(new Date());
// accessLogPdu.setMethod(method);
// accessLogPdu.setUri(path);
// accessLogPdu.setTraceID(traceId);
// messageProducer.syncAccessSend(accessLogPdu);
//exchange.getAttributes().put(START_TIME, System.currentTimeMillis());
// ServerHttpRequest newRequest = exchange.getRequest().mutate()
// .header(TRACE_ID, traceId)
// .header(TRACE_ID, traceId)
// .header(TRACE_ID, traceId)
// .build();
//
// return chain.filter(exchange.mutate().request(newRequest).build());
}
@Override
public
int
getOrder
()
{
return
0
;
return
-
3
;
}
/**
...
...
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