J2EE Websphere Integration

  GigaSpaces 5.X

Documentation Home
Quick Start Guide
Release Notes

Previous release

  Search Here
Searching GigaSpaces Platform 5.X Documentation

                                               

Summary: Installing WSAD; using correct JDK and JRE; ReplicatedSessionBean object; configuring server for an application; GigaSpaces WebSphere demo.

Overview

This section describes required steps for building J2EE Web applications with IBM WebSphere 5 and GigaSpaces. WebSphere will be used as part of WebSphere Studio Application Developer (WSAD 5.1.2).
A simple demo is accompanied to this document demonstrates flow and relevant components integration to provide access into GigaSpaces API.

WSAD 5 Download

WebSphere Studio Application Developer for Windows (WSAD 5.1.2) Download:
http://www-128.ibm.com/developerworks/websphere/downloads/wsad/

JDK

Make sure to use the WebSphere 5 JDK and not the default one comes with eclipse. This is required when building Java clients that access WebSphere.

Select from main menu Window->Preferences:

The Preferences window will open. Select the Java->Installed JREs.

Select the WebSphere JRE to be your default JRE.
Click OK.

Importing ReplicatedSessionBean into WSAD 5 workspace

You will need to introduce GigaSpaces ReplicatedSessionBean EAR to your WSAD workspace.

The ReplicatedSessionBean EAR must be build prior launching this example by running the ear.bat/sh script located at <GigaSpaces ROOT>\J2EE\examples\ReplicatedSessionBean.
Make sure you run the script using JDK 1.4!

Running the ear.bat/sh script should display the following output:

JAVA_HOME environment variable is set to D:\JDK\j2sdk1.4.2_08 in "<GigaSpaces Root>\bin\setenv.bat"
Environment set successfully from D:\GigaSpacesEE5.0\bin\\..
------------------------------------------------------------------------------------------
ensuring that we are working on the latest jar and config files from product distribution
------------------------------------------------------------------------------------------
Could Not Find D:\GigaSpacesEE5.0\j2ee\examples\ReplicatedSessionBean\lib
        1 file(s) copied.
D:\GigaSpacesEE5.0\bin\\..\lib\jini\browser-dl.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\browser.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\jsk-dl.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\jsk-lib.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\jsk-platform.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\jsk-policy.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\jsk-resources.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\mahalo-dl.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\mahalo.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\reggie-dl.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\reggie.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\start.jar
D:\GigaSpacesEE5.0\bin\\..\lib\jini\tools.jar
       13 file(s) copied.
Deleted file - D:\GigaSpacesEE5.0\j2ee\examples\ReplicatedSessionBean\lib\jini\browser.jar
Deleted file - D:\GigaSpacesEE5.0\j2ee\examples\ReplicatedSessionBean\lib\jini\browser-dl.jar
Deleted file - D:\GigaSpacesEE5.0\j2ee\examples\ReplicatedSessionBean\lib\jini\tools.jar
D:\GigaSpacesEE5.0\bin\\..\lib\rio\boot.jar
D:\GigaSpacesEE5.0\bin\\..\lib\rio\webster.jar
        2 file(s) copied.
        1 file(s) copied.
        1 file(s) copied.
-------------------------------------
Creating ReplicatedSessionBean.jar ..
-------------------------------------
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
added manifest
ignoring entry META-INF/
adding: META-INF/application.xml(in = 528) (out= 292)(deflated 44%)
adding: META-INF/ejb-jar.xml(in = 917) (out= 409)(deflated 55%)
adding: META-INF/ibm-ejb-jar-bnd.xmi(in = 576) (out= 316)(deflated 45%)
adding: META-INF/ibm-ejb-jar-ext.xmi(in = 490) (out= 256)(deflated 47%)
adding: META-INF/jboss.xml(in = 187) (out= 106)(deflated 43%)
ignoring entry META-INF/MANIFEST.MF
adding: META-INF/orion-ejb-jar.xml(in = 352) (out= 216)(deflated 38%)
adding: META-INF/sun-ejb-jar.xml(in = 553) (out= 328)(deflated 40%)
adding: META-INF/sun-j2ee-ri.project(in = 241) (out= 139)(deflated 42%)
adding: META-INF/weblogic-ejb-jar.xml(in = 452) (out= 251)(deflated 44%)
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/j_spaces/(in = 0) (out= 0)(stored 0%)
adding: com/j_spaces/examples/(in = 0) (out= 0)(stored 0%)
adding: com/j_spaces/examples/ModelClass.class(in = 1624) (out= 863)(deflated 46%)
adding: com/j_spaces/examples/ReplicatedSession.class(in = 740) (out= 357)(deflated 51%)
adding: com/j_spaces/examples/ReplicatedSessionBean$MyListener.class(in = 1084) (out= 551)(deflated 49%)
adding: com/j_spaces/examples/ReplicatedSessionBean.class(in = 10429) (out= 4472)(deflated 57%)
adding: com/j_spaces/examples/ReplicatedSessionHome.class(in = 319) (out= 213)(deflated 33%)
adding: model/(in = 0) (out= 0)(stored 0%)
adding: model/ModelClass.class(in = 1608) (out= 832)(deflated 48%)
adding: model/SubClass1.class(in = 579) (out= 352)(deflated 39%)
adding: config/(in = 0) (out= 0)(stored 0%)
adding: config/gs.properties(in = 6239) (out= 2194)(deflated 64%)
adding: gslicense.xml(in = 257) (out= 181)(deflated 29%)
ReplicatedSessionBean.jar
        1 file(s) copied.
