In a previous article I talked about an OSBServiceExplorer tool to explore the services (proxy and business) within the OSB via WebLogic Server MBeans with JMX. The code mentioned in that article was based on Oracle Service Bus 11.1.1.7 (11g).
In the meantime the OSB world has changed (for example now we can use pipelines) and it was time for me to pick up the old code and get it working within Oracle Service Bus 12.2.1.1.0 (12c).
This article will explain how the OSBServiceExplorer tool uses WebLogic Server MBeans with JMX in an 12c environment.
Unfortunately, getting the java code to work in 12c wasn’t as straightforward as I hoped.
For more details on the OSB, WebLogic Server MBeans and JMX subject, I kindly refer you to my previous article. In this article I will refer to it as my previous MBeans 11g article.
[https://technology.amis.nl/2017/03/09/oracle-service-bus-service-exploring-via-weblogic-server-mbeans-with-jmx/]
Before using the OSBServiceExplorer tool in an 12c environment, I first created two OSB Projects (MusicService and TrackService) with pipelines, proxy and business services. I used Oracle JDeveloper 12c (12.2.1.1.0) for this (from within a VirtualBox appliance).
For the latest version of Oracle Service Bus see:
http://www.oracle.com/technetwork/middleware/service-bus/downloads/index.html
If you want to use a VirtualBox appliance, have a look at for example: Pre-built Virtual Machine for SOA Suite 12.2.1.3.0
[http://www.oracle.com/technetwork/middleware/soasuite/learnmore/vmsoa122130-4122735.html]
After deploying the OSB Projects that were created in JDeveloper, to the WebLogic server, the Oracle Service Bus Console 12c (in my case: http://localhost:7101/servicebus) looks like:
Before we dive into the OSBServiceExplorer tool , first I give you some detail information of the “TrackService” (from JDeveloper), that will be used as an example in this article.
The “TrackService” sboverview looks like:
As you can see, several proxy services, a pipeline and a business service are present.
The Message Flow of pipeline “TrackServicePipeline” looks like:
The OSB Project structure of service “TrackService” looks like:
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: DefaultServer. Server state: RUNNING
For more info and the responsible code fragment see my previous MBeans 11g article.
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:
See the code fragment below (I highlighted the changes I made on the code from the 11g version):
Set<Ref> refs = alsbConfigurationMBean.getRefs(Ref.DOMAIN); fileWriter.write("Found total of " + refs.size() + " refs, including the following pipelines, 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("Pipeline")) { fileWriter.write("- Pipeline: " + ref.getFullName() + "\n"); } else if (typeId.equalsIgnoreCase("BusinessService")) { fileWriter.write("- BusinessService: " + ref.getFullName() + "\n"); } else { //fileWriter.write(ref.getFullName()); } } fileWriter.write("" + "\n");
For more info see my previous MBeans 11g article.
ResourceConfigurationMBean
In the Oracle Enterprise Manager FMC 12c (in my case: http://localhost:7101/em) I navigated to SOA / service-bus and opened the System MBean Browser:
Here the ResourceConfigurationMBean’s can be found under com.oracle.osb.
[Via MBean Browser]
If we navigate to a particular ResourceConfigurationMBean for a proxy service (for example …$proxy$TrackService), the information on the right is as follows :
[Via MBean Browser]
As in the 11g version the attributes Configuration, Metadata and Name are available.
If we navigate to a particular ResourceConfigurationMBean for a pipeline (for example …$pipeline$TrackServicePipeline), the information on the right is as follows :
[Via MBean Browser]
As you can see the value for attribute “Configuration” for this pipeline is “Unavailable”.
Remember the following java code in OSBServiceExplorer.java (see my previous MBeans 11g article):
for (ObjectName osbResourceConfiguration : osbResourceConfigurations) { CompositeDataSupport configuration = (CompositeDataSupport)connection.getAttribute(osbResourceConfiguration, "Configuration");
So now apparently, getting the configuration can result in a NullPointerException. This has to be dealt with in the new 12c version of OSBServiceExplorer.java, besides the fact that now also a pipeline is a new resource type.
But of course for our OSB service explorer we are in particular, interested in the elements (nodes) of the pipeline. In order to get this information available in the System MBean Browser, something has to be done.
Via the Oracle Enterprise Manager FMC 12c I navigated to SOA / service-bus / Home / Projects / TrackService and clicked on tab “Operations”:
Here you can see the Operations settings of this particular service.
Next I clicked on the pipeline “TrackServicePipeline”, where I enabled “Monitoring”
If we then navigate back to the ResourceConfigurationMBean for pipeline “TrackServicePipeline”, the information on the right is as follows:
[Via MBean Browser]
So now the wanted configuration information is available.
Remark:
For the pipeline “MusicServicePipeline” the monitoring is still disabled, so the configuration is still unavailabe.
Diving into attribute Configuration of the ResourceConfigurationMBean
For each found pipeline, proxy and business service the configuration information (canonicalName, service-type, transport-type, url) is written to file.
Proxy service configuration:
Please see my previous MBeans 11g article.
Business service configuration:
Please see my previous MBeans 11g article.
Pipeline configuration:
Below is an example of a pipeline configuration (content fragment of the text file):
If the pipeline configuration is unavailable, the following is shown:
Resource is a Pipeline (without available Configuration)
The pipelines can be recognized by the Pipeline$ prefix.
Pipeline, element hierarchy
In the 11g version of OSBServiceExplorer.java, for a proxy service the elements (nodes) of the pipeline were investigated.
See the code fragment below:
CompositeDataSupport pipeline = (CompositeDataSupport)configuration.get("pipeline"); TabularDataSupport nodes = (TabularDataSupport)pipeline.get("nodes");
In 12c however this doesn’t work for a proxy service. The same code can be used however for a pipeline.
For pipeline “TrackServicePipeline”, the configuration (including nodes) looks like:
[Via MBean Browser]
Based on the nodes information (with node-id) in the MBean Browser and the content of pipeline “TrackServicePipeline.pipeline” the following structure can be put together:
The mapping between the node-id and the corresponding element in the Messsage Flow can be achieved by looking in the .pipeline file for the _ActiondId- identification, mentioned as value for the name key.
Example of the details of node with node-id = 4 and name = _ActionId-7f000001.N38d9a220.0.163b507de28.N7ffc:
[Via MBean Browser]
Content of pipeline “TrackServicePipeline.pipeline”:
<?xml version="1.0" encoding="UTF-8"?> <con:pipelineEntry xmlns:con="http://www.bea.com/wli/sb/pipeline/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:con1="http://www.bea.com/wli/sb/stages/config" xmlns:con2="http://www.bea.com/wli/sb/stages/routing/config" xmlns:con3="http://www.bea.com/wli/sb/stages/transform/config"> <con:coreEntry> <con:binding type="SOAP" isSoap12="false" xsi:type="con:SoapBindingType"> <con:wsdl ref="TrackService/proxy/TrackService"/> <con:binding> <con:name>TrackServiceBinding</con:name> <con:namespace>http://trackservice.services.soatraining.amis/</con:namespace> </con:binding> </con:binding> <con:xqConfiguration> <con:snippetVersion>1.0</con:snippetVersion> </con:xqConfiguration> </con:coreEntry> <con:router> <con:flow> <con:route-node name="RouteNode1"> <con:context> <con1:userNsDecl prefix="trac" namespace="http://trackservice.services.soatraining.amis/"/> </con:context> <con:actions> <con2:route> <con1:id>_ActionId-7f000001.N38d9a220.0.163b507de28.N7ffc</con1:id> <con2:service ref="TrackService/business/CDService" xsi:type="ref:BusinessServiceRef" xmlns:ref="http://www.bea.com/wli/sb/reference"/> <con2:operation>getTracksForCD</con2:operation> <con2:outboundTransform> <con3:replace varName="body" contents-only="true"> <con1:id>_ActionId-7f000001.N38d9a220.0.163b507de28.N7ff9</con1:id> <con3:location> <con1:xpathText>.</con1:xpathText> </con3:location> <con3:expr> <con1:xqueryTransform> <con1:resource ref="TrackService/Resources/xquery/CDService_getTracksForCDRequest"/> <con1:param name="getTracksForCDRequest"> <con1:path>$body/trac:getTracksForCDRequest</con1:path> </con1:param> </con1:xqueryTransform> </con3:expr> </con3:replace> </con2:outboundTransform> <con2:responseTransform> <con3:replace varName="body" contents-only="true"> <con1:id>_ActionId-7f000001.N38d9a220.0.163b507de28.N7ff6</con1:id> <con3:location> <con1:xpathText>.</con1:xpathText> </con3:location> <con3:expr> <con1:xqueryTransform> <con1:resource ref="TrackService/Resources/xquery/CDService_getTracksForCDResponse"/> <con1:param name="getTracksForCDResponse"> <con1:path>$body/*[1]</con1:path> </con1:param> </con1:xqueryTransform> </con3:expr> </con3:replace> </con2:responseTransform> </con2:route> </con:actions> </con:route-node> </con:flow> </con:router> </con:pipelineEntry>
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. Because of the interest in only certain kind of nodes (Route, Java Callout, Service Callout, etc.) some kind of filtering is needed. For more info about this, see my previous MBeans 11g article.
Diving into attribute Metadata of the ResourceConfigurationMBean
For each found pipeline the metadata information (dependencies and dependents) is written to file.
Example content fragment of the text file:
dependents:
– ProxyService$TrackService$proxy$TrackService
– ProxyService$TrackService$proxy$TrackServiceRest
– ProxyService$TrackService$proxy$TrackServiceRestJSON
As can be seen in the MBean Browser, the metadata for a particular pipeline shows the dependencies on other resources (like business services and WSDLs) and other services that are dependent on the pipeline.
For more info and the responsible code fragment see my previous MBeans 11g article.
Remark:
In the java code, dependencies on Xquery’s are filtered out and not written to the text file.
MBeans with regard to version 11.1.1.7
In the sample java code shown at the end of my previous MBeans 11g article, the use of the following MBeans can be seen:
Therefor in JDeveloper 11g, the following Project Libraries and Classpath settings were made:
For more info about these MBeans, see my previous MBeans 11g article.
In order to connect to a WebLogic MBean Server in my previous MBeans 11g article I used the thick client wlfullclient.jar.
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.
So I build wlfullclient.jar as follow:
cd <Middleware Home Directory>/wlserver_10.3/server/lib
java -jar wljarbuilder.jar
In the sample java code shown at the end of this article, the use of the same MBeans can be seen. However in JDeveloper 12c, changes in Project Libraries and Classpath settings were necessary, due to changes in the jar files used in the 12c environment. Also the wlfullclient.jar is deprecated as of WebLogic Server 12.1.3 !
Overview of WebLogic Client jar files
WebLogic Client | Jar file | Protocol |
WebLogic Full Client | weblogic.jar (6 KB) (Via the manifest file MANIFEST.MF, classes in other JAR files are referenced) |
T3 |
wlfullclient.jar (111.131 KB) is deprecated as of WebLogic Server 12.1.3 |
T3 | |
WebLogic Thin Client | wlclient.jar (2.128 KB) | IIOP |
wljmxclient.jar (238 KB) | IIOP | |
WebLogic Thin T3 Client | wlthint3client.jar (7.287 KB) | T3 |
Remark with regard to version 12.2.1:
Due to changes in the JDK, WLS no longer supports JMX with just the wlclient.jar. To use JMX, you must use either the ”full client” (weblogic.jar) or wljmxclient.jar.
[https://docs.oracle.com/middleware/1221/wls/JMXCU/accesswls.htm#JMXCU144]
WebLogic Full Client
The WebLogic full client, wlfullclient.jar, is deprecated as of WebLogic Server 12.1.3 and may be removed in a future release. Oracle recommends using the WebLogic Thin T3 client or other appropriate client depending on your environment.
[https://docs.oracle.com/middleware/1213/wls/SACLT/t3.htm#SACLT130]
For WebLogic Server 10.0 and later releases, client applications need to use the wlfullclient.jar file instead of the weblogic.jar. A WebLogic full client is a Java RMI client that uses Oracle’s proprietary T3 protocol to communicate with WebLogic Server, thereby leveraging the Java-to-Java model of distributed computing.
[https://docs.oracle.com/middleware/1213/wls/SACLT/t3.htm#SACLT376]
Not all functionality available with weblogic.jar is available with the wlfullclient.jar. For example, wlfullclient.jar does not support Web Services, which requires the wseeclient.jar. Nor does wlfullclient.jar support operations necessary for development purposes, such as ejbc, or support administrative operations, such as deployment, which still require using the weblogic.jar.
[https://docs.oracle.com/middleware/1213/wls/SACLT/t3.htm#SACLT376]
WebLogic Thin Client
In order to connect to a WebLogic MBean Server, it is also possible to use a thin client wljmxclient.jar (in combination with wlclient.jar). This JAR contains Oracle’s implementation of the HTTP and IIOP protocols.
Remark:
wlclient.jar is included in wljmxclient.jar‘s MANIFEST ClassPath entry, so wlclient.jar and wljmxclient.jar need to be in the same directory, or both jars need to be specified on the classpath.
Ensure that weblogic.jar or wlfullclient.jar is not included in the classpath if wljmxclient.jar is included. Only the thin client wljmxclient.jar/wlclient.jar or the thick client wlfullclient.jar should be used, but not a combination of both. [https://docs.oracle.com/middleware/1221/wls/JMXCU/accesswls.htm#JMXCU144]
WebLogic Thin T3 Client
The WebLogic Thin T3 Client jar (wlthint3client.jar) is a light-weight, high performing alternative to the wlfullclient.jar and wlclient.jar (IIOP) remote client jars. The Thin T3 client has a minimal footprint while providing access to a rich set of APIs that are appropriate for client usage. As its name implies, the Thin T3 Client uses the WebLogic T3 protocol, which provides significant performance improvements over the wlclient.jar, which uses the IIOP protocol.
The Thin T3 Client is the recommended option for most remote client use cases. There are some limitations in the Thin t3 client as outlined below. For those few use cases, you may need to use the full client or the IIOP thin client.
Limitations and Considerations:
This release does not support the following:
- Mbean-based utilities (such as JMS Helper, JMS Module Helper), and JMS multicast are not supported. You can use JMX calls as an alternative to “mbean-based helpers.”
- JDBC resources, including WebLogic JDBC extensions.
- Running a WebLogic RMI server in the client.
The Thin T3 client uses JDK classes to connect to the host, including when connecting to dual-stacked machines. If multiple addresses available on the host, the connection may attempt to go to the wrong address and fail if the host is not properly configured.
[https://docs.oracle.com/middleware/12212/wls/SACLT/wlthint3client.htm#SACLT387]
MBeans with regard to version 12.2.1
As I mentioned earlier in this article, in order to get the Java code working in a 12.2.1 environment, I had to make some changes.
In JDeveloper 12c, the following Project Libraries and Classpath settings were made (at first):
Using wlfullclient.jar:
At first I still used the thick client wlfullclient.jar (despite the fact that it’s deprecated), which I build as follow:
wlfullclient.jar and jarbuilder are deprecated starting from the WebLogic 12.1.3 release.
Please use one of the equivalent stand-alone clients instead. Consult Oracle WebLogic public documents for details.
Compiling and running the OSBServiceExplorer tool in JDeveloper worked.
Using weblogic.jar:
When I changed wlfullclient.jar in to weblogic.jar the OSBServiceExplorer tool also worked.
Using wlclient.jar:
When I changed wlfullclient.jar in to wlclient.jar the OSBServiceExplorer tool did not work, because of errors on:
Using wlclient.jar and wljmxclient.jar:
Also adding wljmxclient.jar did not work, because of errors on:
Adding wls-api.jar:
So in order to try resolving the errors shown above, I also added wls-api.jar. But then I got an error on:
String name = serverRuntimeMBean.getName();
I then decided to go for the, by Oracle recommended, WebLogic Thin T3 client wlthint3client.jar.
Using wlthint3client.jar:
When I changed wlfullclient.jar in to wlthint3client.jar the OSBServiceExplorer tool did not work, because of errors on:
Using wlthint3client.jar and wls-api.jar:
So in order to try resolving the errors shown above, I also added wls-api.jar. But then again I got an error on:
String name = serverRuntimeMBean.getName();
However I could run the OSBServiceExplorer tool in JDeveloper , but then I got the error:
I found that the following jar files could solve this error:
- <Middleware Home Directory>/wlserver/modules/clients/com.oracle.webservices.wls.jaxws-wlswss-client.jar (58.115 KB)
- <Middleware Home Directory>/wlserver/modules/com.oracle.weblogic.security.jar (399 KB)
For the time being I extracted the needed class file (weblogic.security.ServerRuntimeSecurityAccess.class) from the smallest size jar file to a lib directory on the filesystem and in JDeveloper added that lib directory as a Classpath to the Project.
As it turned out I had to repeat these steps for the following errors I still got after I extended the Classpath:
- <Middleware Home Directory>/wlserver/modules/clients/com.oracle.webservices.wls.jaxrpc-client.jar (49.750 KB)
- <Middleware Home Directory>/wlserver/modules/clients/com.oracle.webservices.wls.jaxws-wlswss-client.jar (58.115 KB)
- <Middleware Home Directory>/wlserver/modules/clients/com.oracle.webservices.wls.jaxws-wlswss-client.jar (58.115 KB)
- <Middleware Home Directory>/wlserver/modules/com.oracle.weblogic.management.base.jar (816 KB)
After that, compiling and running the OSBServiceExplorer tool in JDeveloper worked.
Using the lib directory with the extracted class files, was not what I wanted. Adding the jar files mentioned above seemed a better idea. So I picked the jar files with the smallest size, to get the job done, and discarded the lib directory.
So in the end, in JDeveloper 12c, the following Project Libraries and Classpath settings were made:
Shell script
For ease of use, a shell script file was created, using MBeans, to explore pipeline, proxy and business services. The WebLogic Server contains a set of MBeans that can be used to configure, monitor and manage WebLogic Server resources.
The content of the shell script file “OSBServiceExplorer” is:
# Script to call OSBServiceExplorer
echo “Start calling OSBServiceExplorer”
java -classpath “OSBServiceExplorer.jar:oracle.servicebus.configfwk.jar:com.bea.core.management.jmx.jar:oracle.servicebus.kernel-api.jar:oracle.servicebus.kernel-wls.jar:wlthint3client.jar:wls-api.jar:com.oracle.weblogic.security.jar:com.oracle.webservices.wls.jaxrpc-client.jar:com.oracle.weblogic.management.base.jar” nl.xyz.osbservice.osbserviceexplorer.OSBServiceExplorer “xyz” “7001” “weblogic” “xyz”
echo “End calling OSBServiceExplorer”
In the shell script file via the java executable, 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 |
Example content of the text file:
Found server runtimes: - Server name: DefaultServer. Server state: RUNNING Found total of 45 refs, including the following pipelines, proxy and business services: - ProxyService: TrackService/proxy/TrackServiceRest - BusinessService: MusicService/business/db_InsertCD - BusinessService: TrackService/business/CDService - Pipeline: TrackService/pipeline/TrackServicePipeline - ProxyService: TrackService/proxy/TrackService - Pipeline: MusicService/pipeline/MusicServicePipeline - ProxyService: MusicService/proxy/MusicService - ProxyService: TrackService/proxy/TrackServiceRestJSON ResourceConfiguration list of pipelines, proxy and business services: - Resource: com.oracle.osb:Location=DefaultServer,Name=ProxyService$MusicService$proxy$MusicService,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=DefaultServer,Name=ProxyService$MusicService$proxy$MusicService,Type=ResourceConfigurationMBean: service-type=SOAP, transport-type=http, url=/music/MusicService - Resource: com.oracle.osb:Location=DefaultServer,Name=Pipeline$TrackService$pipeline$TrackServicePipeline,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=DefaultServer,Name=Pipeline$TrackService$pipeline$TrackServicePipeline,Type=ResourceConfigurationMBean: service-type=SOAP Index#4: level = 1 label = route name = _ActionId-7f000001.N38d9a220.0.163b507de28.N7ffc node-id = 4 type = Action children = [1,3] Index#6: level = 1 label = route-node name = RouteNode1 node-id = 6 type = RouteNode children = [5] Metadata of com.oracle.osb:Location=DefaultServer,Name=Pipeline$TrackService$pipeline$TrackServicePipeline,Type=ResourceConfigurationMBean dependencies: - BusinessService$TrackService$business$CDService - WSDL$TrackService$proxy$TrackService dependents: - ProxyService$TrackService$proxy$TrackService - ProxyService$TrackService$proxy$TrackServiceRest - ProxyService$TrackService$proxy$TrackServiceRestJSON - Resource: com.oracle.osb:Location=DefaultServer,Name=Operations$System$Operator Settings$GlobalOperationalSettings,Type=ResourceConfigurationMBean - Resource: com.oracle.osb:Location=DefaultServer,Name=Pipeline$MusicService$pipeline$MusicServicePipeline,Type=ResourceConfigurationMBean Resource is a Pipeline (without available Configuration) - Resource: com.oracle.osb:Location=DefaultServer,Name=BusinessService$MusicService$business$db_InsertCD,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=DefaultServer,Name=BusinessService$MusicService$business$db_InsertCD,Type=ResourceConfigurationMBean: service-type=SOAP, transport-type=jca, url=jca://eis/DB/MUSIC - Resource: com.oracle.osb:Location=DefaultServer,Name=BusinessService$TrackService$business$CDService,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=DefaultServer,Name=BusinessService$TrackService$business$CDService,Type=ResourceConfigurationMBean: service-type=SOAP, transport-type=http, url=http://127.0.0.1:7101/cd_services/CDService - Resource: com.oracle.osb:Location=DefaultServer,Name=ProxyService$TrackService$proxy$TrackServiceRest,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=DefaultServer,Name=ProxyService$TrackService$proxy$TrackServiceRest,Type=ResourceConfigurationMBean: service-type=REST, transport-type=http, url=/music/TrackServiceRest - Resource: com.oracle.osb:Location=DefaultServer,Name=ProxyService$TrackService$proxy$TrackService,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=DefaultServer,Name=ProxyService$TrackService$proxy$TrackService,Type=ResourceConfigurationMBean: service-type=SOAP, transport-type=http, url=/music/TrackService - Resource: com.oracle.osb:Location=DefaultServer,Name=ProxyService$TrackService$proxy$TrackServiceRestJSON,Type=ResourceConfigurationMBean Configuration of com.oracle.osb:Location=DefaultServer,Name=ProxyService$TrackService$proxy$TrackServiceRestJSON,Type=ResourceConfigurationMBean: service-type=REST, transport-type=http, url=/music/TrackServiceRestJSON
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 pipelines, 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("Pipeline")) { fileWriter.write("- Pipeline: " + 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 pipelines, proxy and business services:\n"); for (ObjectName osbResourceConfiguration : osbResourceConfigurations) { String canonicalName = osbResourceConfiguration.getCanonicalName(); fileWriter.write("- Resource: " + canonicalName + "\n"); try { CompositeDataSupport configuration = (CompositeDataSupport)connection.getAttribute(osbResourceConfiguration, "Configuration"); 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"); } else if (canonicalName.contains("Pipeline")) { String servicetype = (String)configuration.get("service-type"); fileWriter.write(" Configuration of " + canonicalName + ":" + " service-type=" + servicetype + "\n"); } if (canonicalName.contains("Pipeline")) { 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"); CompositeDataSupport metadata = (CompositeDataSupport)connection.getAttribute(osbResourceConfiguration, "Metadata"); 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"); } } catch(Exception e) { if (canonicalName.contains("Pipeline")) { fileWriter.write(" Resource is a Pipeline (without available Configuration)" + "\n"); } else { e.printStackTrace(); } } } 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(); } } }
Hello Marc, great post. I was looking for some information on how to extract services configurations and I came across your previous post (11g) and this one. It helped me to start working on building a tool. It would be great if you find some time to have a look at what I made (It has a GUI, so it won’t take much time).
Thank you.
Hi Marc,
I am trying to disable / enable a proxy service via WebLogic Server(12.2.1.2) MBeans with JMX, however getting below error while connecting to admin server(JMXConnectorFactory.connect)
Pls advise. I have used necessary jars and enabled JMX port at admin server and trying with admin user.
Error: java.io.IOException: Failed to initialize JNDI context, tried 2 time or times totally, the interval of each time is 0ms. Timed out while attempting to establish connection to :t3://:
Thanks
Hi Marc, I tried to connect the server using t3 but getting no router available error, do you have got any idea on how to configure the t3 in wl admin ?
Great job, thanks for descripion of all jars! I spent a lot of time to solve all dependencies in new wls, because my old 11g code does not work.