Commit db8a61d7 authored by 赵啸非's avatar 赵啸非

修改网关日志

parent 356c858d
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
*/
* TraceId
*/
private String traceID;
/**
* 应用名称
*/
* 父服务调用id
*/
private Integer pspanId;
/**
* 当前服务跨度Id
*/
private Integer spanId;
/**
* 应用名称
*/
private String appName;
/**
* 实例IP
*/
* 实例IP
*/
private String hostName;
/**
* 日志等级
*/
* 目标服务
*/
private String targetServer;
/**
* 日志等级
*/
private String logLevel;
/**
* 请求者IP
*/
* 请求者IP
*/
private String requestIp;
/**
* 请求方式
*/
* 请求方式
*/
private String method;
/**
* 用户浏览器UA
*/
* 协议
*/
private String schema;
/**
* 用户浏览器UA
*/
private String ua;
/**
* 请求URI
*/
* 请求URI
*/
private String uri;
/**
* 请求参数,json序列化
*/
private String requestParam;
* 请求参数,json序列化
*/
private String requestData;
/**
* 响应结果
*/
private String response;
* 响应结果,
*/
private String responseData;
/**
* 日志产生时间
*/
* 日志产生时间
*/
private Date logTime;
/**
* 持续时间,单位毫秒
*/
private Integer duration;
* 请求时间
*/
private Date requestTime;
/**
* 响应时间
*/
private Date responseTime;
/**
* 持续时间,单位毫秒
*/
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 */
/** TraceId */
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> requestParamList;
private List<String> requestDataList;
/** 响应结果 */
private List<String> responseList;
/** 响应结果, */
private List<String> responseDataList;
/** 开始 日志产生时间 */
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,943 +215,1379 @@ public class AccessLogPdu extends BaseEntityLong {
public AccessLogPdu(){}
/**
* 获取 追踪Id
* @return String
*/
* 获取 TraceId
* @return String
*/
public String getTraceID(){
return traceID;
}
/**
* 设置 追踪Id
* @param traceID
*/
* 设置 TraceId
* @param traceID
*/
public void setTraceID(String traceID){
this.traceID = traceID;
}
/**
* 获取 应用名称
* @return String
*/
* 获取 父服务调用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
*/
public String getAppName(){
return appName;
}
/**
* 设置 应用名称
* @param appName
*/
* 设置 应用名称
* @param appName
*/
public void setAppName(String appName){
this.appName = appName;
}
/**
* 获取 实例IP
* @return String
*/
* 获取 实例IP
* @return String
*/
public String getHostName(){
return hostName;
}
/**
* 设置 实例IP
* @param hostName
*/
* 设置 实例IP
* @param hostName
*/
public void setHostName(String hostName){
this.hostName = hostName;
}
/**
* 获取 日志等级
* @return String
*/
* 获取 目标服务
* @return String
*/
public String getTargetServer(){
return targetServer;
}
/**
* 设置 目标服务
* @param targetServer
*/
public void setTargetServer(String targetServer){
this.targetServer = targetServer;
}
/**
* 获取 日志等级
* @return String
*/
public String getLogLevel(){
return logLevel;
}
/**
* 设置 日志等级
* @param logLevel
*/
* 设置 日志等级
* @param logLevel
*/
public void setLogLevel(String logLevel){
this.logLevel = logLevel;
}
/**
* 获取 请求者IP
* @return String
*/
* 获取 请求者IP
* @return String
*/
public String getRequestIp(){
return requestIp;
}
/**
* 设置 请求者IP
* @param requestIp
*/
* 设置 请求者IP
* @param requestIp
*/
public void setRequestIp(String requestIp){
this.requestIp = requestIp;
}
/**
* 获取 请求方式
* @return String
*/
* 获取 请求方式
* @return String
*/
public String getMethod(){
return method;
}
/**
* 设置 请求方式
* @param method
*/
* 设置 请求方式
* @param method
*/
public void setMethod(String method){
this.method = method;
}
/**
* 获取 用户浏览器UA
* @return String
*/
* 获取 协议
* @return String
*/
public String getSchema(){
return schema;
}
/**
* 设置 协议
* @param schema
*/
public void setSchema(String schema){
this.schema = schema;
}
/**
* 获取 用户浏览器UA
* @return String
*/
public String getUa(){
return ua;
}
/**
* 设置 用户浏览器UA
* @param ua
*/
* 设置 用户浏览器UA
* @param ua
*/
public void setUa(String ua){
this.ua = ua;
}
/**
* 获取 请求URI
* @return String
*/
* 获取 请求URI
* @return String
*/
public String getUri(){
return uri;
}
/**
* 设置 请求URI
* @param uri
*/
* 设置 请求URI
* @param uri
*/
public void setUri(String uri){
this.uri = uri;
}
/**
* 获取 请求参数,json序列化
* @return String
*/
public String getRequestParam(){
return requestParam;
* 获取 请求参数,json序列化
* @return String
*/
public String getRequestData(){
return requestData;
}
/**
* 设置 请求参数,json序列化
* @param requestParam
*/
public void setRequestParam(String requestParam){
this.requestParam = requestParam;
* 设置 请求参数,json序列化
* @param requestData
*/
public void setRequestData(String requestData){
this.requestData = requestData;
}
/**
* 获取 响应结果
* @return String
*/
public String getResponse(){
return response;
* 获取 响应结果,
* @return String
*/
public String getResponseData(){
return responseData;
}
/**
* 设置 响应结果
* @param response
*/
public void setResponse(String response){
this.response = response;
* 设置 响应结果,
* @param responseData
*/
public void setResponseData(String responseData){
this.responseData = responseData;
}
/**
* 获取 日志产生时间
* @return Date
*/
* 获取 日志产生时间
* @return Date
*/
public Date getLogTime(){
return logTime;
}
/**
* 设置 日志产生时间
* @param logTime
*/
* 设置 日志产生时间
* @param logTime
*/
public void setLogTime(Date logTime){
this.logTime = logTime;
}
/**
* 获取 持续时间,单位毫秒
* @return Integer
*/
public Integer getDuration(){
* 获取 请求时间
* @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 Long
*/
public Long getDuration(){
return duration;
}
/**
* 设置 持续时间,单位毫秒
* @param duration
*/
public void setDuration(Integer duration){
* 设置 持续时间,单位毫秒
* @param duration
*/
public void setDuration(Long duration){
this.duration = duration;
}
/**
* 获取 开始 主键ID,主键,自增长
* @return idStart
*/
* 获取 开始 主键ID
* @return idStart
*/
public Long getIdStart(){
return this.idStart;
}
/**
* 设置 开始 主键ID,主键,自增长
* @param idStart
*/
* 设置 开始 主键ID
* @param idStart
*/
public void setIdStart(Long idStart){
this.idStart = idStart;
}
/**
* 获取 结束 主键ID,主键,自增长
* @return $idEnd
*/
* 获取 结束 主键ID
* @return $idEnd
*/
public Long getIdEnd(){
return this.idEnd;
}
/**
* 设置 结束 主键ID,主键,自增长
* @param idEnd
*/
* 设置 结束 主键ID
* @param idEnd
*/
public void setIdEnd(Long idEnd){
this.idEnd = idEnd;
}
/**
* 获取 增加 主键ID,主键,自增长
* @return idIncrement
*/
* 获取 增加 主键ID
* @return idIncrement
*/
public Long getIdIncrement(){
return this.idIncrement;
}
/**
* 设置 增加 主键ID,主键,自增长
* @param idIncrement
*/
* 设置 增加 主键ID
* @param idIncrement
*/
public void setIdIncrement(Long idIncrement){
this.idIncrement = idIncrement;
}
/**
* 获取 主键ID,主键,自增长
* @return idList
*/
* 获取 主键ID
* @return idList
*/
public List<Long> getIdList(){
return this.idList;
}
/**
* 设置 主键ID,主键,自增长
* @param idList
*/
* 设置 主键ID
* @param idList
*/
public void setIdList(List<Long> idList){
this.idList = idList;
}
/**
* 获取 追踪Id
* @return traceIDList
*/
* 获取 TraceId
* @return traceIDList
*/
public List<String> getTraceIDList(){
return this.traceIDList;
}
/**
* 设置 追踪Id
* @param traceIDList
*/
* 设置 TraceId
* @param traceIDList
*/
public void setTraceIDList(List<String> traceIDList){
this.traceIDList = traceIDList;
}
/**
* 获取 应用名称
* @return appNameList
*/
* 获取 开始 父服务调用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
*/
public List<String> getAppNameList(){
return this.appNameList;
}
/**
* 设置 应用名称
* @param appNameList
*/
* 设置 应用名称
* @param appNameList
*/
public void setAppNameList(List<String> appNameList){
this.appNameList = appNameList;
}
/**
* 获取 实例IP
* @return hostNameList
*/
* 获取 实例IP
* @return hostNameList
*/
public List<String> getHostNameList(){
return this.hostNameList;
}
/**
* 设置 实例IP
* @param hostNameList
*/
* 设置 实例IP
* @param hostNameList
*/
public void setHostNameList(List<String> hostNameList){
this.hostNameList = hostNameList;
}
/**
* 获取 日志等级
* @return logLevelList
*/
* 获取 目标服务
* @return targetServerList
*/
public List<String> getTargetServerList(){
return this.targetServerList;
}
/**
* 设置 目标服务
* @param targetServerList
*/
public void setTargetServerList(List<String> targetServerList){
this.targetServerList = targetServerList;
}
/**
* 获取 日志等级
* @return logLevelList
*/
public List<String> getLogLevelList(){
return this.logLevelList;
}
/**
* 设置 日志等级
* @param logLevelList
*/
* 设置 日志等级
* @param logLevelList
*/
public void setLogLevelList(List<String> logLevelList){
this.logLevelList = logLevelList;
}
/**
* 获取 请求者IP
* @return requestIpList
*/
* 获取 请求者IP
* @return requestIpList
*/
public List<String> getRequestIpList(){
return this.requestIpList;
}
/**
* 设置 请求者IP
* @param requestIpList
*/
* 设置 请求者IP
* @param requestIpList
*/
public void setRequestIpList(List<String> requestIpList){
this.requestIpList = requestIpList;
}
/**
* 获取 请求方式
* @return methodList
*/
* 获取 请求方式
* @return methodList
*/
public List<String> getMethodList(){
return this.methodList;
}
/**
* 设置 请求方式
* @param methodList
*/
* 设置 请求方式
* @param methodList
*/
public void setMethodList(List<String> methodList){
this.methodList = methodList;
}
/**
* 获取 用户浏览器UA
* @return uaList
*/
* 获取 协议
* @return schemaList
*/
public List<String> getSchemaList(){
return this.schemaList;
}
/**
* 设置 协议
* @param schemaList
*/
public void setSchemaList(List<String> schemaList){
this.schemaList = schemaList;
}
/**
* 获取 用户浏览器UA
* @return uaList
*/
public List<String> getUaList(){
return this.uaList;
}
/**
* 设置 用户浏览器UA
* @param uaList
*/
* 设置 用户浏览器UA
* @param uaList
*/
public void setUaList(List<String> uaList){
this.uaList = uaList;
}
/**
* 获取 请求URI
* @return uriList
*/
* 获取 请求URI
* @return uriList
*/
public List<String> getUriList(){
return this.uriList;
}
/**
* 设置 请求URI
* @param uriList
*/
* 设置 请求URI
* @param uriList
*/
public void setUriList(List<String> uriList){
this.uriList = uriList;
}
/**
* 获取 请求参数,json序列化
* @return requestParamList
*/
public List<String> getRequestParamList(){
return this.requestParamList;
* 获取 请求参数,json序列化
* @return requestDataList
*/
public List<String> getRequestDataList(){
return this.requestDataList;
}
/**
* 设置 请求参数,json序列化
* @param requestParamList
*/
public void setRequestParamList(List<String> requestParamList){
this.requestParamList = requestParamList;
* 设置 请求参数,json序列化
* @param requestDataList
*/
public void setRequestDataList(List<String> requestDataList){
this.requestDataList = requestDataList;
}
/**
* 获取 响应结果
* @return responseList
*/
public List<String> getResponseList(){
return this.responseList;
* 获取 响应结果,
* @return responseDataList
*/
public List<String> getResponseDataList(){
return this.responseDataList;
}
/**
* 设置 响应结果
* @param responseList
*/
public void setResponseList(List<String> responseList){
this.responseList = responseList;
* 设置 响应结果,
* @param responseDataList
*/
public void setResponseDataList(List<String> responseDataList){
this.responseDataList = responseDataList;
}
/**
* 获取 开始 日志产生时间
* @return logTimeStart
*/
* 获取 开始 日志产生时间
* @return logTimeStart
*/
public String getLogTimeStart(){
return this.logTimeStart;
}
/**
* 设置 开始 日志产生时间
* @param logTimeStart
*/
* 设置 开始 日志产生时间
* @param logTimeStart
*/
public void setLogTimeStart(String logTimeStart){
this.logTimeStart = logTimeStart;
}
/**
* 获取 结束 日志产生时间
* @return logTimeEnd
*/
* 获取 结束 日志产生时间
* @return logTimeEnd
*/
public String getLogTimeEnd(){
return this.logTimeEnd;
}
/**
* 设置 结束 日志产生时间
* @param logTimeEnd
*/
* 设置 结束 日志产生时间
* @param logTimeEnd
*/
public void setLogTimeEnd(String logTimeEnd){
this.logTimeEnd = logTimeEnd;
}
/**
* 获取 开始 持续时间,单位毫秒
* @return durationStart
*/
public Integer getDurationStart(){
* 获取 开始 请求时间
* @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 Long getDurationStart(){
return this.durationStart;
}
/**
* 设置 开始 持续时间,单位毫秒
* @param durationStart
*/
public void setDurationStart(Integer durationStart){
* 设置 开始 持续时间,单位毫秒
* @param durationStart
*/
public void setDurationStart(Long durationStart){
this.durationStart = durationStart;
}
/**
* 获取 结束 持续时间,单位毫秒
* @return $durationEnd
*/
public Integer getDurationEnd(){
* 获取 结束 持续时间,单位毫秒
* @return $durationEnd
*/
public Long getDurationEnd(){
return this.durationEnd;
}
/**
* 设置 结束 持续时间,单位毫秒
* @param durationEnd
*/
public void setDurationEnd(Integer durationEnd){
* 设置 结束 持续时间,单位毫秒
* @param durationEnd
*/
public void setDurationEnd(Long durationEnd){
this.durationEnd = durationEnd;
}
/**
* 获取 增加 持续时间,单位毫秒
* @return durationIncrement
*/
public Integer getDurationIncrement(){
* 获取 增加 持续时间,单位毫秒
* @return durationIncrement
*/
public Long getDurationIncrement(){
return this.durationIncrement;
}
/**
* 设置 增加 持续时间,单位毫秒
* @param durationIncrement
*/
public void setDurationIncrement(Integer durationIncrement){
* 设置 增加 持续时间,单位毫秒
* @param durationIncrement
*/
public void setDurationIncrement(Long durationIncrement){
this.durationIncrement = durationIncrement;
}
/**
* 获取 持续时间,单位毫秒
* @return durationList
*/
public List<Integer> getDurationList(){
* 获取 持续时间,单位毫秒
* @return durationList
*/
public List<Long> getDurationList(){
return this.durationList;
}
/**
* 设置 持续时间,单位毫秒
* @param durationList
*/
public void setDurationList(List<Integer> durationList){
* 设置 持续时间,单位毫秒
* @param durationList
*/
public void setDurationList(List<Long> durationList){
this.durationList = durationList;
}
/**
* 获取 开始 创建用户
* @return createUserIdStart
*/
* 获取 开始 创建用户
* @return createUserIdStart
*/
public Long getCreateUserIdStart(){
return this.createUserIdStart;
}
/**
* 设置 开始 创建用户
* @param createUserIdStart
*/
* 设置 开始 创建用户
* @param createUserIdStart
*/
public void setCreateUserIdStart(Long createUserIdStart){
this.createUserIdStart = createUserIdStart;
}
/**
* 获取 结束 创建用户
* @return $createUserIdEnd
*/
* 获取 结束 创建用户
* @return $createUserIdEnd
*/
public Long getCreateUserIdEnd(){
return this.createUserIdEnd;
}
/**
* 设置 结束 创建用户
* @param createUserIdEnd
*/
* 设置 结束 创建用户
* @param createUserIdEnd
*/
public void setCreateUserIdEnd(Long createUserIdEnd){
this.createUserIdEnd = createUserIdEnd;
}
/**
* 获取 增加 创建用户
* @return createUserIdIncrement
*/
* 获取 增加 创建用户
* @return createUserIdIncrement
*/
public Long getCreateUserIdIncrement(){
return this.createUserIdIncrement;
}
/**
* 设置 增加 创建用户
* @param createUserIdIncrement
*/
* 设置 增加 创建用户
* @param createUserIdIncrement
*/
public void setCreateUserIdIncrement(Long createUserIdIncrement){
this.createUserIdIncrement = createUserIdIncrement;
}
/**
* 获取 创建用户
* @return createUserIdList
*/
* 获取 创建用户
* @return createUserIdList
*/
public List<Long> getCreateUserIdList(){
return this.createUserIdList;
}
/**
* 设置 创建用户
* @param createUserIdList
*/
* 设置 创建用户
* @param createUserIdList
*/
public void setCreateUserIdList(List<Long> createUserIdList){
this.createUserIdList = createUserIdList;
}
/**
* 获取 开始 创建时间
* @return createTimeStart
*/
* 获取 开始 创建时间
* @return createTimeStart
*/
public String getCreateTimeStart(){
return this.createTimeStart;
}
/**
* 设置 开始 创建时间
* @param createTimeStart
*/
* 设置 开始 创建时间
* @param createTimeStart
*/
public void setCreateTimeStart(String createTimeStart){
this.createTimeStart = createTimeStart;
}
/**
* 获取 结束 创建时间
* @return createTimeEnd
*/
* 获取 结束 创建时间
* @return createTimeEnd
*/
public String getCreateTimeEnd(){
return this.createTimeEnd;
}
/**
* 设置 结束 创建时间
* @param createTimeEnd
*/
* 设置 结束 创建时间
* @param createTimeEnd
*/
public void setCreateTimeEnd(String createTimeEnd){
this.createTimeEnd = createTimeEnd;
}
/**
* 设置 主键ID,主键,自增长
* @param id
*/
* 设置 主键ID
* @param id
*/
public AccessLogPdu id(Long id){
setId(id);
return this;
setId(id);
return this;
}
/**
* 设置 开始 主键ID,主键,自增长
* @param idStart
*/
/**
* 设置 开始 主键ID
* @param idStart
*/
public AccessLogPdu idStart(Long idStart){
this.idStart = idStart;
return this;
this.idStart = idStart;
return this;
}
/**
* 设置 结束 主键ID,主键,自增长
* @param idEnd
*/
* 设置 结束 主键ID
* @param idEnd
*/
public AccessLogPdu idEnd(Long idEnd){
this.idEnd = idEnd;
return this;
this.idEnd = idEnd;
return this;
}
/**
* 设置 增加 主键ID,主键,自增长
* @param idIncrement
*/
* 设置 增加 主键ID
* @param idIncrement
*/
public AccessLogPdu idIncrement(Long idIncrement){
this.idIncrement = idIncrement;
return this;
this.idIncrement = idIncrement;
return this;
}
/**
* 设置 主键ID,主键,自增长
* @param idList
*/
* 设置 主键ID
* @param idList
*/
public AccessLogPdu idList(List<Long> idList){
this.idList = idList;
return this;
}
return this;
}
/**
* 设置 追踪Id
* @param traceID
*/
/**
* 设置 TraceId
* @param traceID
*/
public AccessLogPdu traceID(String traceID){
setTraceID(traceID);
return this;
return this;
}
/**
* 设置 追踪Id
* @param traceIDList
*/
* 设置 TraceId
* @param traceIDList
*/
public AccessLogPdu traceIDList(List<String> traceIDList){
this.traceIDList = traceIDList;
return this;
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;
}
/**
* 设置 应用名称
* @param appName
*/
/**
* 设置 应用名称
* @param appName
*/
public AccessLogPdu appName(String appName){
setAppName(appName);
return this;
return this;
}
/**
* 设置 应用名称
* @param appNameList
*/
* 设置 应用名称
* @param appNameList
*/
public AccessLogPdu appNameList(List<String> appNameList){
this.appNameList = appNameList;
return this;
return this;
}
/**
* 设置 实例IP
* @param hostName
*/
/**
* 设置 实例IP
* @param hostName
*/
public AccessLogPdu hostName(String hostName){
setHostName(hostName);
return this;
return this;
}
/**
* 设置 实例IP
* @param hostNameList
*/
* 设置 实例IP
* @param hostNameList
*/
public AccessLogPdu hostNameList(List<String> hostNameList){
this.hostNameList = hostNameList;
return this;
return this;
}
/**
* 设置 日志等级
* @param logLevel
*/
/**
* 设置 目标服务
* @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
*/
public AccessLogPdu logLevel(String logLevel){
setLogLevel(logLevel);
return this;
return this;
}
/**
* 设置 日志等级
* @param logLevelList
*/
* 设置 日志等级
* @param logLevelList
*/
public AccessLogPdu logLevelList(List<String> logLevelList){
this.logLevelList = logLevelList;
return this;
return this;
}
/**
* 设置 请求者IP
* @param requestIp
*/
/**
* 设置 请求者IP
* @param requestIp
*/
public AccessLogPdu requestIp(String requestIp){
setRequestIp(requestIp);
return this;
return this;
}
/**
* 设置 请求者IP
* @param requestIpList
*/
* 设置 请求者IP
* @param requestIpList
*/
public AccessLogPdu requestIpList(List<String> requestIpList){
this.requestIpList = requestIpList;
return this;
return this;
}
/**
* 设置 请求方式
* @param method
*/
/**
* 设置 请求方式
* @param method
*/
public AccessLogPdu method(String method){
setMethod(method);
return this;
return this;
}
/**
* 设置 请求方式
* @param methodList
*/
* 设置 请求方式
* @param methodList
*/
public AccessLogPdu methodList(List<String> methodList){
this.methodList = methodList;
return this;
return this;
}
/**
* 设置 协议
* @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
*/
/**
* 设置 用户浏览器UA
* @param ua
*/
public AccessLogPdu ua(String ua){
setUa(ua);
return this;
return this;
}
/**
* 设置 用户浏览器UA
* @param uaList
*/
* 设置 用户浏览器UA
* @param uaList
*/
public AccessLogPdu uaList(List<String> uaList){
this.uaList = uaList;
return this;
return this;
}
/**
* 设置 请求URI
* @param uri
*/
/**
* 设置 请求URI
* @param uri
*/
public AccessLogPdu uri(String uri){
setUri(uri);
return this;
return this;
}
/**
* 设置 请求URI
* @param uriList
*/
* 设置 请求URI
* @param uriList
*/
public AccessLogPdu uriList(List<String> uriList){
this.uriList = uriList;
return this;
return this;
}
/**
* 设置 请求参数,json序列化
* @param requestParam
*/
public AccessLogPdu requestParam(String requestParam){
setRequestParam(requestParam);
return this;
/**
* 设置 请求参数,json序列化
* @param requestData
*/
public AccessLogPdu requestData(String requestData){
setRequestData(requestData);
return this;
}
/**
* 设置 请求参数,json序列化
* @param requestParamList
*/
public AccessLogPdu requestParamList(List<String> requestParamList){
this.requestParamList = requestParamList;
return this;
* 设置 请求参数,json序列化
* @param requestDataList
*/
public AccessLogPdu requestDataList(List<String> requestDataList){
this.requestDataList = requestDataList;
return this;
}
/**
* 设置 响应结果
* @param response
*/
public AccessLogPdu response(String response){
setResponse(response);
return this;
/**
* 设置 响应结果,
* @param responseData
*/
public AccessLogPdu responseData(String responseData){
setResponseData(responseData);
return this;
}
/**
* 设置 响应结果
* @param responseList
*/
public AccessLogPdu responseList(List<String> responseList){
this.responseList = responseList;
return this;
* 设置 响应结果,
* @param responseDataList
*/
public AccessLogPdu responseDataList(List<String> responseDataList){
this.responseDataList = responseDataList;
return this;
}
/**
* 设置 持续时间,单位毫秒
* @param duration
*/
public AccessLogPdu duration(Integer duration){
setDuration(duration);
return this;
* 设置 持续时间,单位毫秒
* @param duration
*/
public AccessLogPdu duration(Long duration){
setDuration(duration);
return this;
}
/**
* 设置 开始 持续时间,单位毫秒
* @param durationStart
*/
public AccessLogPdu durationStart(Integer durationStart){
this.durationStart = durationStart;
return this;
/**
* 设置 开始 持续时间,单位毫秒
* @param durationStart
*/
public AccessLogPdu durationStart(Long durationStart){
this.durationStart = durationStart;
return this;
}
/**
* 设置 结束 持续时间,单位毫秒
* @param durationEnd
*/
public AccessLogPdu durationEnd(Integer durationEnd){
this.durationEnd = durationEnd;
return this;
* 设置 结束 持续时间,单位毫秒
* @param durationEnd
*/
public AccessLogPdu durationEnd(Long durationEnd){
this.durationEnd = durationEnd;
return this;
}
/**
* 设置 增加 持续时间,单位毫秒
* @param durationIncrement
*/
public AccessLogPdu durationIncrement(Integer durationIncrement){
this.durationIncrement = durationIncrement;
return this;
* 设置 增加 持续时间,单位毫秒
* @param durationIncrement
*/
public AccessLogPdu durationIncrement(Long durationIncrement){
this.durationIncrement = durationIncrement;
return this;
}
/**
* 设置 持续时间,单位毫秒
* @param durationList
*/
public AccessLogPdu durationList(List<Integer> durationList){
* 设置 持续时间,单位毫秒
* @param durationList
*/
public AccessLogPdu durationList(List<Long> durationList){
this.durationList = durationList;
return this;
}
return this;
}
/**
* 设置 创建用户
* @param createUserId
*/
* 设置 创建用户
* @param createUserId
*/
public AccessLogPdu createUserId(Long createUserId){
setCreateUserId(createUserId);
return this;
setCreateUserId(createUserId);
return this;
}
/**
* 设置 开始 创建用户
* @param createUserIdStart
*/
/**
* 设置 开始 创建用户
* @param createUserIdStart
*/
public AccessLogPdu createUserIdStart(Long createUserIdStart){
this.createUserIdStart = createUserIdStart;
return this;
this.createUserIdStart = createUserIdStart;
return this;
}
/**
* 设置 结束 创建用户
* @param createUserIdEnd
*/
* 设置 结束 创建用户
* @param createUserIdEnd
*/
public AccessLogPdu createUserIdEnd(Long createUserIdEnd){
this.createUserIdEnd = createUserIdEnd;
return this;
this.createUserIdEnd = createUserIdEnd;
return this;
}
/**
* 设置 增加 创建用户
* @param createUserIdIncrement
*/
* 设置 增加 创建用户
* @param createUserIdIncrement
*/
public AccessLogPdu createUserIdIncrement(Long createUserIdIncrement){
this.createUserIdIncrement = createUserIdIncrement;
return this;
this.createUserIdIncrement = createUserIdIncrement;
return this;
}
/**
* 设置 创建用户
* @param createUserIdList
*/
* 设置 创建用户
* @param createUserIdList
*/
public AccessLogPdu createUserIdList(List<Long> createUserIdList){
this.createUserIdList = createUserIdList;
return this;
}
return this;
}
/**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList
*/
/**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList
*/
public List<AccessLogPdu> getOrConditionList(){
return this.orConditionList;
return this.orConditionList;
}
/**
* 设置 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @param orConditionList
*/
* 设置 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @param orConditionList
*/
public void setOrConditionList(List<AccessLogPdu> orConditionList){
this.orConditionList = orConditionList;
}
/**
* 获取 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @return andConditionList
*/
* 获取 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @return andConditionList
*/
public List<AccessLogPdu> getAndConditionList(){
return this.andConditionList;
}
/**
* 设置 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @param andConditionList
*/
* 设置 AND条件集合,列表项之间是AND,项内容之间是OR,如:(list[0].1 or list[0].2) and (list[1].3 or list[1].4)
* @param andConditionList
*/
public void setAndConditionList(List<AccessLogPdu> andConditionList){
this.andConditionList = andConditionList;
}
@Override
public int hashCode() {
return this.getId().hashCode();
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
......@@ -1095,7 +1595,7 @@ public class AccessLogPdu extends BaseEntityLong {
if (obj instanceof AccessLogPdu) {
AccessLogPdu tmp = (AccessLogPdu) obj;
if (this.getId() == tmp.getId()) {
return true;
return true;
}
}
return false;
......@@ -1103,28 +1603,40 @@ public class AccessLogPdu extends BaseEntityLong {
public void initAttrValue(){
this.traceID = "";
this.traceID = "";
this.pspanId = 0;
this.spanId = null;
this.appName = "";
this.hostName = "";
this.targetServer = "";
this.logLevel = "INFO";
this.appName = "";
this.requestIp = "";
this.hostName = "";
this.method = "";
this.logLevel = "";
this.schema = "http";
this.requestIp = "";
this.ua = "";
this.method = "";
this.uri = "";
this.ua = "";
this.requestData = "";
this.uri = "";
this.responseData = "";
this.requestParam = "";
this.logTime = null;
this.response = "";
this.requestTime = null;
this.logTime = null;
this.responseTime = null;
this.duration = null;
this.duration = null;
}
}
\ No newline at end of file
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);
}
};
}
}
......@@ -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 {
......
......@@ -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;
}
}
......@@ -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;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment