[英]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.