Weblogic REST API (or) Weblogic RESTful services is an innovative approach to manage your weblogic application server. Weblogic REST API could help you do various administration tasks like start, stop, deployment tasks, monitoring, Resource creation like JDBC, Server, Cluster so on and so forth.
Weblogic REST API can be easily enabled from the console followed by an Admin Server Restart. Here is how to do it
Goto your Domain -> Configuration -> General -> Advanced -> Enable RESTful Management Services and restart the Admin Server.
In this post, we are going to see how to perform deployment tasks in weblogic using REST API in weblogic 12.2.1 . As most of the REST API features are not available in legacy 12.1 weblogic version.
So Let's go
Some Basics and Brief introduction to Weblogic REST API before we move on
Before we proceed to deployment tasks, There are some basics you need to learn about what is RESTful management Services and how to use REST API in weblogic. So I request you to read the following article (first few headlines) and come back to this article.
How to use Weblogic REST API for various management operations – Examples
If you are already familiar with REST API and want to know how to perform the deployment tasks just skip this and proceed further.
Deploy an Application using REST API - CURL
We have created some sample application named mwiapp.war and we are going to use the application in this post to perform various deployment-related tasks.
Here is command snippet in CURL to do the deployment
curl -v \ --user weblogic:weblogic1 \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ name: 'mwiapp', applicationPath : '/apps/oracle-weblogic/applications/mwiapp.war', targets: ['mwiCluster1'], plan: '/apps/oracle-weblogic/applications/plan.xml', deploymentOptions: {} }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/deploy
Decoding the CURL Command Snippet
Passing username and password with the request.
– user weblogic:weblogic1 \
Note*: Using Clear text username and password in CURL is insecure, we highly recommend you to use our SecureCLI tool to hide the clear text username and password while making API calls
How to Avoid or Hide clear text username and password in CURL
These following lines hold the header name and their values to be passed to REST API as we are making an HTTP/HTTPS call.
-H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \
As we have application/json in the Accept header, The result will be in JSON format
The Following lines in the snippet are the data we are passing to the REST API POST method. Its basically framed as Key and Value format in other words JSON
-d "{ name: 'mwiapp', applicationPath : '/apps/oracle-weblogic/applications/mwiapp.war', targets: ['mwiCluster1'], plan: '/apps/oracle-weblogic/applications/plan.xml', deploymentOptions: {} }" \
- Name of the application is mwiapp
- application archive location in the local file system is '/apps/oracle-weblogic/applications/mwiapp.war'
- targets is a cluster named 'mwiCluster1'
- plan xml file location is '/apps/oracle-weblogic/applications/plan.xml'
- deploymentOptions are the optional values you could pass during the deployment task and it allows to override the deployment options. If not provided, default options will be used. The values should all be of type The keys, units and default values for deployments options are as follows
clusterDeploymentTimeout: 3600000 milliseconds gracefulIgnoreSessions: false gracefulProductionToAdmin: false retireGracefully: true retireTimeout: no timeout adminMode: false timeout: no timeout
To know how to generate plan.xml for your application, click on expand source below (or) skip and proceed
[email protected]:/apps/oracle-weblogic/applications$ java weblogic.PlanGenerator mwiapp.war Generating plan for application mwiapp.war using input plan, plan.xml Export option is: dependencies <10 May, 2018 1:29:03 PM IST> <Info> <Munger> <BEA-2156202> <References were found in the deployment plan for module "mwiapp.war" with URI, "WEB-INF/weblogic.xml". The plan was merged.> <10 May, 2018 1:29:03 PM IST> <Info> <Munger> <BEA-2156202> <References were found in the deployment plan for module "mwiapp.war" with URI, "WEB-INF/weblogic.xml". The plan was merged.> <10 May, 2018 1:29:03 PM IST> <Info> <Munger> <BEA-2156202> <References were found in the deployment plan for module "mwiapp.war" with URI, "WEB-INF/web.xml". The plan was merged.> <10 May, 2018 1:29:03 PM IST> <Info> <Munger> <BEA-2156202> <References were found in the deployment plan for module "mwiapp.war" with URI, "WEB-INF/web.xml". The plan was merged.> <10 May, 2018 1:29:04 PM IST> <Info> <J2EE Deployment SPI> <BEA-260071> <Restored configuration for application, mwiapp.war> Exporting properties... Saving plan to /apps/oracle-weblogic/applications/plan.xml... <10 May, 2018 1:29:04 PM IST> <Info> <J2EE Deployment SPI> <BEA-260072> <Saved configuration for application, mwiapp.war>
Deployment Execution and Sample Output
Note: We are using Secure CLI tool to securely make a CURL calls and this example is also using SecureCLI
] [email protected]:/opt/python_script$ ./SecureCLI-Curl.py ------------------------------------------------------------------------------------------ Secure CLI for CURL - No more clear text password ------------------------------------------------------------------------------------------ Instrutions ------------ This is Secure CLI for CURL tool created to efficiently pass the username and password to CURL Now you will be prompted for username & password After Entering the username and password you DO NOT have to use – user username:password in your request header The Tool will take care of passing the credentials as a Authorization header Note*: Your details will not be saved and only valid for this session Example: -------- curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -X GET http://localhost:7001/management/weblogic/latest/serverConfig?links=none END ------------------------------------------------------------------------------------------ Enter the Username: weblogic Enter the Password: INFO: the entered user credentials have been encrypted and will be sent as a header Enter the whole request line by line, type END and hit enter once done curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ name: 'mwiapp', applicationPath : '/apps/oracle-weblogic/applications/mwiapp.war', targets: ['mwiCluster1'], plan: '/apps/oracle-weblogic/applications/plan.xml', deploymentOptions: {} }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/deploy END ['curl -v \\', '-H "Authorization: Basic d2VibG9naWM6d2VibG9naWMx"', '-H X-Requested-By:MyClient \\', '-H Accept:application/json \\', '-H Content-Type:application/json \\', '-d "{', " name: 'mwiapp',", " applicationPath : '/apps/oracle-weblogic/applications/mwiapp.war',", " targets: ['mwiCluster1'],", " plan: '/apps/oracle-weblogic/applications/plan.xml',", ' deploymentOptions: {}', '}" \\', '-X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/deploy'] COMMAND curl -v \ -H "Authorization: Basic d2VibG9naWM6d2VibG9naWMx" -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ name: 'mwiapp', applicationPath : '/apps/oracle-weblogic/applications/mwiapp.war', targets: ['mwiCluster1'], plan: '/apps/oracle-weblogic/applications/plan.xml', deploymentOptions: {} }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/deploy ========================== Execution Result ========================== Note: Unnecessary use of -X or – request, POST is already inferred. % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 – :--: – – :--: – – :--: – 0* Trying ::1... * TCP_NODELAY set * Connection failed * connect to ::1 port 17001 failed: Connection refused * Trying 127.0.0.1... * TCP_NODELAY set * Connected to localhost (127.0.0.1) port 17001 (#0) > POST /management/weblogic/latest/domainRuntime/deploymentManager/deploy HTTP/1.1 > Host: localhost:17001 > User-Agent: curl/7.54.0 > Authorization: Basic d2VibG9naWM6d2VibG9naWMx > X-Requested-By:MyClient > Accept:application/json > Content-Type:application/json > Content-Length: 206 > } [206 bytes data] * upload completely sent off: 206 out of 206 bytes 100 206 0 0 100 206 0 39 0:00:05 0:00:05 – :--: – 39< HTTP/1.1 200 OK < Date: Thu, 10 May 2018 08:30:18 GMT < Content-Length: 1485 < Content-Type: application/json < X-ORACLE-DMS-ECID: 9ac582eb-85e6-4dbe-9461-6a161f5f219c-00000036 < X-ORACLE-DMS-RID: 0 < Set-Cookie: JSESSIONID=gKRJLB8O5vxHp0QDZcdstr5TsQeP13pIAp7v2aOB5IneFpZvhxQ4!1365034742; path=/; HttpOnly < { [1485 bytes data] 100 1691 100 1485 100 206 262 36 0:00:05 0:00:05 – :--: – 370 * Connection #0 to host localhost left intact { "links": [{ "rel": "job", "href": "http:\/\/localhost:17001\/management\/weblogic\/latest\/domainRuntime\/deploymentManager\/deploymentProgressObjects\/mwiapp" }], "identity": [ "deploymentManager", "deploymentProgressObjects", "mwiapp" ], "rootExceptions": [], "endTimeAsLong": 1525941023604, "deploymentMessages": [ "[Deployer:149191]Operation \"deploy\" on application \"mwiapp\" is initializing on \"mwiserver3\".", "[Deployer:149191]Operation \"deploy\" on application \"mwiapp\" is initializing on \"mwiserver1\".", "[Deployer:149192]Operation \"deploy\" on application \"mwiapp\" is in progress on \"mwiserver1\".", "[Deployer:149192]Operation \"deploy\" on application \"mwiapp\" is in progress on \"mwiserver3\".", "[Deployer:149194]Operation \"deploy\" on application \"mwiapp\" has succeeded on \"mwiserver1\".", "[Deployer:149194]Operation \"deploy\" on application \"mwiapp\" has succeeded on \"mwiserver3\"." ], "name": "mwiapp", "operationType": 3, "startTimeAsLong": 1525941018491, "state": "STATE_COMPLETED", "id": "1", "type": "DeploymentProgressObject", "targets": ["mwiCluster1"], "applicationName": "mwiapp", "failedTargets": [], "progress": "success", "completed": true, "intervalToPoll": 1000, "startTime": "2018-05-10T14:00:18.491+05:30", "endTime": "2018-05-10T14:00:23.604+05:30" } ========================== Would you like to Proceed and Make a New Request ? Yes to Continue| No to exit : No [email protected]:/opt/python_script$
As shown in the preceding sample output, Application deployment using Weblogic REST API is simple and effective and you can get to see the various status changes and phases of the deployment is a valued added.
Here are some more snippets for your reference and usage. You can modify it and use it for all your needs
Note*: we have removed the --user header in all these example snippets and using SecureCLI as we hope you are adherent to the good security standards like we do. if you are OK with using clear text password please add the user header right after curl -v. ( Example Shown above )
--user weblogic:weblogic1
Get state of the Deployed Application
Command Snippet
curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ target: 'mwiCluster1' }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/appDeploymentRuntimes/mwiapp/getState
Result
Note: Unnecessary use of -X or – request, POST is already inferred. % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 – :--: – – :--: – – :--: – 0* Trying ::1... * TCP_NODELAY set * Connection failed * connect to ::1 port 17001 failed: Connection refused * Trying 127.0.0.1... * TCP_NODELAY set * Connected to localhost (127.0.0.1) port 17001 (#0) > POST /management/weblogic/latest/domainRuntime/deploymentManager/appDeploymentRuntimes/mwiapp/getState HTTP/1.1 > Host: localhost:17001 > User-Agent: curl/7.54.0 > Authorization: Basic d2VibG9naWM6d2VibG9naWMx > X-Requested-By:MyClient > Accept:application/json > Content-Type:application/json > Content-Length: 29 > } [29 bytes data] * upload completely sent off: 29 out of 29 bytes < HTTP/1.1 200 OK < Date: Thu, 10 May 2018 08:58:00 GMT < Content-Length: 26 < Content-Type: application/json < Set-Cookie: JSESSIONID=DK5JRXuzvqH4jhqnwZU_PjgoIS4IGkce35CN783SmKjEgL2V-kdO!1365034742; path=/; HttpOnly < { [26 bytes data] 100 55 100 26 100 29 115 128 – :--: – – :--: – – :--: – 129 * Connection #0 to host localhost left intact {"return": "STATE_ACTIVE"}
Redeploy an Application
curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ targets: ['mwiCluster1'], plan: '/apps/oracle-weblogic/applications/plan.xml', deploymentOptions: {} }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/appDeploymentRuntimes/mwiapp/redeploy
Start an Application
curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ targets: ['mwiCluster1'], deploymentOptions: {} }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/appDeploymentRuntimes/mwiapp/start
Stop an Application
curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ targets: ['mwiCluster1'], deploymentOptions: {} }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/appDeploymentRuntimes/mwiapp/stop
Undeploy an Application
curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ targets: ['mwiCluster1'], deploymentOptions: {} }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/appDeploymentRuntimes/mwiapp/undeploy
Update an Application
curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ targets: ['mwiCluster1'], deploymentOptions: {}, plan: '/apps/oracle-weblogic/applications/plan.xml' }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/deploymentManager/appDeploymentRuntimes/mwiapp/update
Get All Deployed Application Health State
curl -v \ -H X-Requested-By:MyClient \ -H Accept:application/json \ -H Content-Type:application/json \ -d "{ links: [], fields: [], children: { serverRuntimes: { links: [], fields: ['name'], children: { applicationRuntimes: { links: [], fields: ['name','healthState','OverallHealthState'] } } } } }" \ -X POST http://localhost:17001/management/weblogic/latest/domainRuntime/search
Deployment tasks using weblogic REST API Video Guide (Covering all the aforementioned deployment tasks)
Hope it Helps
If you like mwinventory, Subscribe for latest posts and stay connected. Leave your name and email in the below form
We promise! we never SPAM.
Cheers,
A K S A R A V
Write to us at [email protected]
Follow us on Facebook | Twitter
To Join our Community in Whatsapp – Click here