3.5.2. 原生 API

原生 API 端点是管理客户端的入口点,它依赖于原生协议与 JBoss EAP 管理层集成。原生 API 由 JBoss EAP 管理 CLI 使用,但也为其他客户端提供集成功能。

以下 Java 代码演示了如何使用原生 API 从 Java 代码执行管理操作的示例。

注意

您必须将 EAP_HOME/bin/client/jboss-cli-client.jar 文件中所需的 JBoss EAP 库添加到您的类路径中。

示例:使用原生 API 读取资源

// Create the management client
ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990);

// Create the operation request
ModelNode op = new ModelNode();

// Set the operation
op.get("operation").set("read-resource");

// Set the address
ModelNode address = op.get("address");
address.add("subsystem", "undertow");
address.add("server", "default-server");
address.add("http-listener", "default");

// Execute the operation and manipulate the result
ModelNode returnVal = client.execute(op);
System.out.println("Outcome: " + returnVal.get("outcome").toString());
System.out.println("Result: " + returnVal.get("result").toString());

// Close the client
client.close();