This topic shows you step-by-step how to deploy a CMP bean from WebLogic 5.1.0 to IBM WebSphere 3.5 and run a client for it. The sample resides in %WL_HOME%\examples\ejb\basic\containerManaged.
Copy all .java files from %WL_HOME%\examples\ejb\basic\containerManaged to %TG_HOME%\myprojects\cmp\examples\ejb\basic\containerManaged.
Start Together.
Create a New Project and set its location to %TG_HOME%\myprojects\cmp. Enter 'cmp' as the project name. You would not need the standard libraries. To remove them from the project, press Advanced button, select Search Classpath and make sure that check boxes 'Include standard libraries' and 'Include Classpath' are cleared. On the EJB tab select IBM WebSphere AE 3.5 server. Press OK.
Navigate to containerManaged node in the Explorer, select Open Diagram on the speedmenu and open containerManaged package.
Select AccountBean in the diagram, choose Properties from the speedmenu and open Object Inspector.
Select Entity EJB page in the Inspector dialog and make the following changes:
On the General tab chose
'Don't synchronize names'.
Type examples.ejb.basic.containerManaged.AccountPK
in the field Primary Key Name and
press Enter. In the opened dialog press Create
button to create Primary Key Class.
Select AccountId
as primary key on the Fields and Finders
tab .
On the same tab set the 'finder query' properties for finder methods as follows:
'findBigAccounts' : 'select * from accountbeantbl where balance > ?',
'findAccount': 'select * from accountbeantbl where balance = ?',
'findNullAccounts': 'select * from accountbeantbl where accountType is null '.
Go to Properties tab and set JNDI name to AccountHome.
Close Object Inspector.
Select AccountPK class and create new constructor (New | Constructor from the speedmenu).
Open the newly created constructor in the text editor and correct it as follows:
public AccountPK(String param) { accountId = param; }
Edit hashCode() method in the AccountPK:
public int hashCode() { return accountId.hashCode(); }
Edit equals() method in the AccountPK:
public boolean equals(Object other) {
if (other instanceof AccountPK) {
}AccountPK otherKey = (AccountPK) other;
} else return false;
return accountId.equals(otherKey.accountId);
Now you are ready to deploy this bean to WebSphere 3.5
Select Client class on the diagram.
Edit main() method:
|
Find |
Replace |
|
String url = "t3://localhost:7001"; |
String url = "iiop://localhost:900"; |
Edit getInitialContext method:
|
Find |
Replace |
|
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); |
h.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory"); |
Edit lookupHome
|
Find |
Replace |
|
Object home = (AccountHome) ctx.lookup("containerManaged.AccountHome");' |
Object home = (AccountHome) ctx.lookup("AccountHome") |
Find and replace all encounters of findByPrimaryKey(id) methods with findByPrimaryKey(new AccountPK(id)).
Edit findNullAccounts().
|
Find |
Replace |
|
Enumeration enum = (Enumeration) PortableRemoteObject.narrow(home.findNullAccounts(), hi.class);
|
Enumeration enum = home.findNullAccounts();
|
|
Account nullAccount= (Account) enum.nextElement(); |
Account nullAccount= (Account) PortableRemoteObject.narrow(enum.nextElement(), Account.class); |
The client is now ready.
Precondition
Start WebSphere server:
Select Control panel | Services from Start | Settings menu.
Select "IBM WS AdminServer" and press Start button.
Note:
"IBM HTTP Administration" and "IBM HTTP Server"
should be already started.
Deploying the bean
1. Run Together 's Main Menu | Tools | EJB Deployment Expert
2. Select "IBM WebSphere AE 3.5" as the target server and make sure that all available checkboxes, except "Process servlets", "Generate WLM jar for Bean","Generate start and compile file for client" and "Generate simple JSP client" are set. Press Next.
3. Set paths to WebSphere home directory and to IBM JDK 1.2.2 root directory (e.g. "c:\WebSphere\AppServer" and "c:\WebSphere\AppServer\jdk"). Press Next.
4. Set the following parameters on the next page:
|
Parameter name |
Setting |
Comment |
|
Admin Node Name |
Name of the Node to deploy |
Name of the computer |
|
Dependent ClassPath |
Fully qualified path to WebSphere |
Check if it refers to existing jars |
|
Application Server Name |
Your Application Server |
"Default Server" by default |
|
EJB Container name |
Your Container name |
"Default Container" by default |
|
Target WebSphere server directory |
WebSphere home directory |
for example c:\WebSphere\AppServer |
|
Create Table for CMP EJBs |
ON |
|
|
Launch server in debug mode |
OFF |
|
Press Next and Finish.
If you have checked Hot Deploy check box, the last message in the
Message Pane should be:
//WAS35: Finished with 0 Errors, 0 Warnings.
It means the deployment process successfully completed.
Add the following libraries to your project:
%WAS_HOME%\jdk\jre\lib\ext\rmiorb.jar
%WAS_HOME%\jdk\jre\lib\ext\iioprt.jar
Deployed jar file (e.g. %WAS_HOME%\deployableEJBs\DeployabletogetherEJB.jar)
Home directory of WebSphere Server %WAS_HOME%This is done in the following way
From the Main Menu | File | Project Properties dialog select
Search/Classpath page on the Resource pane. At this moment there
shouldn't be anything added to the classpath.
Press Add Zip/JAR button and add %WAS_HOME%\jdk\jre\lib\ext\rmiorb.jar,
%WAS_HOME%\jdk\jre\lib\ext\iioprt.jar
Press OK to save project properties.
Select Main Menu | Options | Project
Go to the Tools tab and add Deployed jar file to the ClassPath.
Note: In the nearest builds these libs will be added automatically.
Select Options|Project from the Main Menu and set JDK Home to %WAS_Home%\jdk on the Tools Tab, press "OK"
Select 'Client' class on the diagram and choose Rebuild Node on the speedmenu.
Builder pane displays a message that the tool is completed.
Select Main Menu | Tools | Run/Debug | Run. Make
sure that 'Class with main' is set to examples.ejb.basic.containerManaged.Client.
Press OK.
The following messages appear in the Runner pane:
Beginning containerManaged.Client...
Starting Part A of the example...
Creating account 10020 with a balance of 3000.0 account type Savings...
Account 10020 successfully created
Part A: Depositing $2000
Current balance is $5000.0
Attempting to withdraw an amount greater than current balance. Expecting an exception...
Received expected Processing Error:
examples.ejb.basic.containerManaged.ProcessingErrorException: Request to withdraw $5001.0; is more than balance
$5000.0 in account 10020
Removing account...
End Part A of the example...
Starting Part B of the example...
Creating account ID: 0 with a balance of 0.0 account type null...
Account ID: 0 successfully created
Creating account ID: 1 with a balance of 1000.0 account type Savings...
Account ID: 1 successfully created
Creating account ID: 2 with a balance of 2000.0 account type Savings...
Account ID: 2 successfully created
Creating account ID: 3 with a balance of 3000.0 account type Savings...
Account ID: 3 successfully created
Creating account ID: 4 with a balance of 4000.0 account type Savings...
Account ID: 4 successfully created
Creating account ID: 5 with a balance of 5000.0 account type null...
Account ID: 5 successfully created
Creating account ID: 6 with a balance of 6000.0 account type Savings...
Account ID: 6 successfully created
Creating account ID: 7 with a balance of 7000.0 account type Savings...
Account ID: 7 successfully created
Creating account ID: 8 with a balance of 8000.0 account type Savings...
Account ID: 8 successfully created
Creating account ID: 9 with a balance of 9000.0 account type Savings...
Account ID: 9 successfully created
Creating account ID: 10 with a balance of 10000.0 account type null...
Account ID: 10 successfully created
Creating account ID: 11 with a balance of 11000.0 account type Savings...
Account ID: 11 successfully created
Creating account ID: 12 with a balance of 12000.0 account type Savings...
Account ID: 12 successfully created
Creating account ID: 13 with a balance of 13000.0 account type Savings...
Account ID: 13 successfully created
Creating account ID: 14 with a balance of 14000.0 account type Savings...
Account ID: 14 successfully created
Creating account ID: 15 with a balance of 15000.0 account type null...
Account ID: 15 successfully created
Creating account ID: 16 with a balance of 16000.0 account type Savings...
Account ID: 16 successfully created
Creating account ID: 17 with a balance of 17000.0 account type Savings...
Account ID: 17 successfully created
Creating account ID: 18 with a balance of 18000.0 account type Savings...
Account ID: 18 successfully created
Creating account ID: 19 with a balance of 19000.0 account type Savings...
Account ID: 19 successfully created
Account: :examples.ejb.basic.containerManaged.AccountPK@4247acf has a balance of 0.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad0 has a balance of 1000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad1 has a balance of 2000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad2 has a balance of 3000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad3 has a balance of 4000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad4 has a balance of 5000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad5 has a balance of 6000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad6 has a balance of 7000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad7 has a balance of 8000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@4247ad8 has a balance of 9000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf60 has a balance of 10000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf61 has a balance of 11000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf62 has a balance of 12000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf63 has a balance of 13000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf64 has a balance of 14000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf65 has a balance of 15000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf66 has a balance of 16000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf67 has a balance of 17000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf68 has a balance of 18000.0
Account: :examples.ejb.basic.containerManaged.AccountPK@806adf69 has a balance of 19000.0
Querying for accounts with a balance greater than 5000.0...
Account examples.ejb.basic.containerManaged.AccountPK@4247ad5; balance is $6000.0
Account examples.ejb.basic.containerManaged.AccountPK@4247ad6; balance is $7000.0
Account examples.ejb.basic.containerManaged.AccountPK@4247ad7; balance is $8000.0
Account examples.ejb.basic.containerManaged.AccountPK@4247ad8; balance is $9000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf60; balance is $10000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf61; balance is $11000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf62; balance is $12000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf63; balance is $13000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf64; balance is $14000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf65; balance is $15000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf66; balance is $16000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf67; balance is $17000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf68; balance is $18000.0
Account examples.ejb.basic.containerManaged.AccountPK@806adf69; balance is $19000.0
Querying for an account with zero balance...
Account examples.ejb.basic.containerManaged.AccountPK@4247acf; balance is zero
Querying for accounts with a null account type
Account examples.ejb.basic.containerManaged.AccountPK@4247ad4; account type is null
Account examples.ejb.basic.containerManaged.AccountPK@806adf60; account type is null
Account examples.ejb.basic.containerManaged.AccountPK@806adf65; account type is null
Account examples.ejb.basic.containerManaged.AccountPK@4247acf; account type is null
Removing beans...
End Part B of the example...
End containerManaged.Client..