• XMPP即时通讯协议使用(十三)——获取当前在线用户或关闭指定用户


    1、开启REST API插件或根据需求修改其插件源码;

    2、添加服务器->服务器管理->系统属性中添加

    plugin.restapi.enabled=true

    3、pom依赖

    <dependency>
    	<groupId>org.igniterealtime</groupId>
    	<artifactId>rest-api-client</artifactId>
    	<version>1.1.4</version>
    </dependency>

    4、相关代码

    import java.util.List;
    
    import org.igniterealtime.restclient.RestApiClient;
    import org.igniterealtime.restclient.entity.AuthenticationToken;
    import org.igniterealtime.restclient.entity.SessionEntity;
    
    public class Test {
    	public static void main(String[] args) {
    		// Set Shared secret key
    		AuthenticationToken authenticationToken = new AuthenticationToken("admin", "123456");
    		// Set Openfire settings (9090 is the port of Openfire Admin Console)
    		RestApiClient restApiClient = new RestApiClient("http://127.0.0.1", 9090, authenticationToken);
    
    		// Request all active Sessions
    		System.out.println(restApiClient.getSessions());
    
    		// Request all active Sessions from a specific user
    		System.out.println(restApiClient.getSessions("admin"));
    		
    		List<SessionEntity> list = restApiClient.getSessions("admin").getSessions();
    		for(SessionEntity session:list) {
    			System.out.println(session.getSessionId());
    		}
    		// 关闭指定用户
    		restApiClient.deleteSessions("admin");
    	}
    }

    5、补充

    Openfire源码下载地址:https://www.igniterealtime.org/downloads/source.jsp

    rest-api-client源码地址:https://github.com/igniterealtime/REST-API-Client

  • 相关阅读:
    npm包开发与发布
    mapbox展示动态图标
    axios并行请求
    Vue引入ES5的js库
    git常用操作
    单词倒排
    FT232RL芯片USB转TTL应用
    应用GL823芯片自制的读卡器
    队列图示
    队列
  • 原文地址:https://www.cnblogs.com/gmhappy/p/11864030.html
Copyright © 2020-2023  润新知