In the previous Part1 , I have introduced how to integrate Apache Aries Application(EBA) into Glassfish. And in the Part1, I used a simple sample to demonstrate such an integration. However, in a real world, an user’s application can be very complex and typically be made up of EJB, JPA,Servlet,CDI,JAX-RS…. So, you can ask me whether I can use these skills in an EBA and deploying the EBA into Glassfish successfully?
The answer is Yes!
Firstly, an EBA can be made up of EJB Bundles, an WAB, other OSGi Bundles.
Secondly, by using hybrid OSGi-JavaEE(EJB Bundles and WAB) , an user can use powers from both JavaEE and OSGi.
Thirdly, we can deploy such an EBA with JEE capability into Glassfish successfully.
Next, let us see an concrete example. As a prerequisite, please building a glassfish with Aries Application Bundles based on Part1.
Then, we can build such a EBA with JEE based on Fighterfish UAS Sample[1] .
[1]: https://svn.java.net/svn/glassfish~svn/trunk/fighterfish/sample/uas
[Wrapping UAS Sample into EBA]
1. Create a directory called “ebawithjee”
2. Creating a pom.xml file and adding the following important contents,
...<modelVersion>4.0.0</modelVersion>
<groupId>cn.fujitsu.com.tangyong</groupId>
<artifactId>ebawithjee.application</artifactId>
<packaging>eba</packaging>
<version>1.0.0</version>
<name>Glassfish Ear Bundle With JEE</name>
<dependencies>
<dependency>
<groupId>org.glassfish.fighterfish</groupId>
<artifactId>sample.uas.api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.fighterfish</groupId>
<artifactId>sample.uas.entities</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.fighterfish</groupId>
<artifactId>sample.uas.ejbservice</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.fighterfish</groupId>
<artifactId>sample.uas.simplewab</artifactId>
<version>1.0.0</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.aries</groupId>
<artifactId>eba-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<generateManifest>false</generateManifest>
</configuration>
</plugin>
...
Here, we select the following bundles from UAS Sample,
1) sample.uas.api
Providing an interface called “UserAuthService”
2) sample.uas.entities
Creating EntityManagerFactory and persisting/finding user’s registration data.
3) sample.uas. ejbservice
Defining a stateless session bean with local view, and the ejb implements UserAuthService interface.
4) sample.uas.simplewab
This is a WAB using Servlet 3.x and uses Glassfish OSGi/CDI skill to obtain UserAuthService. Eg, seeing the following,
@Inject @OSGiService(dynamic=true)
private UserAuthService uas;
Among the above bundles, 1) and 2) are common OSGi bundles, 3) are EJB Bundle, 4) is a WAB.
3. executing “mvn clean install”
This will generate an EBA file(seeing the attachment) with the above UAS Sample Bundles.
Download Ebawithjee.application-1.0.0
[Deploying EBA into Glassfish]
1. executing “asadmin start-database”
2. setting the following in glassfish/config/osgi.properties
org.glassfish.osgjpa.extension.useHybridPersistenceProviderResolver=true
Defaultly, the value is false. Because we will use JPA in sample.uas.entities bundle, so we must set the value is true. Otherwise, you will see http://java.net/jira/browse/GLASSFISH-20345
3. executing “asadmin start-domain”
4. deploying the EBA with JEE into Glassfish
putting the EBA into glassfish/domains/domain1/autodeploy/bundles directory.
5. executing “asadmin osgi lb”
Seeing whether deploying is successful, of course, we also should see whether any exception happened server.log.
From
the above image, we can find that deploying has been successful.
[Running The EBA]
From your favorite browser, accessing http://localhost:8080/uas/index.jsp
And click “register”and “login”to see whether you are “Welcome”, :)
Good luck to you!