1

Trying to write a aspectJ class for my dropwizard project. Below is the class

@Aspect
public class LoggingAspect {

  @Around("execution(* javax.servlet.http.HttpServlet.*(..)) *)")
  public Object log(ProceedingJoinPoint joinPoint) throws Throwable {
    Long startTime = System.currentTimeMillis();
    Object retVal = joinPoint.proceed();
    Long timeTaken = System.currentTimeMillis() - startTime;
    HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getResponse();

    return retVal;
  }

  @Before("execution(* com.my.api.resource.*.*(..))")
  public void logBefore(JoinPoint joinPoint) throws Throwable {
    HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getResponse();
    System.out.println(joinPoint.getSignature().getName());
  }
}

What I am trying to do here is to get the api call's mapping method name. However, it seems the code above was not hit. How should I add this aspectJ class into Dropwizard class? If no way to do this, anyway I can get the api call's mapping method name? For instance, I have resource file with following code, I want to get the "listDepts" in my Filter.

@GET
@UnitOfWork
@Timed(name = "get-requests")
@ApiOperation(value = "List all departments", notes = "List all the departments", response = DeptDTO.class, responseContainer = "List", position = 10)
public Response listDepts(
  @Auth @ApiParam(access = "internal", required = false)
  PrincipalDTO user
)
{
  // ...
}
kriegaex
  • 63,017
  • 15
  • 111
  • 202
Laodao
  • 1,547
  • 3
  • 17
  • 39
  • `execution(* javax.servlet.http.HttpServlet.*(..)) *)` is invalid syntax. Maybe you mean `execution(* javax.servlet.http.HttpServlet.*(..))`. If that is not the only problem, please share an [MCVE](https://stackoverflow.com/help/mcve) on GitHub, not just snippets I cannot compile and run. I need to reproduce the problem. Too much information is missing. – kriegaex Jul 23 '22 at 10:20

0 Answers0