Show Table of Contents
10.4. HTTP API を用いたデプロイ
10.4.1. HTTP API を使用したアプリケーションのデプロイ
概要
以下の手順に従って、HTTP API よりアプリケーションをデプロイできます。
手順10.7 DeployDmrToJson.java を使用したアプリケーションのデプロイ
DeployDmrToJson.javaを使用して JSON へのリクエストを生成し、アプリケーションをデプロイします。例10.1 DeployDmrToJson.java クラス
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("\nUneploy\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; } }- 以下のように、コマンドを使用してクラスを実行します。
例10.2 コマンドの実行
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
- クラスが実行されると、以下のコマンド形式が表示されます。必要に応じて、
deployまたはundeployコマンドを使用します。例10.3
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"}}]} Uneploy ------------------------------ 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"}}]} - 以下のコマンドを使用して、アプリケーションをデプロイまたはアンデプロイします。
json requestを上記のリクエストに置き換えます。例10.4 コマンドの実行
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.