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

Monday, November 23, 2009

OpenWebBeans and Java SE Project

Hi;

Today, we will learn how to easily use OpenWebBeans Container in a standalone mavenized Java Projects.

To use OpenWebBeans in a standalone project, just add the custom "openwebbeans.properties" file into your project classpath location that is "src/main/resources/META-INF/openwebbeans/" folder.

Content of the openwebbeans.properties file will be:

#Use Static HashMap
org.apache.webbeans.spi.JNDIService=org.apache.webbeans.spi.se.JNDIServiceStaticImpl

# Non Transactional
org.apache.webbeans.spi.TransactionService=org.apache.webbeans.spi.se.TransactionServiceNonJTA

#use the web metadata as default
org.apache.webbeans.spi.deployer.MetaDataDiscoveryService=org.apache.webbeans.spi.se.deployer.MetaDataDiscoveryStandard

#Lifecycle to start container
org.apache.webbeans.spi.Lifecycle=org.apache.webbeans.lifecycle.StandaloneLifeCycle

Add "beans.xml" file into your "src/main/resources/META-INF/beans.xml" as a marker file. That is it! Now, You can use dependency injection service from your standalone Java Projects .

For example:
public class Boot
{ 
 private static BeanManager beanManager;

public void start()
{
 //Boot container
 Lifecycle lifecycle = LifecycleFactory.getInstance().getLifecycle();         
 lifecycle.applicationEnded(null);    

 beanManager = lifecycle.getBeanManager();  
}

public void stop()
{
 //Stop container
 Lifecycle lifecycle = LifecycleFactory.getInstance().getLifecycle();         
 lifecycle.applicationStarted(null);      
}

public static void main(String args[])
{
  Boot boot = new Boot();
  boot.start();

  //USE YOUR BeanManager in your code for injections

 }
}

That is cool Hah :)

Cheers;

Wednesday, November 18, 2009

Introducing the Open Web Foundation Agreement

Hi;

As I am member of the Open Web Foundation, I would like to inform you that OWF has created its license agreement that is applied to web related specifications. Below is excerpted from the announcement page :

The Open Web Foundation is pleased to announce the availability of the Open Web Foundation Agreement (OWFa).

The Open Web Foundation was founded to help developer communities collaborate and share technical innovation on the web, bringing to the world of formats and protocols the same successful grassroots approaches established by the open source community. Modeled after the Apache Software Foundation and Creative Commons, the Open Web Foundation seeks to facilitate the creation and implementation of specifications with legal agreements that make such work simple, safe, and sustainable.

You could get detailed information from http://openwebfoundation.org/2009/11/introducing-the-open-web-foundation-agreement.html

Thursday, October 29, 2009

OpenWebBeans Injection Service in Embeddable Apache OpenEJB

Hi;

In this post, I would like to give a simple tutorial on how to use the OpenWebBeans Dependency Injection service in an embeddable EJB container (Apache OpenEJB within Apache Tomcat 6.X).

This tutorial shows how to deploy and run sample web application that is located at "
https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/samples/ejb-telephone/
".

Sample example simulates a simple telephone contact list. It has two main functionality

1* Add new telephone contact.
Adds a new telephone contact record into the database.

2* Show telephone contacts
Shows all contacts in a table.

Configuration Steps

1* If your system does not have Maven and Java Development Kit Version 6 (JDK 6).
Install maven and java 6 sdk into your system.
Configure your classpath so "mvn" and "java" commands can be run from any location.

2* Checkout OpenWebBeans development code from SVN trunk.

1.1)Checkout source code into the folder openwebbeans.
svn co https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/ openwebbeans

1.2)Compile and install it using maven command
cd openwebbeans;
mvn clean install;

If there is no errors, all jars are nstalled into respective "target" folders of the projects.

