SeamFramework.orgCommunity Documentation
Websphere AS V7 is IBM's application server offering. This release is fully Java EE 5 certified.
First we will go over some basic information about the Websphere AS environment that we used for these examples. We will go over the details of those steps with the JEE5 booking example. We will also deploy the JPA example application.
Websphere AS is a commercial product and so we will not discuss the details of its installation other than to say follow the directions provided by your particular installation type and license. This section will detail the exact server versions used, installation tips, and some custom properties that are needed for all of the examples.
All of the examples and information in this chapter are based on the version V7 of Websphere AS at the time of this writing.
After installing Websphere AS, create server profile with Profile Management Tool, if you didn't create profile in installation process.
The jee5/booking
example is based on the Hotel
Booking example (which runs on JBoss AS). Out of the box it is designed
to run on Glassfish, but with the steps below it can be deployed to
Websphere. It is located in the
$SEAM_DIST/examples/jee5/booking
directory.
Below are the configuration file changes that are need to the base example.
resources/WEB-INF/components.xml
We need to change the way that we look up EJBs for
WAS. We need to remove the
/local
from the end of the
jndi-pattern
attribute. It should
look like this:
<core:init jndi-pattern="java:comp/env/jboss-seam-jee5/#{ejbName}" debug="true"/>
resources/META-INF/ejb-jar.xml
We need to replace the /local string from ejb-ref-name
.
See at the following final code:
<enterprise-beans>
<!-- EJB reference required when one Seam EJB component references another Seam EJB component using @In -->
<!-- Not required if you inject using @EJB, but then you lose state management and client-side interceptors (e.g., security) -->
<session>
<ejb-name>RegisterAction</ejb-name>
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/AuthenticatorAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.Authenticator</local>
</ejb-local-ref>
</session>
</enterprise-beans>
resources/WEB-INF/web.xml
We have to make some changes to the EJB references
in the web.xml
. These changes are
what will allow WAS to bind automatically the EJB3 references in
the web module to the the actual EJB3 beans in the EAR
module. Replace all of the /local strings in
ejb-local-refs
when the values
below.
<!-- JEE5 EJB3 names -->
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/AuthenticatorAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.Authenticator</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/BookingListAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.BookingList</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/RegisterAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.Register</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/ChangePasswordAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.ChangePassword</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/HotelBookingAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.HotelBooking</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/HotelSearchingAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.HotelSearching</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>jboss-seam-jee5/EjbSynchronizations</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
</ejb-local-ref>
Note also that EjbSynchronizations
is
a built-in Seam EJB and not part of the Hotel Booking example. This
means that if your application's components.xml
specifies transaction:ejb-transaction
,
then you must include:
<ejb-local-ref>
<ejb-ref-name>myapp/EjbSynchronizations</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home></local-home>
<local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
</ejb-local-ref>
in your web.xml. If you don't include it, you'll get the following error:
Name comp/env/myapp/EjbSynchronizations not found in context java:
resources/META-INF/persistence.xml
For this example we will be using the default
datasource that comes with WAS. To do this change the
jta-data-source
element:
<jta-data-source>DefaultDatasource</jta-data-source>
Then we need to adjust some of the hibernate properties. First comment out the Glassfish properties. Next you need to add/change the properties:
<!--<property name="hibernate.transaction.flush_before_completion" value="true"/>-->
<property name="hibernate.cache.provider_class"
value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.dialect" value="GlassfishDerbyDialect"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
hibernate.transaction.manager_lookup_class
— Standard Hibernate transaction
manager property for WAS 6.X and 7
hibernate.transaction.flush_before_completion
— This is commented out because we want
the container to manage the transactions. Also
if this is set to true
an
exception will be thrown by WAS when the
EJBContext is looked up.
com.ibm.wsspi.injectionengine.InjectionException: EJBContext may only be looked up by or injected into an EJB
hibernate.dialect
— From WAS 6.1.0.9 on the embedded DB was
switched to the same Derby DB as is in
Glassfish v2.
src/GlassfishDerbyDialect.java
You will need to get the
GlassfishDerbyDialect.java
and
copy it into the /src
directory. The java class exists in the JPA example source directory and can be
copied using the command below assuming you are in
jee5/booking
directory:
cp ../../jpa/src/GlassfishDerbyDialect.java ./src
This class will be put into the
jboss-seam-jee5.jar
file.
resources/import.sql
This file must also be copied from the JPA example
because either the Derby DB or the dialect does not support
changes to the ID
column. The files
are identical except for the column difference. Use the
following command to make the copy
cp ../../jpa/resources-websphere7/import.sql ./resources
In order to get the changes we have made into our application we
need to make some changes to the build.xml
.
There are also some additional jars that are required by our
application in order to work with WAS. This section will cover
what changes are needed to the build.xml
.
We remove the log4j.jar
so that all of the log output from our application will
be added to the WAS log. Additional steps are
required to fully configure log4j and those are outside
of the scope of this document.
Add the following entry to the bottom of the
build.xml
file. This overrides the
default fileset that is used to populate the
jboss-seam-jee5.jar
.
:
<fileset id="jar.resources" dir="${resources.dir}">
<include name="import.sql" />
<include name="seam.properties" />
<include name="META-INF/persistence.xml" />
<include name="META-INF/ejb-jar.xml" />
</fileset>
Now all that is left is to execute the ant
archive
task and the built application will be in
the jee5/booking/dist
directory.
So now we have everything we need in place. All that is left is to deploy it - just a few steps more.
For this we will use Websphere's administration console. As before there are some tricks and tips that must be followed.
The steps below are for the WAS version stated above. The ports are default values, if you changed them substitute your values.
Log in to the administration console
https://localhost:9043/admin
or
http://localhost:9060/admin
Access the Websphere enterprise
applications
menu option under the
Applications --> Application Type
left side menu.
At the top of the Enterprise
Applications
table select
Install
. Below are installation
wizard pages and what needs to done on each:
Preparing for the application
installation
Browse to the
examples/jee5/booking/dist/jboss-seam-jee5.ear
file using the file upload widget.
Select the
Next
button.
Select the
Fast Path
button.
Select the
Next
button.
Select installation
options
Select the Deploy
enterprise beans
and
Allow EJB reference targets to resolve automatically
check boxes. This is needed unless you
used a Websphere AS tool to package the
application.
Select the
Next
button.
Map modules to
servers
No changes needed here as we only
have one server. Select the
Next
button.
Summary
No changes needed here. Select
the Finish
button.
Installation
Now you will see it installing and deploying your application.
When it finishes select the
Save
link and
you will be returned to the
Enterprise
Applications
table.
Now that we have our application installed we need to make some adjustments to it before we can start it:
Starting from the Enterprise
Applications
table select the
Seam Booking
link.
Select the Manage
Modules
link.
Select the
jboss-seam-jee5-booking.war
link.
Change the Class loader
order
combo box to
Classes loaded with application
class loader first (parent last)
.
Select Apply
and then
Save
options.
Return to the Seam Booking
page.
On this page select the Class
loading and update detection
link.
Select the radio button for
Classes loaded with application
class loader first
.
Select Apply
and then
Save
options.
To start the application return to the
Enterprise Applications
table and
select our application in the list. Then choose the
Start
button at the top of the
table.
You can now access the application at
http://localhost:9080/seam-jee5-booking/index.html
.
Thankfully getting the jpa
example to work is
much easier than the jee5
example. This is the
Hotel Booking example implemented in Seam POJOs and using Hibernate JPA
with JPA transactions. It does not use EJB3.
The example already has a breakout of configurations and build scripts for many of the common containers including Websphere.
First thing we are going to do is build and deploy that example. Then we'll go over some key changes that we needed.
Building it only requires running the correct ant command:
ant websphere7
This will create container specific distribution and exploded
archive directories with the websphere7
label.
This is similar to the jee5
example at
Section 40.2.3, “Deploying the application to Websphere”, but without so many steps.
From the Enterprise Applications
table
select the Install
button.
Preparing for the application
installation
Browse to the
examples/jpa/dist-websphere7/jboss-seam-jpa.war
file using the file upload widget.
Select the
Fast Path
button.
Select the
Next
button.
Select the Next
button for the next
three pages, no changes are needed.
Map context roots for Web modules
In the Context root
text box
enter jboss-seam-jpa
.
Select the Next
button.
Summary
page
Review the settings if you wish and select
the Finish
button to install
the application. When installation finished select the
Save
link and you will be returned to the
Enterprise Applications
table.
As with the jee5
example there are some
class loader changes needed before we start the application.
Follow the instructions at installation adjustments for jee5 example
but exchange jboss-seam-jpa_war
for Seam Booking
.
Finally start the application by selecting it in the
Enterprise Applications
table and clicking
the Start
button.
You can now access the application at the
http://localhost:9080/jboss-seam-jpa/index.html
.
The differences between the JPA examples that deploys to JBoss 4.2 and Websphere AS V7 are mostly expected; library and configuration file changes.
Configuration file changes
META-INF/persistence.xml
— the main changes here are for the
datasource JNDI path, switching to the Websphere
transaction manager look up class, and
changing the hibernate dialect to be
GlassfishDerbyDialect
.
WEB-INF/components.xml
— the change here is jndi-pattern
without /local string.
META-INF/ejb-jar.xml
— the same change in ejb-ref-name
,
where is replace /local string in
jboss-seam-jee5/AuthenticatorAction
.
src/GlassfishDerbyDialect.java
— this class is needed for the
hibernate dialect change to
GlassfishDerbyDialect
import.sql
—
either for the dialect or Derby DB the
ID
column can not be
populated by this file and was removed.
Changes for dependent libraries
The Websphere version requires several library packages because they are
not included as they are with JBoss AS. These are primarily for
hibernate and their dependencies. Below are
listed only the additional jars needed above and beyond the JBoss
JPA
example.
To use Hibernate as your JPA provider you need the following jars:
hibernate.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate-validator.jar
commons-collections.jar
jboss-common-core.jar
Various third party jars that Websphere needs:
antlr.jar
cglib.jar
asm.jar
dom4j.jar
javassist.jar
concurrent.jar
seam-gen
is a very useful tool for developers
to quickly get an application up and running, and provides a foundation
to add your own functionality. Out of box seam-gen
will produce applications configured to run on JBoss AS. These
instructions will show the steps needed to get it to run on Websphere.
As stated above in Section 40.2, “ The jee5/booking
example ” there
are some tricky changes needed to get an EJB3 application running. This
section will take you through the exact steps.
The first step is setting up seam-gen
to
construct the base project. There are several choices made below,
specifically the datasource and hibernate values that we will adjust
once the project is created.
./seam setup Buildfile: build.xml init: setup: [echo] Welcome to seam-gen :-) [input] Enter your Java project workspace (the directory that contains your Seam projects) [C:/Projects] [C:/Projects] /home/jbalunas/workspace [input] Enter your JBoss home directory [C:/Program Files/jboss-4.2.3.GA] [C:/Program Files/jboss-4.2.3.GA] /home/jbalunas/jboss/jboss-4.2.3.GA [input] Enter the project name [myproject] [myproject] websphere_example [echo] Accepted project name as: websphere_example [input] Do you want to use ICEFaces instead of RichFaces [n] (y, [n], ) [input] skipping input as property icefaces.home.new has already been set. [input] Select a RichFaces skin [blueSky] ([blueSky], classic, ruby, wine, deepMarine, emeraldTown, sakura, DEFAULT) [input] Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support) [ear] ([ear], war, ) [input] Enter the Java package name for your session beans [org.jboss.seam. tutorial.websphere.action] [org.jboss.seam.tutorial.websphere.action] org.jboss.seam.tutorial.websphere.action [input] Enter the Java package name for your entity beans [org.jboss.seam. tutorial.websphere.model] [org.jboss.seam.tutorial.websphere.model] org.jboss.seam.tutorial.websphere.model [input] Enter the Java package name for your test cases [org.jboss.seam. tutorial.websphere.action.test] [org.jboss.seam.tutorial.websphere.action.test] org.jboss.seam.tutorial.websphere.test [input] What kind of database are you using? [hsql] ([hsql], mysql, oracle, postgres, mssql, db2, sybase, enterprisedb, h2) [input] Enter the Hibernate dialect for your database [org.hibernate. dialect.HSQLDialect] [org.hibernate.dialect.HSQLDialect] [input] Enter the filesystem path to the JDBC driver jar [/tmp/seam/lib/hsqldb.jar] [/tmp/seam/lib/hsqldb.jar] [input] Enter JDBC driver class for your database [org.hsqldb.jdbcDriver] [org.hsqldb.jdbcDriver] [input] Enter the JDBC URL for your database [jdbc:hsqldb:.] [jdbc:hsqldb:.] [input] Enter database username [sa] [sa] [input] Enter database password [] [] [input] Enter the database schema name (it is OK to leave this blank) [] [] [input] Enter the database catalog name (it is OK to leave this blank) [] [] [input] Are you working with tables that already exist in the database? [n] (y, [n], ) [input] Do you want to drop and recreate the database tables and data in import.sql each time you deploy? [n] (y, [n], ) [propertyfile] Creating new property file: /rhdev/projects/jboss-seam/svn-seam_2_2/jboss-seam-2_2/seam-gen/build.properties [echo] Installing JDBC driver jar to JBoss server [copy] Copying 1 file to /home/jbalunas/jboss/jboss-4.2.3.GA/server/default/lib [echo] Type 'seam create-project' to create the new project BUILD SUCCESSFUL Total time: 3 minutes 5 seconds
Type ./seam new-project
to create your
project and cd
/home/jbalunas/workspace/websphere_example
to the
newly created structure.
We now need to make some changes to the generated project.
resources/META-INF/persistence-dev.xml
Alter the
jta-data-source
to be
DefaultDatasource
. We are
going to be using the integrated Websphere
DB.
Add or change the properties below.
These are described in detail at Section 40.2, “ The jee5/booking
example ”:
<property name="hibernate.dialect" value="GlassfishDerbyDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.cache.provider_class"
value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
Remove the JBoss AS specific method of exposing the EntityManagerFactory:
<property
name="jboss.entity.manager.factory.jndi.name"
value="java:/websphere_exampleEntityManagerFactory">
You'll need to alter
persistence-prod.xml
as
well if you want to deploy to Websphere using the
prod profile.
src/GlassfishDerbyDialect.java
As with other examples we need to include this java class for
DB support. It can be copied from the
jpa
example into the
websphere_example/src
directory.
cp $SEAM/examples/jpa/src/GlassfishDerbyDialect.java ./src
resources/META-INF/jboss-app.xml
You can delete this file as we aren't deploying to JBoss
AS ( jboss-app.xml
is used to enable
classloading isolation in JBoss AS)
resources/*-ds.xml
You can delete these file as we aren't deploying to JBoss AS (these files define datasources in JBoss AS, we are using Websphere's default datasource)
resources/WEB-INF/components.xml
Enable container managed transaction
integration - add the
<transaction:ejb-transaction />
component, and it's namespace
declaration
xmlns:transaction="http://jboss.com/products/seam/transaction"
Alter the jndi-pattern
to
java:comp/env/websphere_example/#{ejbName}
We do not need
managed-persistence-context
for this example and so can delete its
entry.
<persistence:managed-persistence-context name="entityManager"
auto-create="true"
persistence-unit-jndi-name="java:/websphere_exampleEntityManagerFactory"/>
resources/WEB-INF/web.xml
As with the jee5/booking
example we need to add EJB references to the web.xml. These
references require replacing /local string in
ejb-ref-name
to flag them for
Websphere to perform the proper binding.
<ejb-local-ref>
<ejb-ref-name>websphere_example/AuthenticatorAction</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.tutorial.websphere.action.Authenticator</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>websphere_example/EjbSynchronizations</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
</ejb-local-ref>
We want to take the existing Authenticator
Seam POJO component and create an EJB3 out of it.
Change the generated Authenticator class
Rename the class to
AuthenticatorAction
Add the @Stateless
annotation to the new
AuthenticatorAction
class.
Create an interface called
Authenticator
which
AuthenticatorAction
implements (EJB3 requires session beans to have a
local interface). Annotate the interface with
@Local
, and add a single method
with same signature as the
authenticate
in
AuthenticatorAction
.
@Name("authenticator") @Stateless public class
AuthenticatorAction implements Authenticator {
@Local public interface Authenticator {
public boolean authenticate();
}
We've already added its reference to the
web.xml
file so are good to go.
This application has similar requirements as the
jee5/booking
example.
Change the default target to
archive
(we aren't going to cover
automatic deployment to Websphere).
<project name="websphere_example" default="archive" basedir=".">
Websphere looks for the drools
/security.drl
file in the root of the
war
file instead of the root of the
websphere_example.jar
so we need
to have the build.xml
move it to the
correct location at build time. The following must be added at
the top of the <target name="war"
depends="compile" description="Build the distribution
.war file">
target.
<copy todir="${war.dir}">
<fileset dir="${basedir}/resources" >
<include name="*.drl" />
</fileset>
</copy>
Now we need to get extra jars into the
build.xml
. Look for the
<fileset dir="${basedir}">
section
of the task below. Add the new includes at the bottom of
the fileset.
<target name="ear" description="Build the EAR">
<copy todir="${ear.dir}">
<fileset dir="${basedir}/resources">
<include name="*jpdl.xml" />
<include name="*hibernate.cfg.xml" />
<include name="jbpm.cfg.xml" />
</fileset>
<fileset dir="${basedir}">
<include name="lib/jbpm*.jar" />
<include name="lib/jboss-el.jar" />
<include name="lib/drools-*.jar"/>
<include name="lib/core.jar"/>
<include name="lib/janino*.jar"/>
<include name="lib/antlr-*.jar"/>
<include name="lib/mvel*.jar"/>
<include name="lib/richfaces-api*.jar" />
</fileset>
</copy>
<copy todir="${ear.dir}/META-INF">
<fileset dir="${basedir}/resources/META-INF">
<include name="application.xml" />
<include name="jboss-app.xml" />
</fileset>
</copy>
</target>
Hibernate dependencies
<!-- Hibernate and deps -->
<include name="lib/hibernate.jar"/>
<include name="lib/hibernate-commons-annotations.jar"/>
<include name="lib/hibernate-annotations.jar"/>
<include name="lib/hibernate-entitymanager.jar"/>
<include name="lib/hibernate-validator.jar"/>
<include name="lib/jboss-common-core.jar" />
Third party dependencies.
<!-- 3rd party and supporting jars -->
<!--<include name="lib/log4j.jar" />-->
<include name="lib/javassist.jar"/>
<include name="lib/dom4j.jar" />
<include name="lib/concurrent.jar" />
<include name="lib/cglib.jar"/>
<include name="lib/asm.jar"/>
<include name="lib/antlr.jar" />
<include name="lib/commons-logging.jar" />
<include name="lib/commons-collections.jar" />
jboss-seam.jar
- this is needed in
the ear
base
directory.
<!-- seam jar -->
<include name="lib/jboss-seam.jar" />
You should end up with something like:
<fileset dir="${basedir}">
<include name="lib/jbpm*.jar" />
<include name="lib/jboss-el.jar" />
<include name="lib/drools-*.jar"/>
<include name="lib/core.jar"/>
<include name="lib/janino*.jar"/>
<include name="lib/antlr-*.jar"/>
<include name="lib/mvel*.jar"/>
<include name="lib/richfaces-api*.jar" />
<!-- Hibernate and deps -->
<include name="lib/hibernate.jar"/>
<include name="lib/hibernate-commons-annotations.jar"/>
<include name="lib/hibernate-annotations.jar"/>
<include name="lib/hibernate-entitymanager.jar"/>
<include name="lib/hibernate-validator.jar"/>
<include name="lib/jboss-common-core.jar" />
<!-- 3rd party and supporting jars -->
<include name="lib/javassist.jar"/>
<include name="lib/dom4j.jar" />
<include name="lib/concurrent.jar" />
<include name="lib/cglib.jar"/>
<include name="lib/asm.jar"/>
<include name="lib/antlr.jar" />
<include name="lib/commons-logging.jar" />
<include name="lib/commons-collections.jar" />
<!-- seam jar -->
<include name="lib/jboss-seam.jar" />
</fileset>
Build your application by calling
ant
in the base directory of your
project (ex.
/home/jbalunas/workspace/websphere_example
). The target of the build will be
dist/websphere_example.ear
.
To deploy the application follow the instructions here :
Section 40.2.3, “Deploying the application to Websphere” but use references to
this project websphere_example
instead of
jboss-seam-jee5
.
Checkout the app at:
http://localhost:9080/websphere_example/index.html