How do I use JMX to expose Application data in WebLogic?

You can find the answer to that below. I used WebLogic 8.1 on Windows to test this example (This should work on other platforms too).

Here I will describe a working example on how to register your JMX MBeans in WebLogic 8.1 and view the MBean information in a JMX Console like ManageEngine Applications Manager.

The main difference between this example and an example that registers MBeans in another JMX enabled server will be how you get the MBean Server reference. In WebLogic you get the MBean Server reference using the below code.


Quote:

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.management.ObjectName;

import weblogic.jndi.Environment;

import weblogic.management.MBeanHome;

import javax.management.MBeanServer;

…………

Environment env = new Environment();

env.setProviderUrl(”t3://localhost:7001″);

env.setSecurityPrincipal(”weblogic”); // username

env.setSecurityCredentials(”weblogic”); // password

Context myCtx = new InitialContext();

/* The below code gets the local WebLogic MBean server. It returns a WebLogic

specific object.

*/

MBeanHome mbeanHome = (MBeanHome)myCtx.lookup(”weblogic.management.home.localhome”);

/*

You get the JMX specific object from the MBeanHome. Version 8.1 and earlier are not

JMX 1.2 complaint and are more of JMX 1.x complaint.

*/

MBeanServer server = mbeanHome.getMBeanServer();

………………

Steps to try out:

1) Deploy the web application in Bea WebLogic.

You can deploy it by unzipping it into the /applications folder.

I tried this with WebLogic 8.1, using the examples domain.

Eg: Unzip this file to C:\bea\weblogic81\samples\domains\examples\applications

Since the ‘examples’ domain in WebLogic runs by default in development mode (PRODUCTION_MODE=false), this will be automatically picked up by WebLogic. Note the web application’s context is test_war.

2) Index page of web application : :/test_war/index.jsp” target=”_blank”>http://:/test_war/index.jsp

3) Click Register MBean

4) Click View MBean Values

Playing with the example:

On registering the MBean, a standard MBean gets registered with the WebLogic’s local M

Bean server.

Note : To compile the java code, you need to set the classpath to the relevant WebLogic jars.

I executed the setExamplesEnv.cmd script provided by WebLogic to set the classpath

Eg : C:\bea\weblogic81\samples\domains\examples\setExamplesEnv.cmd

A JMX Console will normally connect to an MBean Server using a connector. Here we will use the WebLogic JMX Connector to connect to the WebLogic’s MBean Server.

I have also listed some pointers below :

Web Page

Help Docs Page