How to access server MBean properties at weblogic 11g using Java – JMX

Hi,

If you want to get any property of Admin or Managed Server (Weblogic) using Java, then this post will help you.

The Oracle Enterprise Manager have a useful tool for explore MBean (System MBean Browser).

As you can see in the picture bellow:

Do you can to capture any server property desired with these java code:

1 – Reading a property if the application is deployed at server (local connection)

import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.InitialContext;

String serverName = System.getProperty("weblogic.Name");
InitialContext ctx = new InitialContext();
MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");
ObjectName objName = new ObjectName("com.bea:Name=" + serverName + ",Type=Server");
String pathJKS = (String) server.getAttribute(objName, "CustomTrustKeyStoreFileName");

2 – Reading a property if the application is remote (remote connection)

import java.util.Hashtable;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

  public static void main(String [] args) throws Exception{
    String serverName = "AdminServer";
    String hostName = "192.168.1.192";
    String username = "weblogic";
    String password = "welcome1";
    int port = 10000;
    String protocol = "t3";
    String jndiroot = "/jndi/";
    String mserver = "weblogic.management.mbeanservers.domainruntime";
    JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostName, port, jndiroot + mserver);
    Hashtable h = new Hashtable();
    h.put(Context.SECURITY_PRINCIPAL, username);
    h.put(Context.SECURITY_CREDENTIALS, password);
    h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
    JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
    ObjectName objName = new ObjectName("com.bea:Name=" + serverName + ",Type=Server");
    String pathJKS = (String) connector.getMBeanServerConnection().getAttribute(objName, "CustomTrustKeyStoreFileName");
    System.out.println(pathJKS);
  }

In the cases above, i’m reading a property that is called “CustomTrustKeyStoreFileName”, that’s a string path of the Trusted Keystore. But many and many properties could be read, for example:

  • CustomIdentityKeyStoreFileName
  • ListenPort
  • UploadDirectoryName

That’s it.

Victor Jabur

About these ads

9 Responses to How to access server MBean properties at weblogic 11g using Java – JMX

  1. Andy says:

    I deployed my web application to a managed server. I want to get the name of that managed server in my web servlet. Do you know how to do that?

    I’m using WL 10.3.2

    Thanks

  2. website says:

    I rarely drop remarks, but I read a bunch of responses on
    this page How to access server MBean properties at weblogic 11g using Java – JMX | Victor Jabur’s Blog.
    I do have a couple of questions for you if it’s okay.
    Is it only me or do a few of the responses look like they are written by brain dead individuals? :-P And, if you are writing on additional online sites, I’d like to keep up with anything fresh you have to post.
    Could you list of the complete urls of all your social community pages like your
    linkedin profile, Facebook page or twitter feed?

  3. Migo says:

    is it normal to provide passwords in clear text? Is it possible to use Foreign JNDI providers instead?

    • victorjabur says:

      No. Is not normal to provide passwords in clear text. This post is an example of shat is possible, but not always recommended for any scenarios. The foreign jndi is the most common use to acess resources on the weblogic

  4. mobile games says:

    I have been exploring for a little bit for any high quality articles or blog posts in this kind of space .

    Exploring in Yahoo I at last stumbled upon this site. Studying this info So i am happy to exhibit that I have an
    incredibly just right uncanny feeling I discovered just what I needed.
    I most surely will make sure to don?t omit this website and give it a look regularly.

  5. Howdy! I could have sworn I’ve been to this blog before but after checking through some of
    the post I realized it’s new to me. Anyways, I’m definitely happy I found
    it and I’ll be bookmarking and checking back often!

  6. Petar says:

    Thank you so much. This is only working example of local and remote usage of MBeans for WL. Thanks a bunch !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 606 other followers

%d bloggers like this: