Monthly Archive: November 2015

Shared Library example for Oracle Weblogic Server

1. Compile your code and package it in a jar file. In this example I have written a simple program that has a function that just takes a string as input and prints hello infront of the string.


package wonders;

public class MyTestClass

static {
System.out.println("MyTestClass class Loaded From sf1.jar");

public String sayHello(String name)
System.out.println("sf1.jar sayHello() called"); ;
return name;


2. Deploy the jar file on the server as a library.

3. Refer the shared library in the weblogic-application.xml present under EAR\META-INF folder.


<?xml version="1.0" encoding="ISO-8859-1"?>

<weblogic-application xmlns="” 



4. Access the library from your application. In my example I am calling the function from a jsp.

 <body> Hi this is hello from sl1.jar<BR> 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="wonders.*" %>
 <% wonders.MyTestClass mtc=new wonders.MyTestClass(); 
 System.out.println("Hello to "+ mtc.sayHello("Wonders")); %> 


shared library


shared library1

Using WLDF to view Historical Data

1. Go to the Home Page and click on Monitoring Dashboard under charts & graph

charts and graph

2. This will open the dashboard in a new tab. There are some built in views. You can select JVM Runtime Heap and click on the start button on the top.


3. You should be able to see the Heap Size Current ( Yellow Line) and Heap Free Current ( Blue Line)

JVM Runtime Heap View


4. You can also change the chart type

bar graph

5. You can create your own view’s as well to monitor. Select My Views and click on New symbol on the top.

New View

6. Create the view and go to Metric Browser. Select the server. Select the Mbean Type, Instance and the attribute you want to monitor.

Operating System Mbean

7. Select your view and create a new chart, add a metric and then start the recording. You can add multiple metrics as I have done in this example. I am monitoring the System Load, Process CPU Time and Total Physical Memory.

New chart

add metric


JMX Code to print Datasource Status

You need to provide the server host name and port number in the JMX code and also set the class path before compiling it.

import java.util.Hashtable;
import org.apache.log4j.Logger;

import javax.naming.Context;

public class WLMonitMain {

    private static MBeanServerConnection connection;
    private static JMXConnector connector;
    private static ObjectName service;
    static Logger log = Logger.getLogger(WLMonitMain.class.getName());

    static {

        try {

            service = new ObjectName(
                    + "");
        } catch (MalformedObjectNameException e) {
            throw new AssertionError(e.getMessage());

    public static void initConnection(String hostname, String portString,
            String username, String password) throws IOException,
            MalformedURLException {
        String protocol = "t3";
        Integer portInteger = Integer.valueOf(portString);
        int port = portInteger.intValue();
        String jndiroot = "/jndi/";
        String mserver = "";
        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);
        connector = JMXConnectorFactory.connect(serviceURL, h);
        connection = connector.getMBeanServerConnection();

    public static void testMethod() {

        try {


            ObjectName serverRuntime = (ObjectName) connection.getAttribute(service, "ServerRuntime");
            String name = (String) connection.getAttribute(serverRuntime,"Name");
            ObjectName jvmRuntime = new ObjectName("com.bea:ServerRuntime="+name+",Name="+name+",Type=JVMRuntime");
            System.out.println("Heap Free Percent"+connection.getAttribute(jvmRuntime, "HeapFreePercent"));
            log.debug("Heap Free Percent"+connection.getAttribute(jvmRuntime, "HeapFreePercent"));
            ObjectName jdbcRuntime= new ObjectName("com.bea:ServerRuntime="+name+",Name="+name+",Type=JDBCServiceRuntime");
            ObjectName[] dataSourceArray = (ObjectName[]) connection.getAttribute(jdbcRuntime,"JDBCDataSourceRuntimeMBeans");
             for (int j = 0; j < dataSourceArray.length; j++){   
			   String poolName = (String)connection.getAttribute(dataSourceArray[j], "Name");
                           ObjectName jdbcDatasourceRuntime = new ObjectName("com.bea:ServerRuntime="+name+",Name="+poolName+",Type=JDBCDataSourceRuntime");
			   System.out.println("Datasource Status "+connection.getAttribute(jdbcDatasourceRuntime, "State"));
                 "Datasource Status "+connection.getAttribute(jdbcDatasourceRuntime, "State"));

        } catch (Exception e) {

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

        String hostname = "localhost";
        String portString = "7001";
        String username = "weblogic";
        String password = "weblogic123";
        System.out.println("initializing connection");
        initConnection(hostname, portString, username, password);





How to decrypt WebLogic Datasource Password

You need to copy the datasource password present in the -jdbc.xml present under \config\jdbc to the password variable in the WLST Script.



Change the path variable to point to your domain

from import *
from import *

password = "{AES}0+5YrFk+fD9BFIykr3H+wPsNmPRP/GIOUId7SPqBgNg="
path = "D:/Oracle/Middleware/user_projects/domains/pega7_domain/security"
encryptionService = SerializedSystemIni.getEncryptionService(path)
cService = ClearOrEncryptedService(encryptionService)
print "password: " + cService.decrypt(password)

Execute the above script after setting the environment
>java weblogic.WLST

You should see the decrypted password in the terminal.