Monday, December 21, 2009

Using Interceptors with OpenWebBeans

OpenWebBeans has a good support for interceptors. Interceptors are generally used for handling cross-cutting concerns of the application. OpenWebBeans supports 2 different interceptors configuration:
  1. Using "javax.interceptor.Interceptors" based,
  2. Using "javax.interceptor.Interceptor" with "javax.interceptor.InterceptorBinding" (This is defined by JSR-299),
  3. Use both of them. (InterceptorBinding based interceptors are called after calling Interceptors.)
You can use any of them within your web or standalone application. For example,

public class  Login{}
public class LogInterceptor {   
     public Object log(InvocationContext context) throws Exception{}

public class Login{....} with interceptor class and interceptor binding type@Log.

@Log  @Interceptor
public class LogInterceptor{
      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.


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!

No comments: