Java Reference
In-Depth Information
C
The main() method for this MBean allows you to register the MBean with the
JMXBookAgent agent that you developed in chapter 3. You should recognize this
code: it's identical to code used other times you've needed to register MBeans in
the agent.
14.3.3
Writing the user login client test class
Up to this point, you have completed the EJB and the MBean that will grant
management access to it. Now you need to develop a client class so that you can
simulate a login attempt from a user. The test class will need to locate the entity
bean and attempt to call its login() method. The test class will then print the
status of the login attempt to standard out. The UserLogin test class is shown in
listing 14.6.
Listing 14.6
UserLogin.java
package jmxbook.ch14;
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
public class UserLogin{
public static void main(String[] args)
{
System.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url", "localhost:1099");
try{
// Get a naming context
InitialContext jndiContext = new InitialContext();
System.out.println("Got context");
// Get a reference to the UserInfo Bean
Object ref = jndiContext.lookup("jmxbook/ch14/UserInfo");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
UserInfoHome home = (UserInfoHome)
PortableRemoteObject.narrow (ref, UserInfoHome.class);
UserInfo userInfo=home.findByPrimaryKey(args[0]);
if(userInfo==null){
System.out.println("No Existing userInfo Found:");
return;
}
else{
System.out.println("Existing userInfo Found:");
}
Search WWH ::




Custom Search