-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Annotation
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface AuditLog { String title() default ""; }
Guice Interceptor
`
@slf4j
public class LogInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
TimeInterval timer = DateUtil.timer();
timer.start();
Object result = invocation.proceed();
long costTime = timer.intervalMs();
log.info("cost time: {}", costTime);
return result;
}
}
Module
public class AdminModule extends AbstractModule {
@Override
protected void configure() {
LogInterceptor logInterceptor = new LogInterceptor();
requestInjection(logInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(AuditLog.class), logInterceptor);
}
}
`
API
`
@slf4j
@path("/system/user")
public class SysUserApi {
@get
@path("/list")
@produces("application/json")
@RolesAllowed("system:user:list")
public TableDataInfo list(@QueryParam("user") SysUser user, @context HttpServerRequest request) {
startPage(request);
List list = userService.selectUserList(user);
return getDataTable(list);
}
@get
@path("/export")
@produces("application/json")
@RolesAllowed("system:user:export")
@auditlog(title = "export")
public AjaxResult export(@QueryParam("user") SysUser user) {
List list = userService.selectUserList(user);
ExcelUtil util = new ExcelUtil(SysUser.class);
return util.exportExcel(list, "data", downloadPath);
}
`
Result:
version, rest vertx 0.8.9
- without the @auditlog, the route is correct.
[INFO] Registering route: GET /system/user/export
[INFO] Registering route: GET /system/user/list - with the the @auditlog, the route is incorrect.
[INFO] Registering route: GET /system/user/export
[INFO] Registering route: GET /list/list - all route has @auditlog, the route is correct too.
[INFO] Registering route: GET /system/user/export
[INFO] Registering route: GET /system/user/list