Connect to Mbean using RMI Connector
scttu Dec 26, 2003 9:42 PMHello,
I try to connect to Mbean using the RMI Connector. From the stack trace seems it require Sun JMX implementation. whereas i am using JBoss JMX implementation. I am confused why It required com/sun/jmx/mbeanserver/GetPropertyAction.
Below is the code i used to invoke the mbean. I have jbossall-client.jar in my classpath.
public static RemoteMBeanServer getMBeanServer(){
String jndiName = "jmx/rmi/RMIAdaptor";
RemoteMBeanServer server = null;
try{
Context context = initContext();
if(context != null){
RMIAdaptor adaptor =
(RMIAdaptor)context.lookup(jndiName);
server = new RMIConnectorImpl(adaptor);
}
}catch(NamingException ex){
System.out.println("can't find the adapter");
//ex.printStackTrace();
}
return server;
}
public static Context initContext(){
Context context = null;
String jndiUrl = "jnp://172.16.0.112:1099";
try{
Properties props = new Properties();
props.setProperty(Context.PROVIDER_URL,
jndiUrl);
props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.setProperty (Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
context = new InitialContext(props);
}catch(NamingException e){
e.printStackTrace();
}
return context;
}
public static Object invokeOpByName(String name, String method,
Object [] args, String [] argsType)
throws MalformedObjectNameException,
NullPointerException,
InstanceNotFoundException,
MBeanException,
ReflectionException {
Object ob = null;
RemoteMBeanServer server = getMBeanServer();
if(server != null){
ObjectName objectName = new ObjectName(name);
ob =
server.invoke(objectName,method,args,argsType);
return ob;
}
}
Any helps are very much appreciated. thanks
Regards,
Stephen
java.lang.NoClassDefFoundError: com/sun/jmx/mbeanserver/GetPropertyAction
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at $Proxy0.(Unknown Source)
at sun.reflect.GeneratedSerializationConstructorAccessor24.newInstance(Unkn
own Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.io.ObjectStreamClass.newInstance(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at java.rmi.MarshalledObject.get(Unknown Source) at
org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:30)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:550)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:964)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:613)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
at javax.naming.InitialContext.lookup(Unknown Source)
at my.com.shinyang.mbean.RemoteMBeanInvoker.getMBeanServer(RemoteMBeanInvok
er.java:40)
at my.com.shinyang.mbean.RemoteMBeanInvoker.invokeOpByName(RemoteMBeanInvok
er.java:86)
at my.com.shinyang.user.provider.UserManagerProviderImpl.createUser(UserMan
agerProviderImpl.java:32)
at my.com.shinyang.user.UserManagerTest.testCreateUser(UserManagerTest.java
:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:167)