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,

@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

Using OpenWebBeans in Web Containers

Hi;

OpenWebBeans has been developing as a modular and pluggable way from the start. Core "Dependency Injection" functionality is not dependent on any Java EE requirements. Therefore, it can be configured easily to work on any Java Web Containers like Tomcat, Jetty etc. or Java SE like Swing.

To configure OpenWebBeans in a web application based on JSP or JSF,
  1. Put empty "beans.xml" marker file into "WEB-INF" directory of the web application
  2. Update your web application "web.xml" file with following snippet
      <listener>
      <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
       </listener>

That is all! Now you can use JSR-299 functionality in your application.

Stay with OpenWebBeans :)

--Gurkan

Thursday, December 17, 2009

OpenWebBeans Has Graduated!

Hey there,

Today Apache Incubator OpenWebBeans has become Apache TLP (Top Level Project of Apache Foundation). Thanks to all of our community and mentors for their great support! In Apache Terms, OpenWebBeans has graduated from incubation successfully!

It takes more than one year living in Incubator with delivering 3 releases. Personally, I learned lots of new things about how to develop/implement and manage open source project while working on the OWB under the incubation. As the main motivation for Apache Incubation is to learn Apache Way,  I believe that I have very experienced with it.

After now, we will be working on producing a cool "Dependency Injection" framework that will be used in both Java EE and Java SE environments. Besides it implements JSR-299 and JSR-330 specifications, we will create a bunch of useful extensions that are related with other Apache Projects. For example, altough JSR-299 does not define Java Messaging Service artifacts injections, OWB provides injection of JMS artifacts like ConnectionFactory, Queue, Topic, Session etc.

Have a nice day

--Gurkan