------------------------------------
Creating ReplicatedSessionWeb.war ..
------------------------------------
adding: ejbwar.bat(in = 52) (out= 48)(deflated 7%)
adding: ejbwar.sh(in = 60) (out= 56)(deflated 6%)
adding: HelloWorldFormHandler.jsp(in = 3638) (out= 1080)(deflated 70%)
adding: index.html(in = 2459) (out= 537)(deflated 78%)
adding: META-INF/(in = 0) (out= 0)(stored 0%)
adding: META-INF/MANIFEST.MF(in = 35) (out= 37)(deflated -5%)
adding: WEB-INF/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/com/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/com/j_spaces/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/com/j_spaces/web/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/com/j_spaces/web/TestServlet.class(in = 6223) (out= 3021)(deflated 51%)
adding: WEB-INF/classes/com/j_spaces/web/TestServlet.java(in = 6696) (out= 1653)(deflated 75%)
adding: WEB-INF/ibm-web-bnd.xmi(in = 316) (out= 194)(deflated 38%)
adding: WEB-INF/ibm-web-ext.xmi(in = 456) (out= 260)(deflated 42%)
adding: WEB-INF/sun-web.xml(in = 334) (out= 233)(deflated 30%)
adding: WEB-INF/web.xml(in = 916) (out= 360)(deflated 60%)
ReplicatedSessionWeb.war
        1 file(s) copied.
-------------------------------------------
Creating final ReplicatedSessionBean.ear ..
-------------------------------------------
ReplicatedSessionBean : no such file or directory
adding: META-INF/(in = 0) (out= 0)(stored 0%)
adding: META-INF/application.xml(in = 528) (out= 292)(deflated 44%)
adding: META-INF/ibm-application-ext.xmi(in = 343) (out= 173)(deflated 49%)
adding: META-INF/ibm-ejb-jar-bnd.xmi(in = 485) (out= 267)(deflated 44%)
adding: META-INF/sun-j2ee-ri.project(in = 135) (out= 126)(deflated 6%)
adding: META-INF/sun-j2ee-ri.xml(in = 788) (out= 376)(deflated 52%)
adding: ReplicatedSessionBean.jar(in = 15928) (out= 13579)(deflated 14%)
adding: ReplicatedSessionWeb.war(in = 9713) (out= 8184)(deflated 15%)
adding: lib/(in = 0) (out= 0)(stored 0%)
adding: lib/common/(in = 0) (out= 0)(stored 0%)
adding: lib/common/backport-util-concurrent.jar(in = 326319) (out= 284557)(deflated 12%)
adding: lib/jini/(in = 0) (out= 0)(stored 0%)
adding: lib/jini/jsk-dl.jar(in = 61563) (out= 51927)(deflated 15%)
adding: lib/jini/jsk-lib.jar(in = 291877) (out= 264368)(deflated 9%)
adding: lib/jini/jsk-platform.jar(in = 995179) (out= 903709)(deflated 9%)
adding: lib/jini/jsk-policy.jar(in = 31055) (out= 27339)(deflated 11%)
adding: lib/jini/jsk-resources.jar(in = 1722) (out= 880)(deflated 48%)
adding: lib/jini/mahalo-dl.jar(in = 16470) (out= 14518)(deflated 11%)
adding: lib/jini/mahalo.jar(in = 107261) (out= 98672)(deflated 8%)
adding: lib/jini/reggie-dl.jar(in = 58054) (out= 54033)(deflated 6%)
adding: lib/jini/reggie.jar(in = 141059) (out= 131432)(deflated 6%)
adding: lib/jini/start.jar(in = 63029) (out= 56851)(deflated 9%)
adding: lib/JSpaces.jar(in = 5644925) (out= 5234941)(deflated 7%)
adding: lib/rio/(in = 0) (out= 0)(stored 0%)
adding: lib/rio/boot.jar(in = 23629) (out= 22356)(deflated 5%)
adding: lib/rio/webster.jar(in = 27750) (out= 26183)(deflated 5%)

