该文档说明可以通过REST对WildFly服务器执行某些操作:https://docs.jboss.org/author/display/WFLY10/The%20HTTP%20management%20API.html但是,没有如何添加/删除/读取系统属性的示例。我不知道HTTP体如何查找这些调用。
下面的StackOverflow问题的答案说,在示例中使用的类SimpleOperation并不真正存在:Wildfly 10管理Rest API
我想做以下操作:
/system-property=BLA:remove
/system-property=BLA:add(value="1,2,3,4")
和读取
我如何通过REST与WildFly HTTP管理API执行这些操作?理想情况下,如果有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();
}