JMX Connection Problems

L

Lord Zoltar

Hi all,
I've been working with some JMX code on WebSphere and I've kinda hit a
brick wall.
I'm trying to ween an application off of depending on WebSphere code
(specifically, the AdminClient class) so that it can be deployed onto
Tomcat and connect to non-WebSphere servers.
The code I have found from IBM that demonstrates how to connect to
WebSphere from plain JMX is found here:
http://publib.boulder.ibm.com/infoc...ress.doc/info/exp/ae/tjmx_develop_jsr160.html

And the connection code I have looks like this:

String jndiPath="/jndi/JMXConnector"; //also could try
"jmxrmi" or "server" or "JMXConnector"
System.out.println("creating URL...");
String urlString = "service:jmx:iiop://"+hostname
+":"+port
+jndiPath;
JMXServiceURL url = new JMXServiceURL(urlString);
System.out.println("URL is "+url.toString());

Hashtable h = new Hashtable();
String[] credentials = new String[] {user ,password };
h.put("jmx.remote.credentials", credentials);

//Establish the JMX connection.
try
{
JMXConnector jmxc = (JMXConnector)
JMXConnectorFactory.connect(url,h);
//JMXConnector jmxc = (JMXConnector)
JMXConnectorFactory.connect(url);
//Get the MBean server connection instance.
mbsc = jmxc.getMBeanServerConnection();
}
catch(Exception e)
{
System.out.println("Error creating connection:");
e.printStackTrace();
}

It throws the following exeception:
java.io.IOException: Failed to retrieve RMIServer stub:
javax.naming.NameNotFoundException: Context:
16DH6CAC71401GBNode01Cell/
nodes/16DH6CAC71401GBNode01/servers/server1, name: JMXConnector:
First
component in name JMXConnector not found. Root exception is
org.omg.CosNaming.NamingContextPackage.NotFound: IDL:eek:mg.org/
CosNaming/
NamingContext/NotFound:1.0

So it seems to me that there is no object named JMXConnector. Has
anyone ever run into this problem before? If so, how did you resolve
it?
Thanks!
 
M

Manfred Rosenboom

I use the following code:

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.URL_PKG_PREFIXES,
"com.ibm.ws.naming");

If you want to use security, you have also to add the following
code:

String[] credentials = new String[] {"user" , "password" };
env.put(JMXConnector.CREDENTIALS, credentials);


With my above setted env hashtable, I can create a JMXConnector
as follows:

jmxConnector = JMXConnectorFactory.newJMXConnector(
new JMXServiceURL(
"service:jmx:iiop://localhost:9100/jndi/JMXConnector"
),
env);

The JMX client needs the following WAS jar file at runtime:

<WAS_HOME>/AppServer/runtimes/com.ibm.ws.admin.client_6.1.0.jar


My clients don't use the IBM JDK. In this case you have to add the
followng jar files to the bootclasspath of your client's JVM:

- <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmorb.jar</li>
- <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmorbapi.jar</li>
- <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmcfw.jar</li>


Best,
Manfred
 
L

Lord Zoltar

I use the following code:

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
         "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.URL_PKG_PREFIXES,
         "com.ibm.ws.naming");

If you want to use security, you have also to add the following
code:

String[] credentials = new String[] {"user" , "password" };
env.put(JMXConnector.CREDENTIALS, credentials);

With my above setted env hashtable, I can create a JMXConnector
as follows:

jmxConnector  = JMXConnectorFactory.newJMXConnector(
                                        new JMXServiceURL(
     "service:jmx:iiop://localhost:9100/jndi/JMXConnector"
                                                         ),
                                        env);

The JMX client needs the following WAS jar file at runtime:

<WAS_HOME>/AppServer/runtimes/com.ibm.ws.admin.client_6.1.0.jar

My clients don't use the IBM JDK. In this case you have to add the
followng jar files to the bootclasspath of your client's JVM:

   - <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmorb.jar</li>
   - <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmorbapi.jar</li>
   - <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmcfw.jar</li>

Best,
Manfred


I tried adding the Initial Context Factory and URL Package Prefix
settings, but I still get a NameNotFound exception.
Is there some server setting that could be responsible for this? This
application was originally using IBM's AdminClient class instead of
the JMXConnector class and it worked fine on the same server, so I
didn't think I needed to make any changes to the server but now I'm
not sure...

I don't really want to package that admin_client jar with the
application, as it's 30 MB (the last person here who tried that trick
had to add another 60 MB of other ibm jars to get their app to
compile) and someone has raised the issue of whether it's allowed to
resdistribute parts of WebSphere with the app.
Either way, I want to include as few IBM jars and classes as possible
in this client.
 
L

Lord Zoltar

The JMX client needs the following WAS jar file at runtime:

<WAS_HOME>/AppServer/runtimes/com.ibm.ws.admin.client_6.1.0.jar

My clients don't use the IBM JDK. In this case you have to add the
followng jar files to the bootclasspath of your client's JVM:

   - <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmorb.jar</li>
   - <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmorbapi.jar</li>
   - <WAS_HOME>/AppServer/AppServer/java/jre/lib/ibmcfw.jar</li>

Best,
Manfred

Ok, so for my little command-line test app (just makes a connection,
nothing else), this worked! :) :) I added all 4 of those jars to the
build path (I didn't need to actually import them to the project) and
I was able to connect without the NameNotFoundException!
Then I tried to do the same trick in my WebApp... It didn't work so
well. I started getting many other exceptions. After a bit of
research, I found I do need to include some other IBM jars.
Specifically:

bootstrap.jar
ecutils.jar
emf.jar
ffdc.jar
idl.jar
iwsorb.jar
jta.jar
naming.jar
namingclient.jar
ras.jar
wsexception.jar

So I added them (in addition to ibmorb.jar, ibmorbapi.jar, ibmcfw.jar,
and the admin client jar) to my web app, and now I'm back to the
NameNotFoundException. I tried adding ibmorb, ibmorbapi and ibmcfw to
the bootclasspath for Tomcat by adding the following line to the JMV
options, but it didn't seem to make any difference.
-Xbootclasspath/a:C:\Program Files\IBM\SDP70\runtimes\base_v61\java\jre
\lib\ibmorb.jar;C:\Program Files\IBM\SDP70\runtimes\base_v61\java\jre
\lib\ibmorbapi.jar;C:\Program Files\IBM\SDP70\runtimes\base_v61\java
\jre\lib\ibmcfw.jar

I'm not very experience with Tomcat so I'm not sure I'm doing it
right. When I export the WebApp as a war file, the jars all get placed
in $APPLICATION_PATH\WEB-INF\lib\ but I have a hunch that this is not
sufficient for the ibmorb* and ibmcfw and admin client jars. any other
tips?
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top