Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
169e3dda
mica
项目概览
mica
/
mica
通知
10
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
169e3dda
编写于
1月 05, 2020
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🐛
List Json log.
上级
ff8427e6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
71 addition
and
24 deletion
+71
-24
build.gradle
build.gradle
+2
-2
mica-boot/src/main/java/net/dreamlu/mica/servlet/logger/RequestLogAspect.java
...ava/net/dreamlu/mica/servlet/logger/RequestLogAspect.java
+14
-19
mica-core/src/main/java/net/dreamlu/mica/core/utils/JsonUtil.java
...e/src/main/java/net/dreamlu/mica/core/utils/JsonUtil.java
+55
-3
未找到文件。
build.gradle
浏览文件 @
169e3dda
ext
{
ext
{
javaVersion
=
JavaVersion
.
VERSION_1_8
javaVersion
=
JavaVersion
.
VERSION_1_8
springBootVersion
=
"2.1.1
0
.RELEASE"
springBootVersion
=
"2.1.1
1
.RELEASE"
springCloudVersion
=
"Greenwich.SR4"
springCloudVersion
=
"Greenwich.SR4"
springCloudAlibabaVersion
=
"2.1.1.RELEASE"
springCloudAlibabaVersion
=
"2.1.1.RELEASE"
micaAutoVersion
=
"1.
1
.0"
micaAutoVersion
=
"1.
2
.0"
apolloVersion
=
"1.4.0"
apolloVersion
=
"1.4.0"
protostuffVersion
=
"1.6.0"
protostuffVersion
=
"1.6.0"
disruptorVersion
=
"3.4.2"
disruptorVersion
=
"3.4.2"
...
...
mica-boot/src/main/java/net/dreamlu/mica/servlet/logger/RequestLogAspect.java
浏览文件 @
169e3dda
...
@@ -16,10 +16,15 @@
...
@@ -16,10 +16,15 @@
package
net.dreamlu.mica.servlet.logger
;
package
net.dreamlu.mica.servlet.logger
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
net.dreamlu.mica.core.utils.*
;
import
net.dreamlu.mica.core.utils.ClassUtil
;
import
net.dreamlu.mica.core.utils.JsonUtil
;
import
net.dreamlu.mica.core.utils.StringUtil
;
import
net.dreamlu.mica.core.utils.WebUtil
;
import
net.dreamlu.mica.launcher.MicaLogLevel
;
import
net.dreamlu.mica.launcher.MicaLogLevel
;
import
net.dreamlu.mica.props.MicaRequestLogProperties
;
import
net.dreamlu.mica.props.MicaRequestLogProperties
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
...
@@ -39,7 +44,6 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -39,7 +44,6 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.*
;
import
java.util.*
;
...
@@ -58,7 +62,6 @@ import java.util.concurrent.TimeUnit;
...
@@ -58,7 +62,6 @@ import java.util.concurrent.TimeUnit;
@ConditionalOnProperty
(
value
=
MicaLogLevel
.
REQ_LOG_PROPS_PREFIX
+
".enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
value
=
MicaLogLevel
.
REQ_LOG_PROPS_PREFIX
+
".enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
class
RequestLogAspect
{
public
class
RequestLogAspect
{
private
final
MicaRequestLogProperties
properties
;
private
final
MicaRequestLogProperties
properties
;
private
final
ObjectMapper
objectMapper
;
/**
/**
* AOP 环切 控制器 R 返回值
* AOP 环切 控制器 R 返回值
...
@@ -95,13 +98,13 @@ public class RequestLogAspect {
...
@@ -95,13 +98,13 @@ public class RequestLogAspect {
String
parameterName
=
methodParam
.
getParameterName
();
String
parameterName
=
methodParam
.
getParameterName
();
Object
value
=
args
[
i
];
Object
value
=
args
[
i
];
// 如果是body的json则是对象
// 如果是body的json则是对象
if
(
requestBody
!=
null
)
{
if
(
requestBody
!=
null
&&
value
!=
null
)
{
if
(
value
==
null
)
{
JsonNode
jsonNode
=
JsonUtil
.
valueToTree
(
value
);
paraMap
.
put
(
parameterName
,
null
);
if
(
JsonUtil
.
valueToTree
(
value
)
instanceof
ObjectNode
)
{
}
else
if
(
ClassUtil
.
isPrimitiveOrWrapper
(
value
.
getClass
())
)
{
paraMap
.
putAll
(
JsonUtil
.
convertValue
(
jsonNode
,
new
TypeReference
<
Map
<?
extends
String
,
?>>(
)
{
paraMap
.
put
(
parameterName
,
value
);
})
);
}
else
{
}
else
{
paraMap
.
put
All
(
BeanUtil
.
toMap
(
value
)
);
paraMap
.
put
(
parameterName
,
value
);
}
}
continue
;
continue
;
}
}
...
@@ -135,7 +138,7 @@ public class RequestLogAspect {
...
@@ -135,7 +138,7 @@ public class RequestLogAspect {
paraMap
.
put
(
paraName
,
"InputStream"
);
paraMap
.
put
(
paraName
,
"InputStream"
);
}
else
if
(
value
instanceof
InputStreamSource
)
{
}
else
if
(
value
instanceof
InputStreamSource
)
{
paraMap
.
put
(
paraName
,
"InputStreamSource"
);
paraMap
.
put
(
paraName
,
"InputStreamSource"
);
}
else
if
(
canJso
nSerialize
(
value
))
{
}
else
if
(
JsonUtil
.
ca
nSerialize
(
value
))
{
// 判断模型能被 json 序列化,则添加
// 判断模型能被 json 序列化,则添加
paraMap
.
put
(
paraName
,
value
);
paraMap
.
put
(
paraName
,
value
);
}
else
{
}
else
{
...
@@ -201,12 +204,4 @@ public class RequestLogAspect {
...
@@ -201,12 +204,4 @@ public class RequestLogAspect {
}
}
}
}
private
boolean
canJsonSerialize
(
Object
value
)
{
try
{
objectMapper
.
writeValueAsBytes
(
value
);
return
true
;
}
catch
(
IOException
e
)
{
return
false
;
}
}
}
}
mica-core/src/main/java/net/dreamlu/mica/core/utils/JsonUtil.java
浏览文件 @
169e3dda
...
@@ -18,6 +18,7 @@ package net.dreamlu.mica.core.utils;
...
@@ -18,6 +18,7 @@ package net.dreamlu.mica.core.utils;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.TreeNode
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.*
;
import
com.fasterxml.jackson.databind.*
;
import
com.fasterxml.jackson.databind.type.CollectionLikeType
;
import
com.fasterxml.jackson.databind.type.CollectionLikeType
;
...
@@ -204,7 +205,7 @@ public class JsonUtil {
...
@@ -204,7 +205,7 @@ public class JsonUtil {
* @return Bean
* @return Bean
*/
*/
@Nullable
@Nullable
public
static
<
T
>
T
readValue
(
@Nullable
byte
[]
content
,
TypeReference
<
?
>
typeReference
)
{
public
static
<
T
>
T
readValue
(
@Nullable
byte
[]
content
,
TypeReference
<
T
>
typeReference
)
{
if
(
ObjectUtil
.
isEmpty
(
content
))
{
if
(
ObjectUtil
.
isEmpty
(
content
))
{
return
null
;
return
null
;
}
}
...
@@ -224,7 +225,7 @@ public class JsonUtil {
...
@@ -224,7 +225,7 @@ public class JsonUtil {
* @return Bean
* @return Bean
*/
*/
@Nullable
@Nullable
public
static
<
T
>
T
readValue
(
@Nullable
String
jsonString
,
TypeReference
<
?
>
typeReference
)
{
public
static
<
T
>
T
readValue
(
@Nullable
String
jsonString
,
TypeReference
<
T
>
typeReference
)
{
if
(
StringUtil
.
isBlank
(
jsonString
))
{
if
(
StringUtil
.
isBlank
(
jsonString
))
{
return
null
;
return
null
;
}
}
...
@@ -244,7 +245,7 @@ public class JsonUtil {
...
@@ -244,7 +245,7 @@ public class JsonUtil {
* @return Bean
* @return Bean
*/
*/
@Nullable
@Nullable
public
static
<
T
>
T
readValue
(
@Nullable
InputStream
in
,
TypeReference
<
?
>
typeReference
)
{
public
static
<
T
>
T
readValue
(
@Nullable
InputStream
in
,
TypeReference
<
T
>
typeReference
)
{
if
(
in
==
null
)
{
if
(
in
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -396,6 +397,18 @@ public class JsonUtil {
...
@@ -396,6 +397,18 @@ public class JsonUtil {
}
}
}
}
/**
* jackson 的类型转换
*
* @param fromValue 来源对象
* @param toValueType 转换的类型
* @param <T> 泛型标记
* @return 转换结果
*/
public
static
<
T
>
T
convertValue
(
Object
fromValue
,
Class
<
T
>
toValueType
)
{
return
getInstance
().
convertValue
(
fromValue
,
toValueType
);
}
/**
/**
* jackson 的类型转换
* jackson 的类型转换
*
*
...
@@ -420,6 +433,45 @@ public class JsonUtil {
...
@@ -420,6 +433,45 @@ public class JsonUtil {
return
getInstance
().
convertValue
(
fromValue
,
toValueTypeRef
);
return
getInstance
().
convertValue
(
fromValue
,
toValueTypeRef
);
}
}
/**
* tree 转对象
*
* @param treeNode TreeNode
* @param valueType valueType
* @param <T> 泛型标记
* @return 转换结果
*/
public
static
<
T
>
T
treeToValue
(
TreeNode
treeNode
,
Class
<
T
>
valueType
)
{
try
{
return
getInstance
().
treeToValue
(
treeNode
,
valueType
);
}
catch
(
JsonProcessingException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
}
/**
* 对象转为 json node
*
* @param value 对象
* @return JsonNode
*/
public
static
JsonNode
valueToTree
(
@Nullable
Object
value
)
{
return
getInstance
().
valueToTree
(
value
);
}
/**
* 判断是否可以序列化
*
* @param value 对象
* @return 是否可以序列化
*/
public
static
boolean
canSerialize
(
@Nullable
Object
value
)
{
if
(
value
==
null
)
{
return
true
;
}
return
getInstance
().
canSerialize
(
value
.
getClass
());
}
public
static
ObjectMapper
getInstance
()
{
public
static
ObjectMapper
getInstance
()
{
return
JacksonHolder
.
INSTANCE
;
return
JacksonHolder
.
INSTANCE
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录