Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AspectJ-记录HttpServletRequest_Java_Spring_Aspectj_Spring Aop - Fatal编程技术网

Java AspectJ-记录HttpServletRequest

Java AspectJ-记录HttpServletRequest,java,spring,aspectj,spring-aop,Java,Spring,Aspectj,Spring Aop,我想劫持一个HTTPServletRequest,并使用AspectJ记录其中的一些值。然而,在连接点中结束的是一个“RequestFacade”对象。我对这个物体似乎无能为力。我的日志策略都错了吗?如何从HttpServletRequest获取有用的信息?如果我必须在调用方法之前将其展开,那么这就有点违背了我的应用程序中AOP的目的 我正在使用Glassfish服务器,如果这有什么不同的话 @Before("execution(* Service.testAuditRecord(..))")

我想劫持一个HTTPServletRequest,并使用AspectJ记录其中的一些值。然而,在连接点中结束的是一个“RequestFacade”对象。我对这个物体似乎无能为力。我的日志策略都错了吗?如何从HttpServletRequest获取有用的信息?如果我必须在调用方法之前将其展开,那么这就有点违背了我的应用程序中AOP的目的

我正在使用Glassfish服务器,如果这有什么不同的话

@Before("execution(* Service.testAuditRecord(..))")
public void logBefore(JoinPoint joinPoint) {
    System.out.println("logBefore  --->"  + joinPoint.getSignature().getName());
    System.out.println("logBefore--->Args : " + Arrays.toString(joinPoint.getArgs()));
}
请求外观记录

INFO: logBefore  --->testAuditRecord
INFO: logBefore--->Args : [org.apache.catalina.connector.RequestFacade@4dbfa7d0]
是一个接口。每个servlet容器都有自己的实现
org.apache.catalina.connector.RequestFacade
就是其中之一

也就是说,您可以自由使用
HttpServletRequest
的任何方法,而不必担心实际的实现

Service.testAuditRecord()的签名是什么?它是否将
HttpServletRequest
作为参数?如果是这样的话,AspectJ应该给您一个强类型实例,而不会带来太多麻烦。试试这个:

@Before("execution(* Service.testAuditRecord(..)) && args(request)")
public void logBefore(JoinPoint joinPoint, HttpServletRequest request) {
  //...

像这样使用
RequestContextHolder

HttpServletRequest request = ((ServletRequestAttributes) 
RequestContextHolder.getRequestAttributes()).getRequest();