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
8dd17521
Commit
8dd17521
authored
Aug 22, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改访问日志
parent
9bad6fd6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
73 deletions
+61
-73
common-lib/src/main/java/com/mortals/xhx/common/pdu/access/AccessLogPdu.java
.../java/com/mortals/xhx/common/pdu/access/AccessLogPdu.java
+58
-58
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/AccessLogFilter.java
...om/mortals/xhx/base/framework/filter/AccessLogFilter.java
+3
-15
No files found.
common-lib/src/main/java/com/mortals/xhx/common/pdu/access/AccessLogPdu.java
View file @
8dd17521
...
@@ -7,7 +7,7 @@ import com.mortals.framework.model.BaseEntityLong;
...
@@ -7,7 +7,7 @@ import com.mortals.framework.model.BaseEntityLong;
* 访问日志Pdu对象
* 访问日志Pdu对象
*
*
* @author zxfei
* @author zxfei
* @date 2022-08-
19
* @date 2022-08-
22
*/
*/
public
class
AccessLogPdu
extends
BaseEntityLong
{
public
class
AccessLogPdu
extends
BaseEntityLong
{
...
@@ -49,10 +49,6 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -49,10 +49,6 @@ public class AccessLogPdu extends BaseEntityLong {
* 请求方式
* 请求方式
*/
*/
private
String
method
;
private
String
method
;
/**
* 协议
*/
private
String
schema
;
/**
/**
* 用户浏览器UA
* 用户浏览器UA
*/
*/
...
@@ -85,6 +81,10 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -85,6 +81,10 @@ public class AccessLogPdu extends BaseEntityLong {
* 持续时间,单位毫秒
* 持续时间,单位毫秒
*/
*/
private
Long
duration
;
private
Long
duration
;
/**
* 协议
*/
private
String
schemaData
;
/** 开始 主键ID */
/** 开始 主键ID */
private
Long
idStart
;
private
Long
idStart
;
...
@@ -143,9 +143,6 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -143,9 +143,6 @@ public class AccessLogPdu extends BaseEntityLong {
/** 请求方式 */
/** 请求方式 */
private
List
<
String
>
methodList
;
private
List
<
String
>
methodList
;
/** 协议 */
private
List
<
String
>
schemaList
;
/** 用户浏览器UA */
/** 用户浏览器UA */
private
List
<
String
>
uaList
;
private
List
<
String
>
uaList
;
...
@@ -206,6 +203,9 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -206,6 +203,9 @@ public class AccessLogPdu extends BaseEntityLong {
/** 结束 创建时间 */
/** 结束 创建时间 */
private
String
createTimeEnd
;
private
String
createTimeEnd
;
/** 协议 */
private
List
<
String
>
schemaDataList
;
/** OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4) */
/** OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4) */
private
List
<
AccessLogPdu
>
orConditionList
;
private
List
<
AccessLogPdu
>
orConditionList
;
...
@@ -340,20 +340,6 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -340,20 +340,6 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setMethod
(
String
method
){
public
void
setMethod
(
String
method
){
this
.
method
=
method
;
this
.
method
=
method
;
}
}
/**
* 获取 协议
* @return String
*/
public
String
getSchema
(){
return
schema
;
}
/**
* 设置 协议
* @param schema
*/
public
void
setSchema
(
String
schema
){
this
.
schema
=
schema
;
}
/**
/**
* 获取 用户浏览器UA
* 获取 用户浏览器UA
* @return String
* @return String
...
@@ -466,6 +452,20 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -466,6 +452,20 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setDuration
(
Long
duration
){
public
void
setDuration
(
Long
duration
){
this
.
duration
=
duration
;
this
.
duration
=
duration
;
}
}
/**
* 获取 协议
* @return String
*/
public
String
getSchemaData
(){
return
schemaData
;
}
/**
* 设置 协议
* @param schemaData
*/
public
void
setSchemaData
(
String
schemaData
){
this
.
schemaData
=
schemaData
;
}
/**
/**
* 获取 开始 主键ID
* 获取 开始 主键ID
...
@@ -764,21 +764,6 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -764,21 +764,6 @@ public class AccessLogPdu extends BaseEntityLong {
public
void
setMethodList
(
List
<
String
>
methodList
){
public
void
setMethodList
(
List
<
String
>
methodList
){
this
.
methodList
=
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
* 获取 用户浏览器UA
* @return uaList
* @return uaList
...
@@ -1095,6 +1080,21 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -1095,6 +1080,21 @@ public class AccessLogPdu extends BaseEntityLong {
this
.
createTimeEnd
=
createTimeEnd
;
this
.
createTimeEnd
=
createTimeEnd
;
}
}
/**
* 获取 协议
* @return schemaDataList
*/
public
List
<
String
>
getSchemaDataList
(){
return
this
.
schemaDataList
;
}
/**
* 设置 协议
* @param schemaDataList
*/
public
void
setSchemaDataList
(
List
<
String
>
schemaDataList
){
this
.
schemaDataList
=
schemaDataList
;
}
/**
/**
* 设置 主键ID
* 设置 主键ID
* @param id
* @param id
...
@@ -1364,25 +1364,6 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -1364,25 +1364,6 @@ 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
* 设置 用户浏览器UA
* @param ua
* @param ua
...
@@ -1553,6 +1534,25 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -1553,6 +1534,25 @@ public class AccessLogPdu extends BaseEntityLong {
/**
* 设置 协议
* @param schemaData
*/
public
AccessLogPdu
schemaData
(
String
schemaData
){
setSchemaData
(
schemaData
);
return
this
;
}
/**
* 设置 协议
* @param schemaDataList
*/
public
AccessLogPdu
schemaDataList
(
List
<
String
>
schemaDataList
){
this
.
schemaDataList
=
schemaDataList
;
return
this
;
}
/**
/**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList
* @return orConditionList
...
@@ -1621,8 +1621,6 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -1621,8 +1621,6 @@ public class AccessLogPdu extends BaseEntityLong {
this
.
method
=
""
;
this
.
method
=
""
;
this
.
schema
=
"http"
;
this
.
ua
=
""
;
this
.
ua
=
""
;
this
.
uri
=
""
;
this
.
uri
=
""
;
...
@@ -1638,5 +1636,7 @@ public class AccessLogPdu extends BaseEntityLong {
...
@@ -1638,5 +1636,7 @@ public class AccessLogPdu extends BaseEntityLong {
this
.
responseTime
=
null
;
this
.
responseTime
=
null
;
this
.
duration
=
null
;
this
.
duration
=
null
;
this
.
schemaData
=
"http"
;
}
}
}
}
\ No newline at end of file
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/AccessLogFilter.java
View file @
8dd17521
...
@@ -88,36 +88,23 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
...
@@ -88,36 +88,23 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
Route
route
=
getGatewayRoute
(
exchange
);
Route
route
=
getGatewayRoute
(
exchange
);
// String ipAddress = WebUtils.get(request);
// String ipAddress = WebUtils.get(request);
String
ipAddress
=
IpUtils
.
getRealIpAddress
(
exchange
.
getRequest
());
String
ipAddress
=
IpUtils
.
getRealIpAddress
(
exchange
.
getRequest
());
Map
<
String
,
String
>
headers
=
exchange
.
getRequest
().
getHeaders
().
toSingleValueMap
();
Map
<
String
,
String
>
headers
=
exchange
.
getRequest
().
getHeaders
().
toSingleValueMap
();
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
,
"0"
)));
accessLogPdu
.
setSpanId
(
Integer
.
parseInt
(
headers
.
getOrDefault
(
SPAN_ID
,
"0"
)));
accessLogPdu
.
setSchema
(
request
.
getURI
().
getScheme
());
accessLogPdu
.
setSchema
Data
(
request
.
getURI
().
getScheme
());
accessLogPdu
.
setHostName
(
NetUtil
.
getLocalHostName
());
accessLogPdu
.
setHostName
(
NetUtil
.
getLocalHostName
());
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
.
setRequestTime
(
new
Date
());
accessLogPdu
.
setRequestTime
(
new
Date
());
accessLogPdu
.
setLogTime
(
new
Date
());
accessLogPdu
.
setLogTime
(
new
Date
());
accessLogPdu
.
setMethod
(
request
.
getMethodValue
());
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
();
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
);
...
@@ -260,6 +247,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
...
@@ -260,6 +247,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
// accessLogPdu.setResponseTime(responseTime);
// accessLogPdu.setResponseTime(responseTime);
// 计算执行时间
// 计算执行时间
long
executeTime
=
(
responseTime
.
getTime
()
-
accessLogPdu
.
getRequestTime
().
getTime
());
long
executeTime
=
(
responseTime
.
getTime
()
-
accessLogPdu
.
getRequestTime
().
getTime
());
accessLogPdu
.
setResponseTime
(
responseTime
);
accessLogPdu
.
setDuration
(
executeTime
);
accessLogPdu
.
setDuration
(
executeTime
);
// 获取响应类型,如果是 json 就打印
// 获取响应类型,如果是 json 就打印
String
originalResponseContentType
=
exchange
.
getAttribute
(
ServerWebExchangeUtils
.
ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR
);
String
originalResponseContentType
=
exchange
.
getAttribute
(
ServerWebExchangeUtils
.
ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR
);
...
...
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