¿Es posible utilizar Guice AOP para interceptar un método anotado en un recurso de Jersey?Interceptación del método en Jersey utilizando Guice AOP
Tengo una integración de Guice configurada con éxito que trabaja con Jersey con respecto a la Inyección de Dependencia sin ningún problema, sin embargo, mi Interceptor configurado no está interceptando mi método anotado en absoluto.
web.xml
<listener>
<listener-class>my.package.GuiceConfig</listener-class>
</listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
módulo de configuración GuiceConfig
public class GuiceConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
return Guice.createInjector(new JerseyServletModule() {
@Override
protected void configureServlets() {
bindInterceptor(Matchers.any(),
Matchers.annotatedWith(RequiredAuthority.class),
new AuthorisationInterceptor());
Map<String, String> params = new HashMap<String, String>();
params.put(JSP_TEMPLATES_BASE_PATH, "/WEB-INF/jsp");
params.put(FEATURE_FILTER_FORWARD_ON_404, "true");
params.put(PROPERTY_PACKAGES, "my.service.package");
filter("/*").through(GuiceContainer.class, params);
}
});
}
}
RequiredAuthority anotación
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiredAuthority {
String value();
}
AuthorisationInterceptor aspecto
public class AuthorisationInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
// Allow invocation to process or throw an appropriate exception
}
}
clase de recurso TempResource JAX-RS
@Path("/temp")
public class TempResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
@RequiredAuthority("PERMISSION")
public String getTemp() {
// Return resource normally
}
}
tarde a la fiesta, pero se parece a ['@ BindingAnnotation'] (http://google-guice.googlecode.com/git/javadoc/com/google/inject/BindingAnnotation. html) también falta en 'RequiredAuthority'. –
Gracias, sí, esto también causó un problema en ese momento. Vale la pena señalar aquí. – Kynth