Hi All,

Jay SenSharma

Jay SenSharma

Here is a Simple JMX code which we can use to check the Current Status of Application deployed on the Oracle WebLogic Server.

import java.util.*;
import java.util.Enumeration;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.management.ObjectName;
import weblogic.jndi.Environment;
import weblogic.management.*;
import weblogic.management.runtime.*;
import javax.management.*;
public class ApplicationStatusChecker
{
MBeanServer server = null; // MBeanServer
MBeanHome mbeanHome=null;
Hashtable inStart = new Hashtable();
public ApplicationStatusChecker()
{
try {
Environment env = new Environment();
env.setProviderUrl(“t3://localhost:7001”);
env.setSecurityPrincipal(“weblogic”); // username
env.setSecurityCredentials(“weblogic”); // password
Context myCtx = env.getInitialContext();
mbeanHome =(MBeanHome)myCtx.lookup(“weblogic.management.home.localhome”);
server = mbeanHome.getMBeanServer();
}
catch (Exception ex)
{
System.err.println(“nntCannot get MBeanServer: “+ex);
}
}

public void getAllMBeans()
{
Set set=mbeanHome.getAllMBeans();
Iterator it=set.iterator();
while(it.hasNext())
{
System.out.println(“nt “+it.next());
}
}

public void getMBeanByType(String type)
{
System.out.println(“nnt NOTE: 2t Means ACTIVATED”);
System.out.println(“nnt NOTE: 1t Means PREPARED”);
System.out.println(“nnt NOTE: 0t Means UNPREPARED”);
Set set=mbeanHome.getMBeansByType(type);
Iterator it=set.iterator();
while(it.hasNext())
{
ApplicationRuntimeMBean appRun=(ApplicationRuntimeMBean)it.next();
System.out.print(“nntApplication Name: “+appRun.getApplicationName());
int n=appRun.getActiveVersionState();
String status=””;
if(n==0) status=”UNPREPARED”;
if(n==1) status=”PREPARED”;
if(n==2) status=”ACTIVATED”;
System.out.print(“t ***** : “+status);
}
}
public static void main(String ar[]) throws Exception
{
ApplicationStatusChecker sm=new ApplicationStatusChecker();
sm.getMBeanByType(“ApplicationRuntime”);
}
}

===================================

Below is the More Refined version of the Same Program

===================================

import java.util.*;
import java.util.Enumeration;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.management.ObjectName;
import weblogic.jndi.Environment;
import weblogic.management.*;
import weblogic.management.runtime.*;
import javax.management.*;
public class WebApplicationStatusChecker
{
MBeanServer server = null; // MBeanServer
MBeanHome mbeanHome=null;
Hashtable inStart = new Hashtable();
public WebApplicationStatusChecker()
{
try {
Environment env = new Environment();
env.setProviderUrl(“t3://localhost:7001”);
env.setSecurityPrincipal(“weblogic”); // username
env.setSecurityCredentials(“weblogic”); // password
Context myCtx = env.getInitialContext();
mbeanHome =(MBeanHome)myCtx.lookup(“weblogic.management.home.localhome”);
server = mbeanHome.getMBeanServer();
}
catch (Exception ex)
{
System.err.println(“nntCannot get MBeanServer: “+ex);
}
}

public void getAllMBeans()
{
Set set=mbeanHome.getAllMBeans();
Iterator it=set.iterator();
while(it.hasNext())
{
System.out.println(“nt “+it.next());
}
}

public void getMBeanByType(String type)
{
Set set=mbeanHome.getMBeansByType(type);
Iterator it=set.iterator();
while(it.hasNext())
{
WebAppComponentRuntimeMBean appRun=(WebAppComponentRuntimeMBean)it.next();
System.out.println(“t Application Name                  : “+appRun.getName());
System.out.println(“t Status                            :”+appRun.getStatus());
System.out.println(“t ContextRoot                       :”+appRun.getContextRoot());
System.out.println(“t ContextRoot                       :”+appRun.getContextRoot());
System.out.println(“=================================================”);
}

}
public static void main(String ar[]) throws Exception
{
WebApplicationStatusChecker sm=new WebApplicationStatusChecker();
sm.getMBeanByType(“WebAppComponentRuntime”);
}
}

=======================

regards

JaySenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.