Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Weblogic JMX API Example Using weblogic serverRuntime to monitor WebLogic Server State, Name, and shutdown WebLogic server

10 total views, 0 views today

WebLogic JMX API Example: Using Weblogic serverRuntime to print WebLogic server state, Name and shutdown WebLogic server

The Java code mentioned in this post connects to WebLogic server and prints the WebLogic server state, name, Oracle Home and all other server attributes. The WebLogic serverRuntime MBean code invokes the forceshutdown() to shut down the WebLogic server

Note: Add the C:\middleware1213\wlserver\server\lib\wljmxclient.jar if you connect to the WebLogic Server remotely

The WebLogic serverRuntime can be referred in the JConsole below:

Supported WebLogic ServerRuntimeMbean Attributes


Supported WebLogic ServerRuntimeBean Operations/Methods


Other WebLogic ServerRuntimeMBean properties can be referred in the below Java Class

https://docs.oracle.com/middleware/1221/wls/WLAPI/weblogic/management/runtime/ServerRuntimeMBean.html

The below Java code Prints server state, and other supported parameters using WebLogic ServerRuntimeMBean. Also, The Java JMX code force-shutdown all the WebLogic server.

package com.catgovind;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;

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;

import com.sun.xml.internal.bind.v2.runtime.output.StAXExStreamWriterOutput;

public class WeblogicMonitor {
	
	
	//Weblogic Histname and other credentials     
		private static String hostname = "localhost";
		private static String portString = "7001";
		private static String username = "weblogic";
		private static String password = "password123";

	// Weblogic JMX Connections 
	private static MBeanServerConnection connection;
    private static JMXConnector connector;
    private static final ObjectName service=null;
    ObjectName[]  atnProviders  = null;
    ObjectName mBeanTypeService = null;
 
		 //This method creates a WebLogic connection  Object
		 public static void initConnection() throws IOException,
		       MalformedURLException {
		 
		       String protocol = "t3";
		       Integer portInteger = Integer.valueOf(portString);
		       int port = portInteger.intValue();
		       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");
		       h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
		       connector = JMXConnectorFactory.connect(serviceURL, h);
		       connection = connector.getMBeanServerConnection();
		    }
	
	
 //This method prints WebLogic serverRuntime Properties 
 public static void displayWeblogicServerArguments() throws Exception {
     ObjectName[] serverRT = getServerRuntimes();
     System.out.println("got server runtimes");
     int length = (int) serverRT.length;
     for (int i = 0; i 


 OutPut

Server name = AdminServer. Server state: RUNNING

WebLogic Home = C:\middleware1213\wlserver

DefaultURL = t3://192.168.253.1:7001

SSL Listen Address = null

Current Directory = c:\middleware1213\user_projects\domains\p6\.

Administration URL = t3://192.168.253.1:7001



This post first appeared on Oracle ADF, BPM, BI And Primavera P6 Tutorials, please read the originial post: here

Share the post

Weblogic JMX API Example Using weblogic serverRuntime to monitor WebLogic Server State, Name, and shutdown WebLogic server

×

Subscribe to Oracle Adf, Bpm, Bi And Primavera P6 Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription

×