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.
Posted by dsuspense | April 12, 2004 4:53 PM
Posted on April 12, 2004 16:53
The book I am speaking of is Java and JMX, see http://www.aw-bc.com/catalog/academic/product/0,4096,0672324083,00.html
Posted by dsuspense | April 12, 2004 4:54 PM
Posted on April 12, 2004 16:54