Thursday, January 25, 2018

Oracle Weblogic - repair URL format in management REST messages

Whenever using the REST management API for Oracle Weblogic and you start to look into the JSON response files provided by Oracle Weblogic you will find that some (all) of the URL's in the JSON response are being constructed in a manner that slashes have been escaped in a generic manner. This is done, most likely, to ensure that nothing breaks when it is called by some other application. However, if you expect clean URL's this is a bit frustrating.

The example below showcases a part of the original JSON message as it it presented by the Weblogic REST API.

[vagrant@docker ~]$ curl -s --user weblogic -H "Accept: application/json" http://192.168.56.50:7001/management/weblogic
Enter host password for user 'weblogic':
{
    "links": [
        {
            "rel": "self",
            "href": "http:\/\/192.168.56.50:7001\/management\/weblogic"
        },
        {
            "rel": "canonical",
            "href": "http:\/\/192.168.56.50:7001\/management\/weblogic"
        },
        {
            "rel": "current",
            "href": "http:\/\/192.168.56.50:7001\/management\/weblogic\/12.2.1.3.0"
        }
    ],
    "items": [


If you are using Oracle Linux and if you are using curl to get the content of the file you can pipe the result into sed to ensure you remove the unwanted slashes from the URL's in the reponse.

For this you pipe the result into the below sed command to get the expected output:

| sed 's|[\,]||g'

This will give you the below clean output as an example:
[vagrant@docker ~]$ curl -s --user weblogic -H "Accept: application/json" http://192.168.56.50:7001/management/weblogic | sed 's|[\,]||g'
Enter host password for user 'weblogic':
{
    "links": [
        {
            "rel": "self"
            "href": "http://192.168.56.50:7001/management/weblogic"
        }
        {
            "rel": "canonical"
            "href": "http://192.168.56.50:7001/management/weblogic"
        }
        {
            "rel": "current"
            "href": "http://192.168.56.50:7001/management/weblogic/12.2.1.3.0"
        }
    ]
    "items": [

As you can see this is a much more clean way of looking at the response and much more easy to understand and handle from a coding point of view.

No comments: