JMXConnector.getMBeanServerConnection() returns null

Hi,

I have the following problem. I'm using MX4J (3.0.2) implementation of JMX. The MBean server is running on Java 1.4. I exposed a JSR-160 JMXConnectorServer correctly bounded to "service:jmx:rmi://localhost/jndi/rmi://localhost:9099/jmxrmi" using Spring JMX support.

I have a java client (to start, stop, watch other java aplication), that cann't connect to the JMX server over RMI, because JMXConnector.getMBeanServerConnection() returns null. I have no idea howI can solve this problem.

On windows platform runs my JMX client perfect, but on AIX doesn't.

My environment:

-Operating system: IBM AIX

-JDK 1.4

-WebSphere 6

-Spring 2.0

thanx for any tips or advance

[730 byte] By [Peter212a] at [2007-11-14]
# 1
Hi Peter,I have made a suggestion here: http://forum.java.sun.com/thread.jspa?messageID=9403754Hope this helps,-- danielJMX, SNMP, Java, etc... http://blogs.sun.com/jmxetc
dfuchsa at 2007-7-7 > top of java,Core,Monitoring & Management...
# 2

Hi Daniel,

I didn't ask this on a websphere forum because I'm don't using websphere libs. I have 2 plain java aplications (adapters - for data loading from external systems). This adapters are registered on JMX Server (MX4J) using Spring JMX support. I want manage (start, stop, status watch) this adapters using JSR-160 over RMI. All is running on AIX platform:

java version "1.4.2"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2)

Classic VM (build 1.4.2, J2RE 1.4.2 IBM AIX build ca142ifx-20060209 (SR4-1) (JIT enabled: jitc))

I tried your suggestion. I created the RMIConnector as follows:

JMXConnector connector = new RMIConnector(serviceURL, environment);

connector.connect(environment);

logger.debug("JMXConnector: " + connector);

logger.debug("JMXConnector.getConnectionId(): " + connector.getConnectionId());

mBeanConnection = connector.getMBeanServerConnection();

if (mBeanConnection == null) {

throw new IOException("JMXConnector.getMBeanServerConnection() returns null!");

}

Result is following:

2006-12-20 15:48:29,616 DEBUG [main] MBeanServerConnectionFactory: JMXConnector: javax.management.remote.rmi.RMIConnector@6a70cca7

2006-12-20 15:48:29,616 DEBUG [main] MBeanServerConnectionFactory: JMXConnector.getConnectionId(): null