3* Download Tomcat 6.X version, (you can download Tomcat from http://tomcat.apache.org/download-60.cgi)

4* Download and configure OpenEJB. Look at the URL http://openejb.apache.org/tomcat.html for OpenEJB installation steps.

5* Copy "atinject-api-1.0.0-incubating-SNAPSHOT.jar" from "openwebbeans/atinject-api/target" to Tomcat "/lib" folder.

6* Copy "openwebbeans-api-1.0.0-incubating-SNAPSHOT.jar" from "openwebbeans/webbeans-api/target" to Tomcat "/lib" folder.

After completing the above configuration steps successfully, our OpenEJB+Tomcat embeddable container is ready to use.


OpenWebBeans Configuration

To use the OpenWebBeans in an OpenEJB+Tomcat, it requires some configuration. OpenWebBeans has lots of configuration parameters. You can override all of them with an properties file. (You can look at https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/readme/README_M3.txt for further details).

OpenWebBeans default properties can be overriden by using a "openwebbeans.properties" file locating at the classpath of an application.

1* Create a "META-INF/openwebbeans/openwebbeans.properties" in your web application classpath.(Its location will be "java/main/resources" in a mavenized web application.)

2* Add the following [key,value] pairs into the "openwebbeans.properties" file. This enables EJB functionality and resource injection service in the web project, for example injection of @PersistenceContext, @PersistenceUnit, @Resource etc.

#use embedded openejb metadata discovery
org.apache.webbeans.spi.deployer.UseEjbMetaDataDiscoveryService=true

#use resource service
org.apache.webbeans.resource.spi.ResourceService=org.apache.webbeans.spi.ee.openejb.resource.OpenEjbResourceServiceImpl


Maven Based Web Application Configuration

Web Application Configuration

Create a web application using maven archetype. Look at the code in the "ejb-telephone" sample.

It uses "tomcat-maven-plugin" to deploy the web application into a running tomcat instance.

The web application directory structure look like this;
telephone
   src
   main
      java
      resources
       META-INF
        openwebbeans
         openwebbeans.properties --> OWB specific file
         beans.xml
         persistence.xml --> JPA specific file
     WebContent
       WEB-INF
         beans.xml
         web.xml
         faces-config.xml --> JSF Specific file
     contact.xhtml
     index.html


Compile And Deploy

Source code of the telephone application can be found at the "openwebbeans/samples/ejb-telephone".

Tomcat plugin uses http://localhost:8080/manager application to deploy war file
into your embeddable EJB Tomcat container. There must be an tomcat-users.xml
file in the "conf" directory of the Tomcat server that contains manager role and username.

Example tomcat-users.xml file

<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="" roles="manager"/>
</tomcat-users>

>Start Tomcat server if not started
>cd Tomcat_Directory/bin;
>catalina.sh (or catalina.bat) run;
>mvn clean tomcat:deploy;

If everything goes well, hit the location in your favorite browser

Ejb Sample URL : http://localhost:8080/ejb-telephone.


Enjoy!

Sunday, October 25, 2009

Using JSF2 Ajax with OpenWebBeans

Hi;

I have created a simple JSF2 Ajax sample using OpenWebBeans. First update trunk and do following

Source Location is :

https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/samples/jsf2sample/

Run : mvn clean jetty:run

URL : http://localhost:8080/jsf2sample

Enjoy!

Sunday, October 18, 2009

Using OpenWebBeans in Java SE

You can use OpenWebBeans dependency injection service in Java SE (for example Java Swing) project. New sample project is added to SVN trunk that shows how to use OpenWebBeans in Swing applications.

Source of the module is under "trunk/samples/standalone-sample".

Firstly you run mvn:install from the "trunk" to install/update necessary modules.

Then;

>> cd samples/standalone-sample;
>> mvn clean package;

This creates a jar in "target/standalone-sample.jar"
>> unjar this into any folder
>> java -jar standalone-sample-1.0.0-incubating-SNAPSHOT.jar Boot

It shows simple login screen :)

Cheers;

OpenWebBeans Pass JSR-330 TCK

After struggling some weird errors, we have finally passed JSR-330 TCK test suite.

You can check out sources from "/trunk/atinject-tck" module. It depends on new module "trunk/webbeans-porting" module.

>>cd atinject-tck;
>>mvn test;

Or from "trunk/"
>>mvn test -Pjsr330tck.

SVN Location : https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/

Cheers;

Sunday, September 27, 2009

News from OpenWebBeans

Hi;

Apache OpenWebBeans team has released Milstone-1(M1) and Milestone-2(M2) successfully. It is now under vote at Apache to release Milestone-3 (M3). M3 covers most of the specification requirements. M3 Features will include;

--------------------------------
OpenWebBeans M3 Release Features
--------------------------------

- M3 Release Supports the followings
-----------------------------------
* Managed Beans Support
* Session Beans Support (via Embeddable OpenEJB container in Tomcat)
* Producer Method Support
* Producer Field Support
* Java EE Resource Injection Support
* JMS OpenWebBeans Support(OWB Specific)
* Inheritance, Stereotype Inheritances
* Specialization Support
* Event Support
* Decorator and Interceptor Support
* Lookup and Dependency Injection Support
* Java EE Plugin Support (via ServetContextListener interface)
* Portable Integration Support

You can look at detailed information from the source location
http://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/readme/README_M3.txt

We are always looking for new committers to help creating an Apache Licensed JSR-299 implementation. You could look current jira issues from
https://issues.apache.org/jira/browse/OWB.

More information about the project can be found here:

[Incubation Status Page ] :
http://incubator.apache.org/projects/openwebbeans.html

[Project Page] :
http://incubator.apache.org/openwebbeans/1.0.0-SNAPSHOT/index.html

[Wiki Page] :
http://cwiki.apache.org/OWB/

[Blog] :
http://blogs.apache.org/OWB/

Nice day,

Gurkan