- Using "javax.interceptor.Interceptors" based,
- Using "javax.interceptor.Interceptor" with "javax.interceptor.InterceptorBinding" (This is defined by JSR-299),
- Use both of them. (InterceptorBinding based interceptors are called after calling Interceptors.)
@Interceptors(LogInterceptor.class)
@RequestScoped
public class Login{}
public class LogInterceptor {
@AroundInvoke
public Object log(InvocationContext context) throws Exception{}
}
OR
@Log
@RequestScoped
public class Login{....} with interceptor class and interceptor binding type@Log.
@Log @Interceptor
public class LogInterceptor{
@AroundInvoke
public Object log(InvocationContext context) throws Exception{}
}
To use Interceptor Binding Type version, you have to define interceptor class in a "beans.xml" file of your application.
<beans>
<interceptors>
<class>LoginInterceptor</class>
</interceptors>
</beans>
The good news is that you can even use interceptors in a pure Java SE or Java Web application :)
Lightweight Dependency Injection <--> OpenWebBeans
PS: Currently OpenWebBeans does not support interceptors for @Dependent scoped beans! But it is under active development and included with the next version!
Stay tune!
--Gurkan
