
WildFly is a free, open source & cross platform application server (formely known as Jboss AS or Jboss). It is written in java programming language & currently it is being maintained, developed by Redhat. It is one of the most popular application servers among Java EE programmers all around the world.
WildFly provides multiple ways to deploy your applications. In this post, we will deploy applications to remote WildFly server using curl. See my other posts to learn the other ways to do it.
- Deploy applications to a remote WildFly server using jboss-cli
- Deploy applications to a remote WildFly Server using jboss-cli-client.jar
- Deploy applications to WildFly server using wildfly maven plugin
The Management API in WildFly is accessible through multiple channels, one of them being HTTP and JSON. Even if you haven’t used a curl command line you might already have used this channel since it is how the web console interact with the Management API.
Deploying applications using curl is a two-step process. It does not require you to have any distribution of WildFly or the jboss-cli-client.jar
inside the client machine.
Step 1: Upload the war/ear/jar distribution of the application to WildFly using the following command:
curl -F "file=@target/test.war" --digest http://<user>:<password>@<remote_wildfly_ip>:9990/management/add-content
This command makes a POST request:
“-F” using form-encoded data with one field (“file”) defining the location of the war/ear file
“target/test.war” is the location of the war file
“–digest” is used as WildFly management port uses digest authentication
“<user>:<password>” is the management username and password
“<remote_wildfly_ip>” is the management host and port for remote WildFly instance
The output of the command is something like:
{"outcome":"success","result":{"BYTES_VALUE":"NG6FkmnMOX4O/Blv+33todfnAXA="}}
Step 2: Deploy and enable the application using following command:
curl -S -H "Content-Type: application/json" -d '{"content":[{"hash": {"BYTES_VALUE" : "NG6FkmnMOX4O/Blv+33todfnAXA="}}], "address": [{"deployment":"test.war"}], "operation":"add", "enabled":"true"}' --digest http://<user>:<password>@<remote_wildfly_ip>:9990/management
This command sends a POST request:
“-d” with JSON payload
“-H” request heade specifying content type of the payload is “application/json”
“BYTES_VALUE” : “NG6FkmnMOX4O/Blv+33todfnAXA=” is the result of previous command
“operation”:”add” command triggers the deployment
“enabled”:”true” is to enable the application
“–digest” is used as WildFly management port uses digest authentication
“<user>:<password>” is the management username and password
“<remote_wildfly_ip>” is the management host and port for remote WildFly instance
If the application is already deployed, you will get a failure response:
{ "outcome": "failed", "failure-description": "WFLYCTL0212: Duplicate resource [(\"deployment\" => \"test.war\")]", "rolled-back": true }
In that case, need to change "operation":"add"
to "operation":"redeploy"
in the json payload:
curl -S -H "Content-Type: application/json" -d '{"content":[{"hash": {"BYTES_VALUE" : "NG6FkmnMOX4O/Blv+33todfnAXA="}}], "address": [{"deployment":"test.war"}], "operation":"redeploy", "enabled":"true"}' --digest http://<user>:<password>@<remote_wildfly_ip>:9990/management
Or you can undeploy application before running new deployment:
curl -S -H "Content-Type: application/json" -d '{"operation":"undeploy, "address": [{"deployment":"test.war"}]"}' --digest http://<user>:<password>@<remote_wildfly_ip>:9990/management
To know the deployment status, run:
curl -S -H "Content-Type: application/json" -d '{"operation":"read-resource","recursive":"true", "include-runtime":"true", "address":["deployment","test.war"], "json.pretty":1}' --digest http://<user>:<password>@<remote_wildfly_ip>:9990/management
The output will be something like this:
{ "outcome": "success", "result": { "content": [ { "hash": { "BYTES_VALUE": "NG6FkmnMOX4O/Blv+33todfnAXA=" }, "archive": null } ], "disabled-time": null, "disabled-timestamp": null, "enabled": true, "enabled-time": 1531723270025, "enabled-timestamp": "2018-07-16 12:41:10,025 BDT", "managed": true, "name": "test.war", "owner": null, "persistent": true, "runtime-name": "test.war", "status": "OK", "subdeployment": null, "subsystem": { "undertow": null } } }
That’s it! Now your application is deployed and enabled in the remote WildFly instance using curl.