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的更多相关文章

  1. 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中后,观察服务的运行状态以 ...

  2. 使用Servlet3.0新特性asyncSupported=true时抛异常java.lang.IllegalStateException: Not supported

    最近在运用Servlet3.0新特性:异步处理功能的时候出现以下了2个问题: 运行时会抛出以下两种异常: 一月 19, 2014 3:07:07 下午 org.apache.catalina.core ...

  3. 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 ...

  4. 异常:java.lang.LinkageError: loader constraint violation: when resolving interface method

    异常:java.lang.LinkageError: loader constraint violation: when resolving interface method "javax. ...

  5. Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)

    使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下: Caused by: java.lang.IllegalStateExcepti ...

  6. 异常java.lang.IllegalStateException的解决

    在初始化viewPagerAdapter时,显示异常.从网上找了找有两类这样的问题,一种是说给一个视图设置了两个父类,如: TextView tv = new TextView();layout.ad ...

  7. 项目启动异常,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 ...

  8. 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 ...

  9. Tomcat启动之异常java.lang.IllegalStateException

    严重: Exception sending context destroyed event to listener instance of class org.springframework.web. ...

随机推荐

  1. 官方文档翻译-Today

    原文链接: Today 最后更新:2017-02-18 译文: 应用的今日视图扩展被称作小部件.小部件为用户提供快速访问重要信息的入口.例如,用户打开今日视图实时查看股票价格或天气情况,查看今天的日程 ...

  2. So the type system doesn’t feel so static.

    object wb{ def main(args:Array[String]){ println("Happy everyday!DATA-CENTER!") println(ne ...

  3. sublime 3 安装格式化JSON插件

    转自 https://blog.csdn.net/sweettool/article/details/72677784     一.首先下载SublimePrettyJson插件包 https://g ...

  4. Eclipse Java工程转为Web工程步骤

    找到工程的.project文件,在<natures>标签中增加以下两行配置:<nature>org.eclipse.wst.common.modulecore.ModuleCo ...

  5. border-radius 如何计算

    1.使用px: 圆的半径是那个px值大小 用这个圆放到div的角上去切割div 2.使用%: 如果长度和宽度一样 圆的半径是长度乘这个百分比得到的结果 如果长度和宽度不一样 产生的效果是宽高乘以百分数 ...

  6. 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第4节 方法引用_7方法引用_数组的构造器引用

    先创建函数式接口 创建测试类 打印长度是10...... 方法引用优化

  7. java通过HtmlUnit工具和J4L实现模拟带验证码登录

    1.HtmlUnit 1.1介绍 HtmlUnit是一个用java编写的无界面浏览器,建模html文档,通过API调用页面,填充表单,点击链接等等.如同正常浏览器一样操作.典型应用于测试以及从网页抓取 ...

  8. 绕过安全狗Apache4.0版本

    参数拦截:script.空格and空格.空格or空格.union select.user() 绕过: and.order by绕过:  内联注释 union select绕过: union%23%0a ...

  9. vue-router路由详细

      由于Vue在开发时对路由支持的不足,于是官方补充了vue-router插件.vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来.传统的页面应用,是用一些超链接来实现 ...

  10. Pycharm 修改项目名称后 中括号中出现先前名称怎么解决?

    这时候,你打开工程的路径,会找到一个隐藏文件, .idea  目录删掉他,重新导入Pycharm 就行了. idea记录了一些工程项目信息. 步骤: 1.退出当前工程 2.打开工程路径删除.ideal ...