Interceptor not called
pelikast Apr 18, 2014 5:23 AMHello,
I'm using JBoss 7.2.0 and I want to install a bean-method-interceptor for a restful webservice (for logging-purpose). I did all as described in many tutorials, but the interceptor isn't called. If I add an @Interceptors annotation, the interceptor is called.
My files are
Logged.java:
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Logged {
}
LoggedInterceptor.java:
@Logged
@Interceptor
public class LoggedInterceptor {
public LoggedInterceptor() {
}
@AroundInvoke
public Object logMethodEntry(InvocationContext invocationContext)
throws Exception {
System.out.println("HE Entering method: "
+ invocationContext.getMethod().getName() + " in class "
+ invocationContext.getMethod().getDeclaringClass().getName());
return invocationContext.proceed();
}
}
MyRestfulService.java:
@Named
@Path("/myrestfulservice")
@RequestScoped
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
//@Interceptors({LoggedInterceptor.class})
public class MyRestfulService extends AnyOfBaseClass {
@POST
@Logged
public GroupedResponse<TariffSelectionResponse> execute(
TariffSelectionInput input) {
// any functionality
}
}
WEB-INF/beans.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all" version="1.1"> <interceptors> <class>interceptorpackage.LoggedInterceptor</class> </interceptors> </beans>
The interceptor-method should be invoke on calling the restful service. If I remove the comment in MyRestfulService.java
@Interceptors({LoggedInterceptor.class})
it works. But I need loose coupling for testing and reusing.
Any suggestions? I cannot imagine that this does not work. I'm sure I forgot something but I cannot find it.
Comments:
- It is not possible to upgrade to WildFly because I use a commercial library in this project which is not yet ported. So I stick to jboss 7.2.0.
- Maybe this is relevant: The webservice is part of a war which is packed into an ear.
Thanks,
Stephan