AOP拦截日志类,抛异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
AOP的日志拦截类中,抛出异常:
java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
主要原因:对方法的参数使用JSON.toJSONString(args[index])转换时,有异常抛出【如果参数类型是请求和响应的http,使用JSON.toJSONString()转换会抛异常】
解决方案:将不能进行序列化的入参过滤掉,只要留下我们需要记录的入参参数记录到日志中即可

完整代码:
/**
* 从切点中解析出该切点对应的方法
* @param point point
* @throws ClassNotFoundException
* @throws IOException
* @author 洪墨水
*/
private void getRequestParams(ProceedingJoinPoint point,
RecordMessage recordMessage)
throws ClassNotFoundException, IOException
{
/* 类名 */
String targetObject = point.getTarget().getClass().getName();
/* 方法名 */
String methodName = point.getSignature().getName(); recordMessage.setTargetObject(targetObject);
recordMessage.setMethod(methodName); Object[] args = point.getArgs(); Class<?> targetClass = Class.forName(targetObject); Method[] methods = targetClass.getMethods(); StringBuilder requestBuilder = new StringBuilder(0); /**
* 遍历方法 获取能与方法名相同且请求参数个数也相同的方法
*/
for (Method method : methods)
{
if (!method.getName().equals(methodName))
{
continue;
} Class<?>[] classes = method.getParameterTypes(); if (classes.length != args.length)
{
continue;
} for (int index = 0; index < classes.length; index++)
{
// 如果参数类型是请求和响应的http,则不需要拼接【这两个参数,使用JSON.toJSONString()转换会抛异常】
if (args[index] instanceof HttpServletRequest
|| args[index] instanceof HttpServletResponse)
{
continue;
}
requestBuilder.append(args[index] == null ? ""
: JSON.toJSONString(args[index]));
} recordMessage.setRequestParames(requestBuilder.toString());
} return;
}
AOP拦截日志类,抛异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode的更多相关文章
- AOP拦截日志报错llegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
原文链接:https://my.oschina.net/mengzhang6/blog/2395893 关于一次AOP拦截入参记录日志报错的梳理总结 将服务发布到tomcat中后,观察服务的运行状态以 ...
- 使用Servlet3.0新特性asyncSupported=true时抛异常java.lang.IllegalStateException: Not supported
最近在运用Servlet3.0新特性:异步处理功能的时候出现以下了2个问题: 运行时会抛出以下两种异常: 一月 19, 2014 3:07:07 下午 org.apache.catalina.core ...
- Aop 打印参数日志时,出现参数序列化异常。It is illegal to call this method if the current request is not in asynchron
错误信息: nested exception is java.lang.IllegalStateException: It is illegal to call this method if the ...
- 异常:java.lang.LinkageError: loader constraint violation: when resolving interface method
异常:java.lang.LinkageError: loader constraint violation: when resolving interface method "javax. ...
- Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)
使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下: Caused by: java.lang.IllegalStateExcepti ...
- 异常java.lang.IllegalStateException的解决
在初始化viewPagerAdapter时,显示异常.从网上找了找有两类这样的问题,一种是说给一个视图设置了两个父类,如: TextView tv = new TextView();layout.ad ...
- 项目启动异常,java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' befo ...
- SpringBoot测试类启动错误 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
报错 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Cont ...
- Tomcat启动之异常java.lang.IllegalStateException
严重: Exception sending context destroyed event to listener instance of class org.springframework.web. ...
随机推荐
- 动态GI
在Engine/Config 目录中找到ConsoleVariables.ini并打开,在其中加入 r.LightPropagationVolume = 1 ,保存,重启引擎 如果场景中有Post P ...
- 图论&线性基(?)(8.12)
边没有负权,最短路最多只有n条边 很暴力的思想: 先跑一遍最短路,找出最短路上的边,枚举每条边,翻倍,放进原图再跑一遍.取最大值 好熟悉啊 分层建图,建k层 每层内部是原图 若原图中u到v有连边,则由 ...
- SQLite入门语句之约束
一.SQLite约束之NOT NULL 确保某列不能有 NULL 值.默认情况下,列可以保存 NULL 值.如果您不想某列有 NULL 值,那么需要在该列上定义此约束,指定在该列上不允许 NULL 值 ...
- CopyOnWriteArrayList 源码分析
CopyOnWriteArrayList CopyOnWriteArrayList 能解决什么问题?什么时候使用 CopyOnWriteArrayList? 1)CopyOnWriteArrayLis ...
- base64加密小案例
python终端下: import base64 >>> dict='{"name":"tom"}' >>> dict.en ...
- 20160520—JS打分控件
效果预览: 可实现功能:鼠标在滑动条内左右滑动,文本框内分数变动:文本框输入数字,滑动条长度自动改变. JavaScript代码: $(function () { scoreFun($("# ...
- 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_06 Properties集合_2_Properties集合中的方法store
第一行是注释,第二行是时间,时间是自动加的 使用FileOutputStream. 写入中文会乱码
- 【BASIS系列】SAP 批量锁住用户和TCODE的方法
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP 批量锁住用户和TCOD ...
- 执行 bower -v 时出现内部错误
安装nodejs ,我的位置是D:\node.js_install.全局模块安装默认放在C:\Users\Administrator\AppData\Roaming\npm\node_modules里 ...
- [Vim 填坑] 01 Vim 中替换与注释的补充
目录 1. print( 坑的信息 ) 2. 开始填坑 (1) :n1,n2s/old/new/gc 的后续命令 ^E ^Y (2) 利用"V-可视"模式进行多行注释 1. pri ...