2006-12-20 15:48:29,622 FATAL [main] MBeanServerConnectionFactory: Could not connect to [service:jmx:rmi://localhost/jndi/rmi://localhost:9099/jmxrmi]

java.io.IOException: JMXConnector.getMBeanServerConnection() returns null!

at at.telekom.cramer.se.adapter.common.jmx.MBeanServerConnectionFactory.getConnection(MBeanServerConnectionFactory.java:46)

Conclusion:

The using of RMIConnector directly instead of using JMXConnectorFactory to create JMXConnector has the same effect. I tried too sun implementation of JMX with the same result.

Im asking myself: Doesn't the MX4J(3.0.2) or sun jmx run correctly on AIX platform?

Peter

Peter212a at 2007-7-7 > top of java,Core,Monitoring & Management...
# 3

Hi Peter,

This is really weird. I was so intrigued that I had a look at the source code of MX4J 3.0.2.

I don't see any way in which MX4J's RMIConnector could return a null

MBeanServerConnection, except if java.lang.reflect.Proxy.newProxyInstance() returns

null, which isn't supposed to happen. If it happened, it would be a bug on the AIX JDK.

Another possibility would be that Spring uses AOP in some way that modifies the code of

RMIConnector and causes it to return null. I would find that weird too. I have never played

with Spring or AOP so I'm out of my depth here.

Maybe running your client in verbose mode could give you a clue?

What I would suggest is that you have a look at these three classes in MX4J's sources:

http://sourceforge.net/project/showfiles.php?group_id=47745

mx4j-3.0.2/src/core/javax/management/remote/rmi/RMIConnector.java

=> look at getMBeanServerConnection()

mx4j-3.0.2/src/core/mx4j/remote/rmi/ClientUnmarshaller.java

=> look at newInstance()

mx4j-3.0.2/src/tools/mx4j/tools/remote/soap/ClientExceptionCatcher.java

=> look at newInstance()

If you could step in with a debugger, or insert some log messages to figure out where

the null comes from, you'd have enough information to figure out the cause of the

problem and who might be able to fix it.

You could also attempt to use the RMIConnector that comes with JSR 160 RI instead

of MX4J's implementation, and see how it behaves.

Hope this helps,

-- daniel

JMX, SNMP, Java, etc...

http://blogs.sun.com/jmxetc

dfuchsa at 2007-7-7 > top of java,Core,Monitoring & Management...
# 4

Hi Daniel,

i switched from MX4J's implementation to Sun implementation (in classpath i have jmxri.jar,jmxremote.jar)

if i try to create a JSR-160 JMXConnectorServer, the result is:

javax.management.remote.JMXConnectorFactory: method resolveClassLoader(Ljava/util/Map;)Ljava/lang/ClassLoader; not found

Caused by:

java.lang.NoSuchMethodError: javax.management.remote.JMXConnectorFactory: method resolveClassLoader(Ljava/util/Map;)Ljava/lang/ClassLoader; not found

at javax.management.remote.JMXConnectorServerFactory.newJMXConnectorServer(JMXConnectorServerFactory.java:269)

What does it mean? With MX4J it runs OK.

Peter212a at 2007-7-7 > top of java,Core,Monitoring & Management...
# 5

Hi Peter,

It looks like the JMXConnectorFactory and the JMXConnectorServerFactory come from

different implementations. Sun's implementation of JMXConnectorFactory has a

package protected method static ClassLoader resolveClassLoader(Map environment)

which Sun's implementation of JMXConnectorServerFactory is

using.

My explanation is that for some weird reason you are mixing two different implementations

of JMX Remote API. The JMXConnectorServerFactory seems to come from Sun's RI, since

it calls JMXConnectorFactory.resolveClassLoader(Map)

, but JMXConnectorFactory seems to come from somewhere else.

Maybe you could try this: System.err.println("CL for JMXConnectorFactory: " +JMXConnectorFactory.class.getClassLoader());

System.err.println("CL for JMXConnectorServerFactory: " +JMXConnectorServerFactory.class.getClassLoader());

. In any case, check your classpath, and try to have a look at the jars which are in the classpath of your appserver. If you mix two implementations of JMX Remote in such a way that part of the classes are loaded from one impl, and part of the classes are loaded from another, you are in trouble.

If you really want to know where those XXXXX classes come from I believe you can print: System.err.println("Location for "+ XXXXX.class.getName()+": "+ XXXXX.class.getProtectionDomain().getCodeSource().getLocation());

Hope this helps,

-- daniel

JMX, SNMP, Java, etc...

http://blogs.sun.com/jmxetc

dfuchsa at 2007-7-7 > top of java,Core,Monitoring & Management...
# 6

Hi Daniel,

Bingo!

That was the reason, why JMXConnector.getMBeanServerConnection() always returned null value.

I used two different implementations of JMX remote API (Sun or MX4J and WebSphere) My classpath was correct, but in the shell script I exposed Websphere libraries following way:

-Djava.ext.dirs=${WEBSPHERE_HOME}/lib

This realy helped me:

System.err.println("Location for "+ XXXXX.class.getName()+": "+ XXXXX.class.getProtectionDomain().getCodeSource().getLocation());

I found out, that the JMXConnectorServerFactory comes from Sun's RI, but the JMXConnectorFactory comes from WebSphere.

I corrected the starting of JMX agent and client. I tested my code with JMX impl. from Sun and with MX4J. All works correct.

Thanx very much!

Peter

Peter212a at 2007-7-7 > top of java,Core,Monitoring & Management...
# 7

Hi,

I'm having the same issue with the JMX client/server connection

My environment:

-Operating system: IBM AIX 5

-JDK 1.4.2

-WebSphere 6.0

and i'd trace the class loader using the following codes

System.err.println("CL for JMXConnectorFactory: " +JMXConnectorFactory.class.getClassLoader());

System.err.println("CL for JMXConnectorServerFactory: " +JMXConnectorServerFactory.class.getClassLoader());

System.err.println("Location for "+ XXXXX.class.getName()+": "+ XXXXX.class.getProtectionDomain().getCodeSource().getLocation());

I'm a newbie on WebSphere, how could i correct the starting of JMX agent and client?

Thanks

Daron_Tana at 2007-7-7 > top of java,Core,Monitoring & Management...