Sunday, July 19, 2015

Overview of WebLogic RESTful Management Services

Inspired by a presentation given by Shukie Ganguly on the free Oracle Virtual Technology Summit in July (see here); "New APIs and Tools for Application Development in WebLogic 12c", I decided to take a look at an interesting new feature in WebLogic Server 12c: the RESTful Management Services. You can see here how to enable them. In this post I will provide an overview of my short study on the topic.

RESTful management services consist of two sets of resources. tenant-monitoring resources and 'wls' resources. The first is more flexible in response format (JSON, XML, HTML) and more suitable for monitoring. With the latter you can for example update datasource properties and create entire servers. It however only supports JSON as return format. The 'wls' resources also provide links so you can automagically traverse the resource tree which is very useful. I've provided a Python script to do just that at the end of this post.


In the past I have already created all kinds of tools to do remote monitoring of WebLogic Server 11g. See for example for some code to monitor datasources and for the state of the SOA Infrastructure; and also for BPEL:

With the 12c RESTful Management Services this becomes a lot easier and does not require any custom code, which is of course a major improvement!

It is possible to let the RESTful Management Services return HTML, JSON or XML by using the Accept HTTP header (application/json or application/xml. HTML is the default). See here.

What can you monitor?
Available resources under http(s)://host:port/management/tenant-monitoring are (WLS 12.1.1):

  • servers
  • clusters
  • applications
  • datasources

You can also go to the level of an individual resource like for example datasources/datasourcename.

SOA Suite
The tenant-monitoring resources of the RESTful Management Services are not specific for SOA Suite. They do not allow you to obtain much information about the inner workings of applications like the SOA infrastructure application or the BPEL process manager. Thus my SOA infrastructure monitoring tool and BPEL process state monitoring tool could still be useful. You can potentially replace this functionality however with for example Jolokia. See below.

Monitoring a lot of resources
Because the Management Services allow monitoring of many resources, they would be ideal to use in a monitoring tool like Nagios. Mark Otting beat me to this however;

The RESTful Management services provide a specific set of resources which you can monitor. These resources are limited. There is also an alternative for the RESTful Management Services for monitoring WebLogic Server (and other application servers), namely Jolokia. See here. One of the nice things about Jolokia is that it allows you to directly access MBeans and you are not limited to a fixed set of available resources. Directly accessing MBeans is very powerful (and potentially dangerous!). This could for example allow obtaining SOA infrastructure state and list deployed composites.


The RESTful Management Services do not only provide monitoring capabilities but also editable resources; These resources can be accessed by going to an URL like; http(s)://host:port/management/wls/{version}/path, for example http://localhost:7001/management/wls/latest/. The resources only provide the option to reply with JSON (Accept: application/json) and provide links entries so you can see the parent and children of a resource. With POST, PUT and DELETE HTTP verbs you can update, create or remove resources and with GET and OPTIONS you can obtain information.

Deploying without dependencies (just curl)
An interesting usecase is command-line deployments without dependencies. This was an example given in the Oracle documentation. (see here). You could use for example a curl command (or whatever command-line HTTP client) to deploy an ear without need for Java libraries or WLST/Ant/Maven scripts.

Walking the resource tree
In contrast to the tenant-monitoring resources, the management resources allow traversing the JSON tree. The response of a HTTP GET request contains a links element, which contains parent and child entries. When an HTTP GET is not allowed or the links element does not exist, you can't go any further down the resource. In order to display available resources on your WebLogic Server I wrote a small Python script.

 import json  
 import httplib  
 import base64  
 import string  
 from urlparse import urlparse  
 WLS_HOST = "localhost"  
 WLS_PORT = "7101"  
 WLS_USERNAME = "weblogic"  
 WLS_PASSWORD = "Welcome01"  
 def do_http_request(host,port,url,verb,accept,username,password,body):  
   # from  
   # base64 encode the username and password  
   auth = string.strip(base64.encodestring(username + ':' + password))  
   service = httplib.HTTP(host,port)  
   # write your headers  
   service.putrequest(verb, url)  
   service.putheader("Host", host)  
   service.putheader("User-Agent", "Python http auth")  
   service.putheader("Content-type", "text/html; charset=\"UTF-8\"")  
   # write the Authorization header like: 'Basic base64encode(username + ':' + password)  
   service.putheader("Authorization", "Basic %s" % auth)  
   # get the response  
   statuscode, statusmessage, header = service.getreply()  
   #print "Headers: ", header  
   res = service.getfile().read()  
   #print 'Content: ', res  
   return statuscode,statusmessage,header,res  
 def do_wls_http_get(url,verb):  
   return do_http_request(WLS_HOST,WLS_PORT,url,verb,"application/json",WLS_USERNAME,WLS_PASSWORD,"")  
 def get_links(body):  
   uris = []  
   json_obj = {}  
   json_obj = json.loads(body)  
   if json_obj.has_key("links"):  
     for link in sorted(json_obj["links"]):  
       if (link["rel"] != "parent"):  
         uri = link["uri"]  
         uriparsed = urlparse(uri)  
   return uris     
 def get_links_recursive(body):  
   links = get_links(body)  
   for link in links:  
     statuscode,statusmessage,header,res = do_wls_http_get(link,"GET")  
     if statuscode==200:  
       print link  
 statuscode,statusmessage,header,res= do_wls_http_get("/management/wls/latest/","GET")  
 if statuscode != 200:  
   print "HTTP statuscode: "+str(statuscode)  
   print "Have you enabled RESTful Management Services?"  

Output of this script on a WebLogic 12.1.3 server contains information on all datasources, application deployments, servers and jobs. You can use it to for example compare two environments for the presence of resources. The script is easily expanded to include the configuration of individual resources. This way you can easily compare environments and see if you have missed a specific configuration setting. Of course, only resources are displayed which can be accessed by the RESTful Management Services. Absence of for example a data-source or application deployment can easily be detected but absence of a credential store or JMS queue will not be detected this way. The links are parsed in order (sorted) to help in comparing. You can also use this script to compare WebLogic Server versions to see what new resources Oracle has added since the last release.