Accessing Weblogic mbeans in BPEL Part 1

Weblogic Server provides runtime MBeans which provide information about the runtime state of its resources. The entry point for these MBeans are the MBeanServer Services. There are two Runtime MBeans, the DomainRuntimeServiceMBean, which is only available at the Administration Server and the RuntimeServiceMBean which is the entry point for WLS runtime MBeans for the current server. WLS runtime MBeans can provide information about the runtime state of WebLogic Server resources. An overview of the available Runtime MBeans can be found in the Weblogic Server MBean Reference. Sometimes it can be useful to retrieve data from these Runtime MBeans in a BPEL process. For example the name of the Weblogic domain, the machine or the managed server whereon the BPEL process is running.

Here is an example how you can retrieve the Weblogic Domain Name, Machine Name and Server Name whereon the BPEL instance is running.

Create a new SOA Application MBean_By_Example using the SOA Application template.
Screenshot-Create SOA Application - Step 1 of 3

Add a project MBeanExampleOne and add SOA as the selected Project Technology.
Screenshot-Create SOA Application - Step 2 of 3

Leave the composite name unchanged and select the Composite Template Composite With BPEL Process
Screenshot-Create SOA Application - Step 3 of 3

Select in the Create BPEL Process window
BPEL 2.0 Specification
Name: BPELProcess
Template: Synchronous BPEL Process
Screenshot-Create BPEL Process

Open the BPEL Process BPELProcess in the composite and change to the Source view.
Paste the following import elements just after the import of the BPELProcess.wsdl.
    <!-- import java classes -->
    <import location="javax.naming.InitialContext" importType=""/>
    <import location="" importType=""/>
    <import location="" importType=""/>

After pasting the code it will look similar to the screenshot below. Switch back to the Design view.

Now add a Java Embedding activity after the receiveInput and cut-and-past the following Java Code Snippet. This code makes a local connection to the Runtime MBean server and moves along various MBeans to retrieve the requested attributes.

String weblogicDomainName = "Unknown" ; 
String machineName = "Unknown" ;
String serverName = "Unknown" ;
String message = "na" ;

InitialContext ctx = null ; 

try { 
    // Make local connecion to Runtime MBean Server 
    ctx = new InitialContext(); 
    MBeanServer beanServer  = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime"); 

    // Get RuntimeServiceMBean 
   ObjectName runtimeService = new ObjectName("com.bea:Name=RuntimeService,"); 

   // Retrieve DomainConfiguration MBean from RuntimeServiceMBean 
   ObjectName domainCFG = (ObjectName) beanServer.getAttribute(runtimeService, "DomainConfiguration"); 

   // Get Weblogic DomainName *attribute) from DomainConfiguration MBean
   weblogicDomainName = (String) beanServer.getAttribute(domainCFG, "Name"); 

   // Retrieve ServerConfiguration MBean from RuntimeService MBean
   ObjectName serverCFG = (ObjectName) beanServer.getAttribute(runtimeService, "ServerConfiguration"); 

   // Retrieve Machine MBean from ServerConfiguration MBean
   ObjectName machineCFG = (ObjectName) beanServer.getAttribute(serverCFG, "Machine");

   // Retrieve Machine Name from Machine MBean
   machineName = (String) beanServer.getAttribute(machineCFG, "Name");

   // Retrieve ManagedServer Name from ServerConfiguration MBean
   serverName = (String) beanServer.getAttribute(serverCFG, "Name");
} catch (Exception ex) { 

   message = "Exception occured in embedded Java action ;" + ex ; 


setVariableData("Variable1","Weblogic Domain:" + weblogicDomainName + " Machine:" + machineName + " Server:" + serverName + " ; " + message);

The output of the Java Code Snippet is written to the BPEL variable Variable1. To return this output when invoking the BPEL process, the output has to be assigned to the variable used in the BPEL Reply activity. To do this, create the variable Variable1 of Simple Type String at the main scope, add an Assign Activity after the Java Embedding Activity and copy the value of Variable 1 to the element result in the variable outputVariable.

Screen Shot Assign

Deploy the MBeanExampleOne composite and test it in your Enterprise Manager Console.

Screen Shot Response

blog comments powered by Disqus