After a successful build the ReplicatedSessionBean.ear will be found at <GigaSpaces ROOT>\J2EE\examples\ReplicatedSessionBean\ReplicatedSessionBean.

Start WSAD. Right-click the Enterprise Applications leaf in the J2EE Hierarchy view, and select import->Import Ear...

Make sure the EAR file you import will not be located in a URL path which contains spaces, such as C:\Documents and Settings.

You will then need to tell WSAD where the EAR file is located.

Make sure you select the ReplicatedSessionBean.jar in the Manifest Class-Path dialog, available dependent jars list.

Browse to the location of the EAR file.
Make sure that the Overwrite existing resources without warning check-box is selected. You may accept the defaults for the project name and location.
Click on finish – you can accept the defaults for the rest of the data WSAD gathers.

Please click Yes for all messages asking for permission to override existing files.

Verifying the Import Action

You can now see your project in the J2EE Hierarchy view:
(The screen shot shows the expanded tree).

Creating a new Server runtime

In WSAD, you may configure a runtime environment for applications. This runtime is not a full-fledged application server, but it is enough for our purposes.
Right click on the Servers leaf in the J2EE Hierarchy view.
Select New->Server and Server Configuration.

In the window that you'll get, enter a name for the server, and make sure that you create a WebSphere version 5.1 Test Environment (as shown in the screen shot).

Click Next, accept the default port suggestion, and click Finish. You now have a new runtime server created, and you can see it under Servers leaf.

Server Configuration

You need the server to be able to start GigaSpaces server. This is a configuration that must be done manually.
In the J2EE Hierarchy view, expand the Servers leaf, and double-click the server you just created.

Server Java VM Arguments

For this example, you need to modify the security settings of Websphere.
Click the Environment tab at the server configuration window, and then click the small blue arrow near "Java VM Arguments" (same can be set in the System Properties section).

Enter the following into the System Properties Arguments text box:
-Djava.security.policy=<GigaSpaces ROOT>\policy\policy.all
This is done so that space has no access permissions problems.

The Classpath should not be modified. GigaSpaces uses all that is required as part of the EAR file using the application class loader.

GigaSpaces & WebSphere 5 Demo

This demo allows you to perform all space basic operations using simple web client GUI interface having a session bean methods calling space operations through both IJSpace and IMap interfaces.

The session bean includes several methods. These in general call space basic operations such as write, read, take, notify, update and batch operations. It also contains basic Map operations (put, get etc.). The web interface JSP file provides GUI for these methods.
In order to access space from session bean method you should follow few basic steps:

  1. Call (IJSpace)SpaceFinder.find(spaceURL) for the Space API, or (IMap)CacheFinder.find(mapURL) for the Map API.
  2. Invoke space operation. Via the space proxy object you can write Entries into space, read, take and activate all other space operations.
Please refer to the example source code at:<GigaSpaces ROOT>\j2ee\examples\ReplicatedSessionBean\ReplicatedSessionBean_jar
\src\com\j_spaces\examples\ReplicatedSessionBean.java.

The session bean source code can be modified and compiled using the <GigaSpaces ROOT>\j2ee\examples\ReplicatedSessionBean\ear.bat file.
The original space operations includes Transaction object as part of the API.
These have been omitted from the GigaSpaces API since the transaction behavior controlled automatically by the Application Server. The transaction will be committed or roll backed when Session bean method will be ended.

ReplicatedSessionBean EAR file structure

