简体   繁体   English

如何通过 REST 在 WildFly 中执行系统属性操作?

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

This documentation states that one can perform certain operations for a WildFly server via REST: https://docs.jboss.org/author/display/WFLY10/The%20HTTP%20management%20API.html However, there is no example how to add/remove/read a system property.该文档指出可以通过 REST 对 WildFly 服务器执行某些操作: https ://docs.jboss.org/author/display/WFLY10/The%20HTTP%20management%20API.html 但是,没有示例如何添加/删除/读取系统属性。 I have no idea how the HTTP body has to look for those calls.我不知道 HTTP 主体必须如何查找这些调用。

The answer of the following StackOverflow question says that the class SimpleOperation used in the example does not really exist: Wildfly 10 management Rest API下面StackOverflow问题的答案说,示例中使用的类SimpleOperation实际上并不存在: Wildfly 10 management Rest API

I would like to do the following operations:我想做以下操作:

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

and to read it.并阅读它。

How can I perform these operations via REST with the WildFly HTTP management API?如何使用 WildFly HTTP 管理 API 通过 REST 执行这些操作? Ideally, I would use a Java API if there was one.理想情况下,如果有的话,我会使用 Java API。

With the org.wildfly.core:wildfly-controller-client API you could do something like this:使用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());
    }
}

You can use the REST API too, however you'll need to have a way to do digest authentication.您也可以使用 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.

相关问题 如何在Wildfly中使用自定义系统属性解析程序 - How to use custom system property resolver in Wildfly 如何在Wildfly中启用远程管理操作 - How to enable remote management operations in Wildfly 如何通过环境变量设置系统属性? - How to set a system property via envirnmoent variable? 如何使用JSch执行多个操作 - How to perform multiple operations with JSch 如何以编程方式执行查询操作? - how to perform operations in queries programatically? 如何在wildfly 17中将&#39;org.apache.jasper.compiler.Parser.STRICT_WHITESPACE&#39;设置为系统属性? - How to set 'org.apache.jasper.compiler.Parser.STRICT_WHITESPACE' in wildfly 17 as system property? Wildfly 8.1-设置系统属性而不使用standalone.xml - Wildfly 8.1 - set system property without standalone.xml 如何使用 java + spring 代码实现将 MFT 服务器与暴露的 rest 连接以执行上传、下载和列出文件等操作 - How to connect MFT server with rest exposed to perform operations like upload, download and list files using java + spring code Implementation 如何在REST中处理异步操作 - How to handle asynchronous operations in REST 如何通过 Kotlin Gradle 和 -D 为我的测试提供系统属性 - How to give System property to my test via Kotlin Gradle and -D
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM