Software Secret Weapons™  
JMX In Apache Tomcat posted by Pavel Simakov on 2006-03-09 18:26:20 under Linguine Watch
view comments
 


I have recently discovered that Tomcat 5.0.25 does not support JMX monitoring. This is sad news, which needed attention. Hereunder is a workaround to make Tomcat 5.0.25 JSR 160 compatible as told to me by a friend.

JSR 160 provides a standard way to connect to remote JMX-enabled applications using RMI; it is possible to use JMX JSR 160 implementation on client side, and have a JMX Remote Reference Implementation on server side, or vice versa. This allows the creation of Management Consoles based on Swing, for example that will be able to interoperate no matter which JMX implementation is used.

To make a system (or system component) accessible for monitoring via JMX-enabled monitoring applications this system has to be JSR 160 compatible. It can be achieved by running this system component on JDK1.5, or using third party implementation such as MX4J.

The Problem
Many JMX-enabled monitoring applications (AdventNet's "Applications Manager 6", for example) are only able to interact with the Remote JMX JSR 160 RMI compatible Adaptors. Tomcat 5.0.x does not have it. Neither it has its own implementation of the adaptor nor does JDK 1.4.x. While it is possible to eliminate this problem by moving application to Tomcat 5.5 and JDK 1.5, it is not always feasible.

The Solution
Tomcat 5.0.x contains old (as it seems now) version of MX4J library. You have to fool Tomcat 5.0 and load new MX4J library classes instead. Unfortunately placing new jars into various folders will be no good as the old library will be already loaded by bootstrap classloader. It also seems that Tomcat code contains some logic to check whether %TOMCAT_HOME%/bin/jmx.jar is in place.

But you can change the jmx.jar library content. I took latest MX4J 3.0.1 and repacked compiled code from jars into one. Specifically I took the following jars from mx4j-3.0.1 distribution pack:

  • mx4j-impl.jar
  • mx4j-jmx.jar
  • mx4j-remote.jar
  • mx4j-tools.jar

and put them into one jar - jmx.jar. That was it. Now while still running Tomcat 5.0 your web application can register MBeans and expose them through MX4J implementation of RMI Adapter for external management.

Comment (1)

  • Comment by Deepak — November 27, 2007 @ 8:40 pm

    Hi,
    I’m trying to access the tomcat’s Mbean from outside the tomcat environment, i.e trying to access the Mbean from standalone application.

    I’ve added and enabled the jmx port by the following code in server.xml

    <Connector port=”0″
    handler.list=”mx”
    mx.enabled=”true”
    mx.httpHost=”localhost”
    mx.httpPort=”5566″
    protocol=”AJP/1.3″ />

    And trying to access the Mbean in the standalone java application by like this,
    JMXServiceURL url = new JMXServiceURL(”service:jmx:rmi:///jndi/rmi://localhost:5566/jmxrmi”);
    Map map = new HashMap();
    String[] credentials = new String[] { “admin” , “admin”};
    map.put(”jmx.remote.credentials”, credentials);
    JMXConnector conn = JMXConnectorFactory.connect(url,map);

    But i’m getting error
    java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
    java.net.SocketTimeoutException: Read timed out]

    and also getting following error in tomcat console
    Exception during http request
    java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
    at mx4j.tools.adaptor.http.HttpInputStream.readLine(HttpInputStream.java
    :272)
    at mx4j.tools.adaptor.http.HttpInputStream.readRequest(HttpInputStream.j
    ava:194)
    at mx4j.tools.adaptor.http.HttpAdaptor$HttpClient.run(HttpAdaptor.java:9
    54)

    I’ve placed all the jar files MX4j related in the lib folder.

    Please tell me wha’t is the issue

    Thanks and Regards,
    Deepak.S


Leave a comment


  Copyright © 2004-2007 by Pavel Simakov SourceForge.net Logo