The example is delivered inside the
<GigaSpaces ROOT>\j2ee\examples\ReplicatedSessionBean folder structure.
This structure is in accordance with the .ear file structure used by J2EE application servers for deploying applications.
Following is the description of this structure:

  • lib folder holds the necessary lib subfolders from the product distribution. Those subfolders hold jars that the application needs, and the configuration files for the application. The structure under this folder is rigid, and other applications should use the same structure when using GigaSpaces technology.
    Note that the lib directory is being copied from <GigaSpaces ROOT>/lib only after running the ear compilation file:
    <GigaSpaces ROOT>\j2ee\examples\ReplicatedSessionBean\ear.bat file.
  • META-INF folder holds deployment-descriptors needed for the various application servers.
  • ReplicatedSessionBean_jar holds the exploded jar file that contains the EJB for this application.
    A subfolder config contains the configuration file. The system loads the following properties file:
    j2ee\examples\ReplicatedSessionBean\ReplicatedSessionBean_jar\config\gs.properties file, which overwrites several configuration elements.
  • ReplicatedSessionWeb_war holds the exploded war file that contains the web application used by this application in order to access the EJB.

Files inside this folder-structure include:

  • build.xml – an ant build file to build the ReplicatedSessionBean.ear file, and all its components.
  • ear.bat and ear.sh – batch and shell files that build the ReplicatedSessionBean.ear file, and all its components.
  • setenv.bat and setenv.sh – batch and shell files that set the environment variables for the ear.bat and ear.sh files respectively.
  • ReplicatedSessionBean.jar and ReplicatedSessionWeb.war are jar and war files that hold the respective ReplicatedSessionBean_jar and ReplicatedSessionWeb_war.
Make sure you run the ear.bat using JDK 1.4 only since the WSAD 5.1 does not support JDK 1.5 yet.

Deploy ReplicatedSessionBean Application

Before deploying the application, you should perform two steps:

  1. Generate deployment code for the EJB.
    Right Click the EJB module in the J2EE Hierarchy View (ReplicatedSessionBeanEJB:GigaCacheSession) and select Generate-Deployment and RMIC code.

    In the next screen make sure that ReplicatedSession is checked, and click Finish:
  2. After you generate the code, go to J2EE Hierarchy view and right click ReplicatedSessionBeanEAR: Replicated Session. Select Run on server from the pop up menu:


On the next screen make sure that your server is selected, and click Finish. If a new screen appears asking you if you want to deploy the EJB, check the check-box and carry on.

Deploy the EJB package ReplicatedSessionBeanEJB.
Right click ReplicatedSessionBeanEJB, select Generate -> Deploy and RMIC code.
Click Finish.
Your application is now being deployed on WebSphere. In WSAD you will see a console view at the bottom right of the screen. Wait until you get the message that the server is ready:

Run the Application

Open a browser window and enter the following at the address bar:
http://localhost:9080/ReplicatedSessionBean/index.html

You should see the application's entry page:

Select any action and press the Go! Button.
The jsp will call SpaceFinder.find() and CacheFinder.find() which load two embedded spaces.
The system loads the following properties file:
j2ee\examples\ReplicatedSessionBean\ReplicatedSessionBean_jar\config\gs.properties, which overwrites several configuration elements and sets also the Space URL suffix (the SpaceURL prefix is set inside the ReplicatedSessionBean.java) which starts a replicated clustered Space node using the line:
gs.space.url.arg_line=schema=cache&total_members=3&cluster_schema=async_replicated&ignoreValidation.

You may need to use the securityManager=false URL property to avoid java security problems. This relevant when accessing remote space. In this case you should get the space proxy via the following URL:

IJSpace space = SpaceFinder.find("jini://*/*/j2eeCache?securityManager=false");
IMap cache = (IMap )CacheFinder.find("jini://*/*/j2eeCache?securityManager=false");

For example, suppose you selected to write 1000 Entries to the space.
Upon completion, you should see the following page:

Using this link you may test the application one method call at a time.
There is another test supplied with the application - a servlet that tests all of the methods at one go. Just try http://localhost:9080/ReplicatedSessionBean/TestServlet and see for yourself.

GigaSpaces Space Browser

You can view class instance count for every class type stored at the space using the GigaSpaces Browser Runtime Module.
Open GigaSpaces Browser by Running:
<GigaSpaces ROOT>\bin\SpaceBrowser.bat – for windows
Or
<GigaSpaces ROOT>\bin\SpaceBrowser.sh – for Unix/Linux
Open the j2eeCache space tree node at the left side panel.
Click the Classes tree node at the left side panel.
Click the Start button at the right side panel.
See the com.j_spaces.examples.ModelClass class instances count table.


Wiki Content Tree


Your Feedback Needed!

We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.

Labels

 
(None)