簡體   English   中英

如何通過 REST 在 WildFly 中執行系統屬性操作?

[英]How to perform system property operations in WildFly via REST?

該文檔指出可以通過 REST 對 WildFly 服務器執行某些操作: https ://docs.jboss.org/author/display/WFLY10/The%20HTTP%20management%20API.html 但是,沒有示例如何添加/刪除/讀取系統屬性。 我不知道 HTTP 主體必須如何查找這些調用。

下面StackOverflow問題的答案說,示例中使用的類SimpleOperation實際上並不存在: Wildfly 10 management Rest API

我想做以下操作:

/system-property=BLA:remove
/system-property=BLA:add(value="1,2,3,4")

並閱讀它。

如何使用 WildFly HTTP 管理 API 通過 REST 執行這些操作? 理想情況下,如果有的話,我會使用 Java API。

使用org.wildfly.core:wildfly-controller-client API,您可以執行以下操作:

try (ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990)) {
    final ModelNode address = Operations.createAddress("system-property", "test.property");
    ModelNode op = Operations.createRemoveOperation(address);
    ModelNode result = client.execute(op);
    if (!Operations.isSuccessfulOutcome(result)) {
        throw new RuntimeException("Failed to remove property: " + Operations.getFailureDescription(result).asString());
    }
    op = Operations.createAddOperation(address);
    op.get("value").set("test-value");
    result = client.execute(op);
    if (!Operations.isSuccessfulOutcome(result)) {
        throw new RuntimeException("Failed to add property: " + Operations.getFailureDescription(result).asString());
    }
}

您也可以使用 REST API,但是您需要有一種方法來進行摘要式身份驗證。

Client client = null;
try {
    final JsonObject json = Json.createObjectBuilder()
            .add("address", Json.createArrayBuilder()
                    .add("system-property")
                    .add("test.property.2"))
            .add("operation", "add")
            .add("value", "test-value")
            .build();
    client = ClientBuilder.newClient();
    final Response response = client.target("http://localhost:9990/management/")
            .request()
            .header(HttpHeaders.AUTHORIZATION, "Digest <settings>")
            .post(Entity.json(json));
    System.out.println(response.getStatusInfo());
} finally {
    if (client != null) client.close();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM