zoukankan      html  css  js  c++  java
  • java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)

    切面打印日志时,参数序列化异常
    异常信息:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
    原因
    joinPoint.getArgs()返回的数组中携带有Request或者Response对象,导致序列化异常。

    解决方案:去除Request或者Response对象

    //        JSONArray json=JSONArray.fromObject(joinPoint.getArgs());
            Object[] args = joinPoint.getArgs();
            Stream<?> stream = ArrayUtils.isEmpty(args) ? Stream.empty() : Arrays.stream(args);
            List<Object> logArgs = stream
                    .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)))
                    .collect(Collectors.toList());
            //过滤后序列化无异常
            JSONArray json=JSONArray.fromObject(logArgs);

    相关jar包:

    import net.sf.json.JSONArray;
    import org.apache.commons.lang.ArrayUtils;
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.*;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.util.Arrays;
    import java.util.List
    import java.util.stream.Collectors;
    import java.util.stream.Stream;
  • 相关阅读:
    poj2253 青蛙
    这代码真是好,真是文艺,转来的
    java.text.MessageFormat
    java多线程的两种实现方式
    javascript with
    面向接口编程
    java 多线程 读写锁
    java 多线程 资源共享
    UML:继承、实现、依赖、关联、聚合、组合
    javascript 语言精粹 学习笔记
  • 原文地址:https://www.cnblogs.com/penghq/p/13045825.html
Copyright © 2011-2022 走看看