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
)
{
// ...
}