Thursday, April 3, 2014

Getting the Messaging Bridge Runtime Details through Java - Weblogic

Getting the Messaging Bridge Runtime Details through Java - Weblogic

The below java jmx code will help us to get the run time details of the messaging bridge in weblogic server.

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

public class GetMessageBridgeStatus {
    private static MBeanServerConnection connection;
    private static JMXConnector connector;
    public static void  getMessageBridgeStatus() {
        try
        {
                getRuntimeMBeanServerConnection();
                String son = "com.bea:ServerRuntime=AdminServer,Name=Bridge-0,Location=AdminServer,Type=MessagingBridgeRuntime";
                ObjectName service = new ObjectName(son);
                String status = connection.getAttribute(service,"State").toString();
                System.out.println("Status: "+status);
         
                String description = connection.getAttribute(service,"Description").toString();
                System.out.println("Descrption: "+description);
       
        }catch(Exception e) {
           e.printStackTrace();
        }
         
    }
    public static void getRuntimeMBeanServerConnection()  throws Exception{
          String jndiroot = "/jndi/";
          String mserver = "weblogic.management.mbeanservers.domainruntime";
          JMXServiceURL serviceURL = new JMXServiceURL("t3", "localhost", 8000,jndiroot + mserver);
          Hashtable h = new Hashtable();
          h.put(Context.SECURITY_PRINCIPAL, "weblogic");
          h.put(Context.SECURITY_CREDENTIALS, "welcome1");
          h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");
          connector = JMXConnectorFactory.connect(serviceURL, h);
          connection = connector.getMBeanServerConnection();
    }
 
    public static void main(String[] args) {
        getMessageBridgeStatus();
    }
 
}


Include the wlfullclient.jar file in the class path(Refer the following post https://www.albinsblog.com/2012/07/creating-wlfullclientjar-weblogic.html to generate the wlfullclient.jar )

2 comments:

  1. import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.PrintStream;
    import java.util.ArrayList;
    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.List;
    import javax.management.MBeanServerConnection;
    import javax.management.ObjectName;
    import javax.management.remote.JMXConnector;
    import javax.management.remote.JMXConnectorFactory;
    import javax.management.remote.JMXServiceURL;
    import javax.naming.Context;

    public class GetMessageBridgeStatus {
    private static MBeanServerConnection connection;
    private static JMXConnector connector;
    public static void getMessageBridgeStatus(String hostname, int portString, String username, String password, String path) {
    try
    {
    getRuntimeMBeanServerConnection(hostname,portString,username,password);
    String wlname="Weblogic";
    List bridgeName = new ArrayList();

    bridgeName.add(0, "amdocsBeans.FulfillmentOrderSvcJMS.bridge");
    bridgeName.add(1, "amdocsBeans.NotifyFulfillmentOrderSvcJMS.bridge");
    PrintStream o = new PrintStream(new File(System.getProperty("user.dir") + " bridge.txt "));
    PrintStream console = System.out;

    System.out.println(path);
    System.out.println("------" + System.getProperty("user.dir") );


    Iterator iterator = bridgeName.iterator();
    while(iterator.hasNext()){
    String bName = iterator.next();

    String son = "com.bea:ServerRuntime="+wlname+",Name="+bName+",Location="+wlname+",Type=MessagingBridgeRuntime";
    ObjectName service = new ObjectName(son);
    String status = connection.getAttribute(service,"State").toString();
    String description = connection.getAttribute(service,"Description").toString();

    System.setOut(o);
    System.out.println(bName+" , "+status+" , "+description);


    System.setOut(console);
    System.out.println(bName+" , "+status+" , "+description);

    }
    }catch(Exception e) {
    e.printStackTrace();
    }

    }
    public static void getRuntimeMBeanServerConnection(String hostname, int portString, String username, String password) throws Exception{
    String jndiroot = "/jndi/";
    String mserver = "weblogic.management.mbeanservers.domainruntime";
    JMXServiceURL serviceURL = new JMXServiceURL("t3", hostname, portString ,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");
    connector = JMXConnectorFactory.connect(serviceURL, h);
    connection = connector.getMBeanServerConnection();
    }

    public static void main(String[] args) throws FileNotFoundException {

    String hostname = args[0];
    int portString = Integer.parseInt(args[1]);
    String username = args[2];
    String password = args[3];
    String path = args[4];
    getMessageBridgeStatus(hostname,portString,username,password,path);
    }

    }

    ReplyDelete
  2. Command Line Arguments for the above code are :
    indlin2717 23101 system password123 C:\Users\abc\WORK\Usm\src


    and "PrintStream" is used to get the status in a TEXT FILE and on CONSOLE.

    ReplyDelete