繁体   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