« Client side single sign-on | Main | Will Google redefine Email with its Gmail? »

J2EE Management in J2EE1.4 RI

J2EE Management (a.k.a JSR-77) defines an alternate mechanim (the conventional one being through an MBean Server) to access J2EE Management Objects: through a Management EJB called MEJB. However, the information to access MEJB in a client Java program is quite scarce.

With some digging around and trial-and-error, I was able to get a Java client within an Application Client Container to access EJB. However, what I am really interested is to access MEJB from a standalone Java client through RMI-IIOP. This is currently not working.

I am posting the client code for those who may be interested:

package client;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.management.*;
import javax.management.j2ee.*;
public class MEJBClient {
public static void main(String[] args) {
String url = null;
String jndiname = null;
boolean acc = true;
try {
if (args.length == 1 ) {
url = args[0];
acc = false;
System.out.println("url = " + url);
}
Context initial;
Object objref;
if (acc) {
initial = new InitialContext();
objref = initial.lookup("ejb/mgmt/MEJB");
System.out.println("objref obtained within ACC...");
} else {
Properties env = new Properties();
env.put("java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.provider.url", url);
env.put("java.naming.security.authentication", "simple");
env.put("java.naming.security.principal", "admin");
env.put("java.naming.security.credentials", "weblogic");
initial = new InitialContext(env);
objref = initial.lookup("ejb/mgmt/MEJB");
System.out.println("objref obtained through RMI-IIOP...");
}
System.out.println("objref = " + objref);
ManagementHome mhome = (ManagementHome)PortableRemoteObject.narrow(objref,
ManagementHome.class);
Management mejb = mhome.create();
ObjectName sp = new ObjectName("*:*");
Set mos = mejb.queryNames(null, null);
System.out.println("Found " + mos.size() + " Managed Objects.");
System.exit(0);
} catch (Exception ex) {
//ResourceBundle rb = ResourceBundle.getBundle("LocalStrings", Locale.getDefault());
//System.err.println(rb.getString("caught_exception")+"!");
ex.printStackTrace();
}
}
}

Comments (2)

Java and JMX covers JSR 77 with some sample code in chapter 10. I have the book but have not read the chapter as yet. But maybe you can check it out.

About

This page contains a single entry from the blog posted on April 12, 2004 1:44 PM.

The previous post in this blog was Client side single sign-on.

The next post in this blog is Will Google redefine Email with its Gmail?.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33