10.4. Deploy with the HTTP API
10.4.1. Deploy an application using the HTTP API
Applications can be deployed via the HTTP API using the following instructions.
Procedure 10.8. Deploy an application using DeployDmrToJson.java
- Use
DeployDmrToJson.javato generate a request to JSON to deploy your application.Example 10.1. DeployDmrToJson.java class
import org.jboss.dmr.ModelNode; import java.net.URL; public class DeployDmrToJson { public static void main(String[] args) throws Exception { if(args.length < 1) throw new IllegalArgumentException("The first argument must be a URL"); URL url = new URL(args[0]); String[] pathElements = url.getFile().split("/"); String name = pathElements[pathElements.length-1]; ModelNode deploy = getDeploy(url.toExternalForm(), name); ModelNode undeploy = getUndeploy(name); System.out.println("Deploy\n------------------------------\n"); System.out.println("Formatted:\n" + deploy.toJSONString(false)); System.out.println("Unformatted:\n" + deploy.toJSONString(true)); System.out.println("\nUndeploy\n------------------------------\n"); System.out.println("Formatted:\n" + undeploy.toJSONString(false)); System.out.println("Unformatted:\n" + undeploy.toJSONString(true)); } public static ModelNode getUndeploy(String name) { ModelNode undeployRequest = new ModelNode(); undeployRequest.get("operation").set("undeploy"); undeployRequest.get("address", "deployment").set(name); ModelNode removeRequest = new ModelNode(); removeRequest.get("operation").set("remove"); removeRequest.get("address", "deployment").set(name); ModelNode composite = new ModelNode(); composite.get("operation").set("composite"); composite.get("address").setEmptyList(); final ModelNode steps = composite.get("steps"); steps.add(undeployRequest); steps.add(removeRequest); return composite; } public static ModelNode getDeploy(String url, String name) { ModelNode deployRequest = new ModelNode(); deployRequest.get("operation").set("deploy"); deployRequest.get("address", "deployment").set(name); ModelNode addRequest = new ModelNode(); addRequest.get("operation").set("add"); addRequest.get("address", "deployment").set(name); addRequest.get("content").get(0).get("url").set(url); ModelNode composite = new ModelNode(); composite.get("operation").set("composite"); composite.get("address").setEmptyList(); final ModelNode steps = composite.get("steps"); steps.add(addRequest); steps.add(deployRequest); return composite; } } - Run the class using a command based on the following instructions:
Example 10.2. Execute command
java -cp .:$JBOSS_HOME/modules/org/jboss/dmr/main/jboss-dmr-1.1.1.Final-redhat-1.jar DeployDmrToJson \ file:///Users/username/support/helloWorld.war/dist/helloWorld.war
- When the class is run the following command formats will be displayed. Use either the
deployorundeploycommand relevant to your requirements.Example 10.3. Deploy and undeploy command
Deploy ------------------------------ Formatted: { "operation" : "composite", "address" : [], "steps" : [ { "operation" : "add", "address" : {"deployment" : "helloWorld.war"}, "content" : [{"url" : "file:/Users/username/support/helloWorld.war/dist/helloWorld.war"}] }, { "operation" : "deploy", "address" : {"deployment" : "helloWorld.war"} } ] } Unformatted: {"operation" : "composite", "address" : [], "steps" : [{"operation" : "add", "address" : {"deployment" : "helloWorld.war"}, "content" : [{"url" : "file:/Users/username/support/helloWorld.war/dist/helloWorld.war"}]},{"operation" : "deploy", "address" : {"deployment" : "helloWorld.war"}}]} Undeploy ------------------------------ Formatted: { "operation" : "composite", "address" : [], "steps" : [ { "operation" : "undeploy", "address" : {"deployment" : "helloWorld.war"} }, { "operation" : "remove", "address" : {"deployment" : "helloWorld.war"} } ] } Unformatted: {"operation" : "composite", "address" : [], "steps" : [{"operation" : "undeploy", "address" : {"deployment" : "helloWorld.war"}},{"operation" : "remove", "address" : {"deployment" : "helloWorld.war"}}]} - Use the following command to deploy or undeploy an application. Replace
json requestwith the request outlined above.Example 10.4. Execute command
curl -f --digest -u "<user>:<pass>" -H Content-Type:\ application/json -d '<json request>' "http://localhost:9990/management"

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.