Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 7. Example 1: Creating the client application
The
UserManagement
client
In the interest of completeness you have to have a client that can exercise your
example. The client in this application does the following:
Looks up the
UserManagement
session bean using JNDI
Adds two user to the system using the addUser method of the
UserManagementBean
Verifies that one of the user s password is "mypassword" using the
verifyPassword()
method of the
UserManagementBean
Then removes the two users using the removeUser method of the
UserManagementBean
The complete code listing for the client is listed below.
In order for the application client to access the session bean, it needs an ejb ref
element entry in its deployment descriptor (
application client.xml
) shown in the
example column to the left below the home interface listing.
Notice the manner that you access the session bean from the client is similar to the
way the
UserManagement
session bean access the User entity.
Listing 7: The
UserManagement
Client code
/** Client code */
package com.rickhightower.client;
import com.rickhightower.auth.UserManagement;
import com.rickhightower.auth.UserManagementHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
public class Section2Client {
public static void main(String[] args) {
try {
Context initial = new InitialContext();
Object ref =
initial.lookup("java:comp/env/ejb/UserManagement");
UserManagementHome home =
(UserManagementHome)PortableRemoteObject
.narrow(ref,UserManagementHome.class);
Introducing EJB CMP/CMR, Part 1 of 2
Page 29 of 48
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved