It is illegal to call this method if the current request is not in asynchronous mode

时间:2025-03-12 08:52:43
public Object businessLog(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature methodSignature = ((MethodSignature) joinPoint.getSignature()); String methodName = methodSignature.getName(); String className = methodSignature.getDeclaringTypeName(); Object[] args = joinPoint.getArgs(); //序列化时过滤掉request和response List<Object> logArgs = StreamUtil.streamOf(args) .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse))) .collect(Collectors.toList()); String argStr = JSON.toJSONString(logArgs); Object result; try { result = joinPoint.proceed(); String resultStr = JSON.toJSONString(result); //对入参出参做操作 } catch (Exception e) { StackTraceElement[] stackTraceArray = e.getStackTrace(); byte[] bytesArray = new byte[]{}; for (int i = 0; i < stackTraceArray.length; i++) { byte[] bytes = stackTraceArray[i].toString().getBytes(); bytesArray = Bytes.concat(bytesArray, bytes); } bytesArray = Bytes.concat(("*exception*" + e.getMessage() + "*exception*").getBytes(), bytesArray); //对异常信息做操作 throw e; } return result; } public static <T> Stream<T> streamOf(T[] array) { return ArrayUtils.isEmpty(array) ? Stream.empty() : Arrays.asList(array).stream(); }