• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Clean Programmer

Clean Programmer

Programming & DevOps Resources

  • Home
  • About
  • Contact

Deploy applications to a remote WildFly server using curl

July 18, 2018 Monzurul Haque Shimul

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.

Related Posts

Mapping Between Domain & Data Transfer Objects With MapStruct
Mapping Between Domain & Data Transfer Objects With MapStruct
Adding 3rd Party Jar to a Maven Project
Practicing Java: Simple String Encoding and Decoding
Practicing Java: Simple String Encoding and Decoding

Categories: Java EE, Wildfly Tags: curl, java, java-ee, jboss, jboss-cli, wildfly

Primary Sidebar

Categories

  • Apache Kafka
  • Druid
  • Git
  • Java
  • Java EE
  • Redis
  • Spring
  • Uncategorized
  • Weblogic
  • Wildfly

Featured Posts

Deploy applications to a remote WildFly Server using jboss-cli-client.jar

Most frequently used commands for managing Kafka Topic

Practicing Java: Simple String Encoding and Decoding

How to Configure Druid to Use Cassandra as Deep Storage

Running Imply Druid Distribution inside Docker Container

Druid quickstart using Imply distribution

Footer

Monzurul Haque Shimul

I’m a full-stack software engineer with 10 years of experience in design and development of large scaled Enterprise Software Systems built on Java and Java EE related tools and technologies. I’m also a contributor on GitHub, Stack Overflow, DZone. My core expertise lies in building JVM-based, scalable, reactive, data-driven applications.

Follow

  • Email
  • GitHub
  • LinkedIn
  • Twitter

© 2019 CLEAN PROGRAMMER

  • Home
  • Archive
  • About
  • Contact
  • Privacy Policy
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OKNoRead more
Revoke Cookies