At a public sector organization in the Netherlands there was the need to make an inventory of the deployed OSB services in order to find out, the dependencies with certain external web services (which were on a list to become deprecated).
For this, in particular the endpoints of business services were of interest.
Besides that, the dependencies between services and also the Message Flow per proxy service was of interest, in particular Operational Branch, Route, Java Callout and Service Callout actions.
Therefor an OSBServiceExplorer tool was developed to explore the services (proxy and business) within the OSB via WebLogic Server MBeans with JMX. For now, this tool was merely used to quickly return the information needed, but in the future it can be the basis for a more comprehensive one.
This article will explain how the OSBServiceExplorer tool uses WebLogic Server MBeans with JMX.
The code mentioned in this article is based on Oracle Service Bus 11.1.1.7.
If you are interested in general information about, using MBeans with JMX, I kindly point you to another article (written be me) on the AMIS TECHNOLOGY BLOG: “Oracle Service Bus : disable / enable a proxy service via WebLogic Server MBeans with JMX”, via url: https://technology.amis.nl/2017/02/28/oracle-service-bus-disable-enable-a-proxy-service-via-weblogic-server-mbeans-with-jmx/
Remark: Some names in the examples in this article are in Dutch, but don’t let this scare you off.
MBeans
For ease of use, a ms-dos batch file was created, using MBeans, to explore services (proxy and business). The WebLogic Server contains a set of MBeans that can be used to configure, monitor and manage WebLogic Server resources.
On a server, the ms-dos batch file “OSBServiceExplorer.bat” is called.
The content of the ms-dos batch file “OSBServiceExplorer.bat” is:
java.exe -classpath “OSBServiceExplorer.jar;com.bea.common.configfwk_1.7.0.0.jar;sb-kernel-api.jar;sb-kernel-impl.jar;wlfullclient.jar” nl.xyz.osbservice.osbserviceexplorer. OSBServiceExplorer “xyz” “7001” “weblogic” “xyz”
In the ms-dos batch file via java.exe a class named OSBServiceExplorer is being called. The main method of this class expects the following parameters:
Parameter name | Description |
HOSTNAME | Host name of the AdminServer |
PORT | Port of the AdminServer |
USERNAME | Username |
PASSWORD | Passsword |
In the sample code shown at the end of this article, the use of the following MBeans can be seen:
- DomainRuntimeServiceMBean (weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean.class part of <Middleware Home Directory>/wlserver_10.3/server/lib/wlfullclient.jar)
Provides a common access point for navigating to all runtime and configuration MBeans in the domain as well as to MBeans that provide domain-wide services (such as controlling and monitoring the life cycles of servers and message-driven EJBs and coordinating the migration of migratable services). [https://docs.oracle.com/middleware/1213/wls/WLAPI/weblogic/management/mbeanservers/domainruntime/DomainRuntimeServiceMBean.html]
This library is not by default provided in a WebLogic install and must be build. The simple way of how to do this is described in “Fusion Middleware Programming Stand-alone Clients for Oracle WebLogic Server, Using the WebLogic JarBuilder Tool”, which can be reached via url: https://docs.oracle.com/cd/E28280_01/web.1111/e13717/jarbuilder.htm#SACLT240.
- ServerRuntimeMBean (weblogic.management.runtime.ServerRuntimeMBean.class part of <Middleware Home Directory>/wlserver_10.3/server/lib/wlfullclient.jar)
Provides methods for retrieving runtime information about a server instance and for transitioning a server from one state to another. [https://docs.oracle.com/cd/E11035_01/wls100/javadocs_mhome/weblogic/management/runtime/ServerRuntimeMBean.html]
- ALSBConfigurationMBean (com.bea.wli.sb.management.configuration.ALSBConfigurationMBean.class part of <Middleware Home Directory>/Oracle_OSB1/lib/sb-kernel-api.jar)
Provides various API to query, export and import resources, obtain validation errors, get and set environment values, and in general manage resources in an ALSB domain. [https://docs.oracle.com/cd/E13171_01/alsb/docs26/javadoc/com/bea/wli/sb/management/configuration/ALSBConfigurationMBean.html]
Once the connection to the DomainRuntimeServiceMBean is made, other MBeans can be found via the findService method.
Service findService(String name, String type, String location)
This method returns the Service on the specified Server or in the primary MBeanServer if the location is not specified.
In the sample code shown at the end of this article, certain java fields are used. For reading purposes the field values are shown in the following table:
Because of the use of com.bea.wli.config.Ref.class , the following library <Middleware Home Directory>/Oracle_OSB1/modules/com.bea.common.configfwk_1.7.0.0.jar was needed.
A Ref uniquely represents a resource, project or folder that is managed by the Configuration Framework.
A special Ref DOMAIN refers to the whole domain.
[https://docs.oracle.com/cd/E17904_01/apirefs.1111/e15033/com/bea/wli/config/Ref.html]
Because of the use of weblogic.management.jmx.MBeanServerInvocationHandler.class , the following library <Middleware Home Directory>/wlserver_10.3/server/lib/wlfullclient.jar was needed.
When running the code the following error was thrown:
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.bea.wli.sb.management.configuration.DelegatedALSBConfigurationMBean at weblogic.management.jmx.MBeanServerInvocationHandler.newProxyInstance(MBeanServerInvocationHandler.java:621) at weblogic.management.jmx.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:418) at $Proxy0.findService(Unknown Source) at nl.xyz.osbservice.osbserviceexplorer.OSBServiceExplorer.<init>(OSBServiceExplorer.java:174) at nl.xyz.osbservice.osbserviceexplorer.OSBServiceExplorer.main(OSBServiceExplorer.java:445) Caused by: java.lang.ClassNotFoundException: com.bea.wli.sb.management.configuration.DelegatedALSBConfigurationMBean at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at weblogic.management.jmx.MBeanServerInvocationHandler.newProxyInstance(MBeanServerInvocationHandler.java:619) ... 4 more Process exited.
So because of the use of com.bea.wli.sb.management.configuration.DelegatedALSBConfigurationMBean.class the following library <Middleware Home Directory>/Oracle_OSB1/lib/sb-kernel-impl.jar was also needed.
Runtime information (name and state) of the server instances
The OSBServiceExplorer tool writes its output to a text file called “OSBServiceExplorer.txt”.
First the runtime information (name and state) of the server instances (Administration Server and Managed Servers) of the WebLogic domain are written to file.
Example content fragment of the text file:
Found server runtimes: - Server name: AdminServer. Server state: RUNNING - Server name: ManagedServer1. Server state: RUNNING - Server name: ManagedServer2. Server state: RUNNING
See the code fragment below:
fileWriter.write("Found server runtimes:\n"); int length = (int)serverRuntimes.length; for (int i = 0; i < length; i++) { ServerRuntimeMBean serverRuntimeMBean = serverRuntimes[i]; String name = serverRuntimeMBean.getName(); String state = serverRuntimeMBean.getState(); fileWriter.write("- Server name: " + name + ". Server state: " + state + "\n"); } fileWriter.write("" + "\n");
List of Ref objects (projects, folders, or resources)
Next, a list of Ref objects is written to file, including the total number of objects in the list.
Example content fragment of the text file:
Found total of 1132 refs, including the following proxy and business services: … - ProxyService: JMSConsumerStuFZKNMessageService-1.0/proxy/JMSConsumerStuFZKNMessageService_PS … - ProxyService: ZKN ZaakService-2.0/proxy/UpdateZaak_Lk01_PS … - BusinessService: ZKN ZaakService-2.0/business/eBUS/eBUS_FolderService_BS
See the code fragment below:
Set refs = alsbConfigurationMBean.getRefs(Ref.DOMAIN); fileWriter.write("Found total of " + refs.size() + " refs, including the following proxy and business services:\n"); for (Ref ref : refs) { String typeId = ref.getTypeId(); if (typeId.equalsIgnoreCase("ProxyService")) { fileWriter.write("- ProxyService: " + ref.getFullName() + "\n"); } else if (typeId.equalsIgnoreCase("BusinessService")) { fileWriter.write("- BusinessService: " + ref.getFullName() + "\n"); } else { //fileWriter.write(ref.getFullName()); } } fileWriter.write("" + "\n");
As mentioned before, a Ref object uniquely represents a resource, project or folder. A Ref object has two components:
- typeId that indicates whether it is a project, folder, or a resource
- array of names of non-zero length.
For a resource the array of names start with the project name, followed by folder names, and end with the resource name.
For a project, the Ref object simply contains one name component, that is, the project name.
A Ref object for a folder contains the project name followed by the names of the folders which it is nested under.
[https://docs.oracle.com/cd/E17904_01/apirefs.1111/e15033/com/bea/wli/config/Ref.html]
Below is an example of a Ref object that represents a folder (via JDeveloper Debug):
Below is an example of a Ref object that represents a resource (via JDeveloper Debug):
ResourceConfigurationMBean
In order to be able to determine the actual endpoints of the proxy services and business services, the ResourceConfigurationMBean is used. When connected, the Service Bus MBeans are located under com.oracle.osb. [https://technology.amis.nl/2014/10/20/oracle-service-bus-obtaining-list-exposed-soap-http-endpoints/]
When we look at the java code, as a next step, the names of a set of MBeans specified by pattern matching are put in a list and looped through.
Once the connection to the DomainRuntimeServiceMBean is made, other MBeans can be found via the queryNames method.
Set queryNames(ObjectName name, QueryExp query) throws IOException
Gets the names of MBeans controlled by the MBean server. This method enables any of the following to be obtained: The names of all MBeans, the names of a set of MBeans specified by pattern matching on the ObjectName and/or a Query expression, a specific MBean name (equivalent to testing whether an MBean is registered). When the object name is null or no domain and key properties are specified, all objects are selected (and filtered if a query is specified). It returns the set of ObjectNames for the MBeans selected.
[https://docs.oracle.com/javase/7/docs/api/javax/management/MBeanServerConnection.html]
See the code fragment below:
String domain = "com.oracle.osb"; String objectNamePattern = domain + ":" + "Type=ResourceConfigurationMBean,*"; SetosbResourceConfigurations = connection.queryNames(new ObjectName(objectNamePattern), null); fileWriter.write("ResourceConfiguration list of proxy and business services:\n"); for (ObjectName osbResourceConfiguration : osbResourceConfigurations) { … String canonicalName = osbResourceConfiguration.getCanonicalName(); fileWriter.write("- Resource: " + canonicalName + "\n"); … }
The pattern used is: com.oracle.osb:Type=ResourceConfigurationMBean,*
Example content fragment of the text file:
ResourceConfiguration list of proxy and business services: … - Resource: com.oracle.osb:Location=AdminServer,Name=ProxyService$ZKN ZaakService-2.0$proxy$UpdateZaak_Lk01_PS,Type=ResourceConfigurationMBean …
Below is an example of an ObjectName object (via JDeveloper Debug), found via the queryNames method:
Via the Oracle Enterprise Manager Fusion Middleware Control for a certain domain, the System MBean Browser can be opened. Here the previously mentioned ResourceConfigurationMBean’s can be found.
[Via MBean Browser]
The information on the right is as follows (if we navigate to a particular ResourceConfigurationMBean, for example …$UpdateZaak_Lk01_PS) :
[Via MBean Browser]
Here we can see that the attributes Configuration and Metadata are available:
- Configuration
[Via MBean Browser]
The Configuration is made available in java by the following code fragment:
CompositeDataSupport configuration = (CompositeDataSupport)connection.getAttribute(osbResourceConfiguration,"Configuration");
- Metadata
[Via MBean Browser]
The Metadata is made available in java by the following code fragment:
CompositeDataSupport metadata = (CompositeDataSupport)connection.getAttribute(osbResourceConfiguration,"Metadata");
Diving into attribute Configuration of the ResourceConfigurationMBean
For each found proxy and business service the configuration information (canonicalName, service-type, transport-type, url) is written to file.
See the code fragment below:
String canonicalName = osbResourceConfiguration.getCanonicalName(); … String servicetype = (String)configuration.get("service-type"); CompositeDataSupport transportconfiguration = (CompositeDataSupport)configuration.get("transport-configuration"); String transporttype = (String)transportconfiguration.get("transport-type"); … fileWriter.write(" Configuration of " + canonicalName + ":" + " service-type=" + servicetype + ", transport-type=" + transporttype + ", url=" + url + "\n");
Proxy service configuration:
Below is an example of a proxy service configuration (content fragment of the text file):
Configuration of com.oracle.osb:Location=AdminServer,Name=ProxyService$ZKN ZaakService-2.0$proxy$UpdateZaak_Lk01_PS,Type=ResourceConfigurationMBean: service-type=Abstract SOAP, transport-type=local, url=local
The proxy services which define the exposed endpoints, can be recognized by the ProxyService$ prefix.
[Via MBean Browser]
For getting the endpoint, see the code fragment below:
String url = (String)transportconfiguration.get("url");
Business service configuration:
Below is an example of a business service configuration (content fragment of the text file):
Configuration of com.oracle.osb:Location=AdminServer,Name=BusinessService$ZKN ZaakService-2.0$business$eBUS$eBUS_FolderService_BS,Type=ResourceConfigurationMBean: service-type=SOAP, transport-type=http, url=http://xyz/eBus/FolderService.svc
The business services which define the exposed endpoints, can be recognized by the BusinessService$ prefix.
[Via MBean Browser]
For getting the endpoint, see the code fragment below:
CompositeData[] urlconfiguration = (CompositeData[])transportconfiguration.get("url-configuration"); String url = (String)urlconfiguration[0].get("url");
So, via the url key found in the business service configuration, the endpoint of a business service can be found (for example: http://xyz/eBus/FolderService.svc). So in that way the dependencies (proxy and/or business services) with certain external web services (having a certain endpoint), could be found.
Proxy service pipeline, element hierarchy
For a proxy service the elements (nodes) of the pipeline are investigated.
See the code fragment below:
CompositeDataSupport pipeline = (CompositeDataSupport)configuration.get("pipeline"); TabularDataSupport nodes = (TabularDataSupport)pipeline.get("nodes");
[Via MBean Browser]
Below is an example of a nodes object (via JDeveloper Debug):
If we take a look at the dataMap object, we can see nodes of different types.
Below is an example of a node of type Stage (via JDeveloper Debug):
Below is an example of a node of type Action and label ifThenElse (via JDeveloper Debug):
Below is an example of a node of type Action and label wsCallout (via JDeveloper Debug):
For the examples above the Message Flow part of the UpdateZaak_Lk01_PS proxy service looks like:
The mapping between the node-id and the corresponding element in the Messsage Flow can be achieved by looking in the .proxy file (in this case: UpdateZaak_Lk01_PS.proxy) for the _ActiondId- identification, mentioned as value for the name key.
<con:stage name="EditFolderZaakStage"> <con:context> … </con:context> <con:actions> <con3:ifThenElse> <con2:id>_ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7c84</con2:id> <con3:case> <con3:condition> … </con3:condition> <con3:actions> <con3:wsCallout> <con2:id>_ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7b7f</con2:id> …
The first node in the dataMap object (via JDeveloper Debug) looks like:
The dataMap object is of type HashMap. A hashMap maintains key and value pairs and often denoted as HashMap<Key, Value> or HashMap<K, V>. HashMap implements Map interface
As can be seen, the key is of type Object and the value of type CompositeData.
In order to know what kind of information is delivered via the CompositeData object, the rowType object can be used.
See the code fragment below:
TabularType tabularType = nodes.getTabularType(); CompositeType rowType = tabularType.getRowType();
Below is an example of a rowType object (via JDeveloper Debug):
From this it is now clear that the CompositeData object for a ProxyServicePipelineElementType contains:
Index | key | value |
0 | children | Children of this node |
1 | label | Label |
2 | name | Name of the node |
3 | node-id | Id of this node unique within the graph |
4 | type | Pipeline element type |
In the code fragment below, an iterator is used to loop through the dataMap object.
Iterator keyIter = nodes.keySet().iterator(); for (int j = 0; keyIter.hasNext(); ++j) { Object[] key = ((Collection)keyIter.next()).toArray(); CompositeData compositeData = nodes.get(key); … }
The key object for the first node in the dataMap object (via JDeveloper Debug) looks like:
The value of this key object is 25, which also is shown as the value for the node-id of the compositeData object, which for the first node in the dataMap object (via JDeveloper Debug) looks like:
It’s obvious that the nodes in the pipeline form a hierarchy. A node can have children, which in turn can also have children, etc. Think for example of a “Stage” having an “If Then” action which in turn contains several “Assign” actions. A proxy service Message Flow can of course contain all kinds of elements (see the Design Palette).
Below is (for another proxy service) an example content fragment of the text file, that reflects the hierarchy:
Index#76: level = 1 label = branch-node name = CheckOperationOperationalBranch node-id = 62 type = OperationalBranchNode children = [42,46,50,61] level = 2 node-id = 42 children = [41] level = 3 label = route-node name = creeerZaak_Lk01RouteNode node-id = 41 type = RouteNode children = [40] level = 4 node-id = 40 children = [39] level = 5 label = route name = _ActionId-4977625172784205635-3567e5a2.15364c39a7e.-7b99 node-id = 39 type = Action children = [] level = 2 node-id = 46 children = [45] level = 3 label = route-node name = updateZaak_Lk01RouteNode node-id = 45 type = RouteNode children = [44] level = 4 node-id = 44 children = [43] level = 5 label = route name = _ActionId-4977625172784205635-3567e5a2.15364c39a7e.-7b77 node-id = 43 type = Action children = [] …
Because of the interest in only certain kind of nodes (Route, Java Callout, Service Callout, etc.) some kind of filtering is needed. For this the label and type keys are used.
See the code fragment below:
String label = (String)compositeData.get("label"); String type = (String)compositeData.get("type"); if (type.equals("Action") && (label.contains("wsCallout") || label.contains("javaCallout") || label.contains("route"))) { fileWriter.write(" Index#" + j + ":\n"); printCompositeData(nodes, key, 1); } else if (type.equals("OperationalBranchNode") || type.equals("RouteNode")) { fileWriter.write(" Index#" + j + ":\n"); printCompositeData(nodes, key, 1); }
Example content fragment of the text file:
Index#72: level = 1 label = wsCallout name = _ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7b7f node-id = 71 type = Action children = [66,70] Index#98: level = 1 label = wsCallout name = _ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7997 node-id = 54 type = Action children = [48,53] Index#106: level = 1 label = wsCallout name = _ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7cf4 node-id = 35 type = Action children = [30,34]
When we take a closer look at the node of type Action and label wsCallout with index 106, this can also be found in the MBean Browser:
[Via MBean Browser]
The children node-id’s are 30 (a node of type Sequence and name requestTransform, also having children) and 34 (a node of type Sequence and name responseTransform, also having children).
Diving into attribute Metadata of the ResourceConfigurationMBean
For each found proxy service the metadata information (dependencies and dependents) is written to file.
See the code fragment below:
fileWriter.write(" Metadata of " + canonicalName + "\n"); String[] dependencies = (String[])metadata.get("dependencies"); fileWriter.write(" dependencies:\n"); int size; size = dependencies.length; for (int i = 0; i < size; i++) { String dependency = dependencies[i]; if (!dependency.contains("Xquery")) { fileWriter.write(" - " + dependency + "\n"); } } fileWriter.write("" + "\n"); String[] dependents = (String[])metadata.get("dependents"); fileWriter.write(" dependents:\n"); size = dependents.length; for (int i = 0; i < size; i++) { String dependent = dependents[i]; fileWriter.write(" - " + dependent + "\n"); } fileWriter.write("" + "\n");
Example content fragment of the text file:
Metadata of com.oracle.osb:Location=AdminServer,Name=ProxyService$ZKN ZaakService-2.0$proxy$UpdateZaak_Lk01_PS,Type=ResourceConfigurationMBean dependencies: - BusinessService$ZKN ZaakService-2.0$business$eBUS$eBUS_FolderService_BS - XMLSchema$CDM$Interface$StUF-ZKN_1_1_02$zkn0310$mutatie$zkn0310_msg_mutatie - BusinessService$ZKN ZaakService-2.0$business$eBUS$eBUS_SearchService_BS - BusinessService$ZKN ZaakService-2.0$business$eBUS$eBUS_LookupService_BS dependents: - ProxyService$JMSConsumerStuFZKNMessageService-1.0$proxy$JMSConsumerStuFZKNMessageService_PS - ProxyService$ZKN ZaakService-2.0$proxy$ZaakService_PS
As can be seen in the MBean Browser, the metadata for a particular proxy service shows the dependencies on other resources (like business services and XML Schemas) and other services that are dependent on the proxy service.
[Via MBean Browser]
By looking at the results in the text file "OSBServiceExplorer.txt", the dependencies between services (proxy and business) and also the dependencies with certain external web services (with a particular endpoint) could be extracted.
Example content of the text file:
Found server runtimes: - Server name: AdminServer. Server state: RUNNING - Server name: ManagedServer1. Server state: RUNNING - Server name: ManagedServer2. Server state: RUNNING Found total of 1132 refs, including the following proxy and business services: … - ProxyService: JMSConsumerStuFZKNMessageService-1.0/proxy/JMSConsumerStuFZKNMessageService_PS … - ProxyService: ZKN ZaakService-2.0/proxy/UpdateZaak_Lk01_PS … - BusinessService: ZKN ZaakService-2.0/business/eBUS/eBUS_FolderService_BS … ResourceConfiguration list of proxy and business services: … - Resource: com.oracle.osb:Location=AdminServer,Name=ProxyService$ZKN ZaakService-2.0$proxy$UpdateZaak_Lk01_PS,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=AdminServer,Name=ProxyService$ZKN ZaakService-2.0$proxy$UpdateZaak_Lk01_PS,Type=ResourceConfigurationMBean: service-type=Abstract SOAP, transport-type=local, url=local Index#72: level = 1 label = wsCallout name = _ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7b7f node-id = 71 type = Action children = [66,70] Index#98: level = 1 label = wsCallout name = _ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7997 node-id = 54 type = Action children = [48,53] Index#106: level = 1 label = wsCallout name = _ActionId-7997641858449402984--36d1ada1.1562c8caabd.-7cf4 node-id = 35 type = Action children = [30,34] Metadata of com.oracle.osb:Location=AdminServer,Name=ProxyService$ZKN ZaakService-2.0$proxy$UpdateZaak_Lk01_PS,Type=ResourceConfigurationMBean dependencies: - BusinessService$ZKN ZaakService-2.0$business$eBUS$eBUS_FolderService_BS - XMLSchema$CDM$Interface$StUF-ZKN_1_1_02$zkn0310$mutatie$zkn0310_msg_mutatie - BusinessService$ZKN ZaakService-2.0$business$eBUS$eBUS_SearchService_BS - BusinessService$ZKN ZaakService-2.0$business$eBUS$eBUS_LookupService_BS dependents: - ProxyService$JMSConsumerStuFZKNMessageService-1.0$proxy$JMSConsumerStuFZKNMessageService_PS - ProxyService$ZKN ZaakService-2.0$proxy$ZaakService_PS …
The java code:
package nl.xyz.osbservice.osbserviceexplorer; import com.bea.wli.config.Ref; import com.bea.wli.sb.management.configuration.ALSBConfigurationMBean; import java.io.FileWriter; import java.io.IOException; import java.net.MalformedURLException; import java.util.Collection; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Properties; import java.util.Set; import javax.management.MBeanServerConnection; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeType; import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularType; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; import weblogic.management.jmx.MBeanServerInvocationHandler; import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean; import weblogic.management.runtime.ServerRuntimeMBean; public class OSBServiceExplorer { private static MBeanServerConnection connection; private static JMXConnector connector; private static FileWriter fileWriter; /** * Indent a string * @param indent - The number of indentations to add before a string * @return String - The indented string */ private static String getIndentString(int indent) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < indent; i++) { sb.append(" "); } return sb.toString(); } /** * Print composite data (write to file) * @param nodes - The list of nodes * @param key - The list of keys * @param level - The level in the hierarchy of nodes */ private void printCompositeData(TabularDataSupport nodes, Object[] key, int level) { try { CompositeData compositeData = nodes.get(key); fileWriter.write(getIndentString(level) + " level = " + level + "\n"); String label = (String)compositeData.get("label"); String name = (String)compositeData.get("name"); String nodeid = (String)compositeData.get("node-id"); String type = (String)compositeData.get("type"); String[] childeren = (String[])compositeData.get("children"); if (level == 1 || (label.contains("route-node") || label.contains("route"))) { fileWriter.write(getIndentString(level) + " label = " + label + "\n"); fileWriter.write(getIndentString(level) + " name = " + name + "\n"); fileWriter.write(getIndentString(level) + " node-id = " + nodeid + "\n"); fileWriter.write(getIndentString(level) + " type = " + type + "\n"); fileWriter.write(getIndentString(level) + " children = ["); int size = childeren.length; for (int i = 0; i < size; i++) { fileWriter.write(childeren[i]); if (i < size - 1) { fileWriter.write(","); } } fileWriter.write("]\n"); } else if (level >= 2) { fileWriter.write(getIndentString(level) + " node-id = " + nodeid + "\n"); fileWriter.write(getIndentString(level) + " children = ["); int size = childeren.length; for (int i = 0; i < size; i++) { fileWriter.write(childeren[i]); if (i < size - 1) { fileWriter.write(","); } } fileWriter.write("]\n"); } if ((level == 1 && type.equals("OperationalBranchNode")) || level > 1) { level++; int size = childeren.length; for (int i = 0; i < size; i++) { key[0] = childeren[i]; printCompositeData(nodes, key, level); } } } catch (Exception ex) { ex.printStackTrace(); } } public OSBServiceExplorer(HashMap props) { super(); try { Properties properties = new Properties(); properties.putAll(props); initConnection(properties.getProperty("HOSTNAME"), properties.getProperty("PORT"), properties.getProperty("USERNAME"), properties.getProperty("PASSWORD")); DomainRuntimeServiceMBean domainRuntimeServiceMBean = (DomainRuntimeServiceMBean)findDomainRuntimeServiceMBean(connection); ServerRuntimeMBean[] serverRuntimes = domainRuntimeServiceMBean.getServerRuntimes(); fileWriter = new FileWriter("OSBServiceExplorer.txt", false); fileWriter.write("Found server runtimes:\n"); int length = (int)serverRuntimes.length; for (int i = 0; i < length; i++) { ServerRuntimeMBean serverRuntimeMBean = serverRuntimes[i]; String name = serverRuntimeMBean.getName(); String state = serverRuntimeMBean.getState(); fileWriter.write("- Server name: " + name + ". Server state: " + state + "\n"); } fileWriter.write("" + "\n"); // Create an mbean instance to perform configuration operations in the created session. // // There is a separate instance of ALSBConfigurationMBean for each session. // There is also one more ALSBConfigurationMBean instance which works on the core data, i.e., the data which ALSB runtime uses. // An ALSBConfigurationMBean instance is created whenever a new session is created via the SessionManagementMBean.createSession(String) API. // This mbean instance is then used to perform configuration operations in that session. // The mbean instance is destroyed when the corresponding session is activated or discarded. ALSBConfigurationMBean alsbConfigurationMBean = (ALSBConfigurationMBean)domainRuntimeServiceMBean.findService(ALSBConfigurationMBean.NAME, ALSBConfigurationMBean.TYPE, null); Set<Ref> refs = alsbConfigurationMBean.getRefs(Ref.DOMAIN); fileWriter.write("Found total of " + refs.size() + " refs, including the following proxy and business services:\n"); for (Ref ref : refs) { String typeId = ref.getTypeId(); if (typeId.equalsIgnoreCase("ProxyService")) { fileWriter.write("- ProxyService: " + ref.getFullName() + "\n"); } else if (typeId.equalsIgnoreCase("BusinessService")) { fileWriter.write("- BusinessService: " + ref.getFullName() + "\n"); } else { //fileWriter.write(ref.getFullName()); } } fileWriter.write("" + "\n"); String domain = "com.oracle.osb"; String objectNamePattern = domain + ":" + "Type=ResourceConfigurationMBean,*"; Set<ObjectName> osbResourceConfigurations = connection.queryNames(new ObjectName(objectNamePattern), null); fileWriter.write("ResourceConfiguration list of proxy and business services:\n"); for (ObjectName osbResourceConfiguration : osbResourceConfigurations) { CompositeDataSupport configuration = (CompositeDataSupport)connection.getAttribute(osbResourceConfiguration, "Configuration"); CompositeDataSupport metadata = (CompositeDataSupport)connection.getAttribute(osbResourceConfiguration, "Metadata"); String canonicalName = osbResourceConfiguration.getCanonicalName(); fileWriter.write("- Resource: " + canonicalName + "\n"); if (canonicalName.contains("ProxyService")) { String servicetype = (String)configuration.get("service-type"); CompositeDataSupport transportconfiguration = (CompositeDataSupport)configuration.get("transport-configuration"); String transporttype = (String)transportconfiguration.get("transport-type"); String url = (String)transportconfiguration.get("url"); fileWriter.write(" Configuration of " + canonicalName + ":" + " service-type=" + servicetype + ", transport-type=" + transporttype + ", url=" + url + "\n"); } else if (canonicalName.contains("BusinessService")) { String servicetype = (String)configuration.get("service-type"); CompositeDataSupport transportconfiguration = (CompositeDataSupport)configuration.get("transport-configuration"); String transporttype = (String)transportconfiguration.get("transport-type"); CompositeData[] urlconfiguration = (CompositeData[])transportconfiguration.get("url-configuration"); String url = (String)urlconfiguration[0].get("url"); fileWriter.write(" Configuration of " + canonicalName + ":" + " service-type=" + servicetype + ", transport-type=" + transporttype + ", url=" + url + "\n"); } if (canonicalName.contains("ProxyService")) { fileWriter.write("" + "\n"); CompositeDataSupport pipeline = (CompositeDataSupport)configuration.get("pipeline"); TabularDataSupport nodes = (TabularDataSupport)pipeline.get("nodes"); TabularType tabularType = nodes.getTabularType(); CompositeType rowType = tabularType.getRowType(); Iterator keyIter = nodes.keySet().iterator(); for (int j = 0; keyIter.hasNext(); ++j) { Object[] key = ((Collection)keyIter.next()).toArray(); CompositeData compositeData = nodes.get(key); String label = (String)compositeData.get("label"); String type = (String)compositeData.get("type"); if (type.equals("Action") && (label.contains("wsCallout") || label.contains("javaCallout") || label.contains("route"))) { fileWriter.write(" Index#" + j + ":\n"); printCompositeData(nodes, key, 1); } else if (type.equals("OperationalBranchNode") || type.equals("RouteNode")) { fileWriter.write(" Index#" + j + ":\n"); printCompositeData(nodes, key, 1); } } fileWriter.write("" + "\n"); fileWriter.write(" Metadata of " + canonicalName + "\n"); String[] dependencies = (String[])metadata.get("dependencies"); fileWriter.write(" dependencies:\n"); int size; size = dependencies.length; for (int i = 0; i < size; i++) { String dependency = dependencies[i]; if (!dependency.contains("Xquery")) { fileWriter.write(" - " + dependency + "\n"); } } fileWriter.write("" + "\n"); String[] dependents = (String[])metadata.get("dependents"); fileWriter.write(" dependents:\n"); size = dependents.length; for (int i = 0; i < size; i++) { String dependent = dependents[i]; fileWriter.write(" - " + dependent + "\n"); } fileWriter.write("" + "\n"); } } fileWriter.close(); System.out.println("Succesfully completed"); } catch (Exception ex) { ex.printStackTrace(); } finally { if (connector != null) try { connector.close(); } catch (Exception e) { e.printStackTrace(); } } } /* * Initialize connection to the Domain Runtime MBean Server. */ 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 mbeanserver = DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mbeanserver); Hashtable hashtable = new Hashtable(); hashtable.put(Context.SECURITY_PRINCIPAL, username); hashtable.put(Context.SECURITY_CREDENTIALS, password); hashtable.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); hashtable.put("jmx.remote.x.request.waiting.timeout", new Long(10000)); connector = JMXConnectorFactory.connect(serviceURL, hashtable); connection = connector.getMBeanServerConnection(); } private static Ref constructRef(String refType, String serviceURI) { Ref ref = null; String[] uriData = serviceURI.split("/"); ref = new Ref(refType, uriData); return ref; } /** * Finds the specified MBean object * * @param connection - A connection to the MBeanServer. * @return Object - The MBean or null if the MBean was not found. */ public Object findDomainRuntimeServiceMBean(MBeanServerConnection connection) { try { ObjectName objectName = new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME); return (DomainRuntimeServiceMBean)MBeanServerInvocationHandler.newProxyInstance(connection, objectName); } catch (MalformedObjectNameException e) { e.printStackTrace(); return null; } } public static void main(String[] args) { try { if (args.length <= 0) { System.out.println("Provide values for the following parameters: HOSTNAME, PORT, USERNAME, PASSWORD."); } else { HashMap<String, String> map = new HashMap<String, String>(); map.put("HOSTNAME", args[0]); map.put("PORT", args[1]); map.put("USERNAME", args[2]); map.put("PASSWORD", args[3]); OSBServiceExplorer osbServiceExplorer = new OSBServiceExplorer(map); } } catch (Exception e) { e.printStackTrace(); } } }
Hi Marc,
I have a scenario for OSB, where I need to recover by wlst, correspond to the OSB session history list when you click on “View Changes” on the top left of sbconsole.
It would be possible to help me.
I have some doubts this information is recorded where in OSB(Domain) or DB?
[Oracle Service Bus 11.1 Wed Apr 20 04:25:20 EDT 2011 1400736]
[WebLogic Server 10.3.5.0.7 PSU Patch for BUG16088411 Mon Apr 01 15:13:52 IST 2013]
Tks,
Márcio Zampiron
Hello Mark,
When I try to run the above code in 12c, I see nullpointerexception and the txt file is generated but seems to be empty. I have already added the dependent 12c jars in the project classpath.
Hello Anusha,
There are indeed changes between version 11.1.1.7 (the version I used when I wrote the article) and for example version 12.2.1.
In 12c besides Proxy Service and Business Service types, there is of course now also a Pipeline type.
You could add for example:
else if (typeId.equalsIgnoreCase(“Pipeline”)) {
fileWriter.write(“- Pipeline: ” +
ref.getFullName() + “\n”);
}
in the Java code example and remark part of the code in order to get it working and having some content in the txt file.
Add /* */ around part of code, for example:
/*fileWriter.write(“ResourceConfiguration list of proxy and business services:\n”);
for (ObjectName osbResourceConfiguration :
…
}*/
fileWriter.close();
System.out.println(“Succesfully completed”);
—–
Be aware that for example the code below does not work anymore in 12c;
CompositeDataSupport pipeline =
(CompositeDataSupport)configuration.get(“pipeline”);
Also for a Pipeline type, the “Configuration” attribute is Unavailable !
CompositeDataSupport configuration =
(CompositeDataSupport)connection.getAttribute(osbResourceConfiguration,
“Configuration”);
I hope my comment will help you. There will be soon a new article about OSB, Mbeans and JMX with regard to the 12.2.1 version.
With kind regards,
Marc
Very good MARC! Exactly what I was looking for to extract data from OSB!
Thank you very much!
Hi Marc,
You mentioned:
So because of the use of com.bea.wli.sb.management.configuration.DelegatedALSBConfigurationMBean.class the following library /Oracle_OSB1/lib/sb-kernel-impl.jar was also needed.
I am trying to find this jar in the 12.1.3 installation but it seems it is not there. Do you know where they moved it or in which jar the DelegatedALSBConfigurationMBean class is now? Perhaps created by a jarbuilder?
Thanks in advance!
Hugo
You can find the equivalent jar in 12c – OracleMiddlewareOracle_Homeosblibmodulesoracle.servicebus.kernel-wls.jar
Hello Marc,
Very interesting your post, I appreciated it so much because I’ve needed to do something like this. In my case, the company wanted to know what databases were referenced by each proxy service in order to stop only the proxy services associated with those databases (for database maintenance purpose).
It becomes a challenge because they had two osb domains and they needed to discover the references between those domains (MQ->BS, BS->PS, PS->PS, BS->MQ) and it was a weak reference (only a HTTP simple call through BS) to another PS in the another domain, maybe through JMX technique as demonstrated in this post we won’t be able to detect those references. I wrote an alghorithm that uses Python / Jython and WLST to download the whole source code through export feature and then I built a code that analyses manually the dependencies between the source code considering multiple domains references.
When I was trying to solve this problem I was asking myself if anyone in the world was facing the same problem and your post was a surprise to me, because I dreamed about an Explorer Osb Tool that surely would be very useful for whatever company using OSB Suite.
Thank you for sharing your knowledge with us.
Victor Jabur
Your welcome