用 Java 操作管理 Openfire(比如管理用户,包括创建、删除用户等)
1. 为 Openfire 安装 REST API 插件
安装后在管理平台的插件列表里可以看到 REST API 插件:
2. 配置 REST API 插件
打开 REST API 插件属性页面,配置插件:
注意,如果打不开插件的属性页面,可能是插件版本与 Openfire 的版本不适配的缘故,到 Openfire 官网查看是否适配,如果不适配就下载适配的插件安装。
控制台上显示的版本号:
在官网上查看版本是否适配:
3. 创建 Java Maven 项目
创建项目后,在 pom.xml 文件中加入 Openfire Client 支持:
<dependency>
<groupId>org.igniterealtime</groupId>
<artifactId>rest-api-client</artifactId>
<version>1.1.4</version>
</dependency>
4. 编写 Java 代码
直接上代码:
package oepnfireRestapi;
import java.util.Random;
import javax.ws.rs.core.Response;
import org.igniterealtime.restclient.RestApiClient;
import org.igniterealtime.restclient.entity.Authenticatio