使用openfire服务器从聊天室删除会员

时间:2016-07-23 06:50:41

标签: java api rest xmpp openfire

我是openfire xmpp协议的新手。我已成功创建聊天室,现在我想使用REST API从房间删除房间成员。 我一直在推荐这里提到的link。  删除聊天室的会员。

@RequestMapping(value = "leaveGroup", headers = {"ACCEPT=*/*"}, method = RequestMethod.POST, produces = "text/plain")
    public @ResponseBody
    String leaveGroup(HttpServletRequest request, HttpServletResponse response) {

        getRestClient();
        try {
            List<String> memberList = restApiClient.getChatRoom("chatrooms").getMembers();
            for (String string : memberList) {
                System.out.println("user::" + string);
            }
            // http://example.org:9090/plugins/restapi/v1/chatrooms/chatrooms/members/rajesh3@peacock-hp

            getJsonFromWEBService("http://192.168.168.24:9090/plugins/restapi/v1/chatrooms/chatrooms/members/rajesh3@peacock-hp");

            //List<String> memberList1 = restApiClient.getChatRoom("chatrooms").getMembers().remove("rajesh3@peacock-hp");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "leaveGroup";
    }

    public void getJsonFromWEBService(String serviceURL) {
        URL url;
        try {
            System.out.println("serviceURL::" + serviceURL);
            url = new URL(serviceURL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            System.out.println("conn::" + conn);
            conn.setRequestProperty("Authorization", "Basic YWRtaW46MTIzNDU=");
            conn.setRequestProperty("Content-Type", "application/xml");
            conn.setRequestMethod("DELETE");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            System.out.println("status::"+conn.getResponseCode());
            System.out.println("msg::"+conn.getResponseMessage());
            System.out.println("req::"+conn.getRequestProperties());
            //conn.getOutputStream().write(postDataBytes);
            conn.disconnect();
            System.out.println("end..........................................");
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

我收到了错误

Info: Response status::401
Info:   Response msg::Unauthorized

这里的openfire控制台&#39;日志文件

2016.07.23 12:14:41 org.jivesoftware.openfire.container.PluginManager - error in opening zip file 
java.util.zip.ZipException: error in opening zip file 
at java.util.zip.ZipFile.open(Native Method) 
at java.util.zip.ZipFile.<init>(ZipFile.java:219) 
at java.util.zip.ZipFile.<init>(ZipFile.java:149) 
at java.util.jar.JarFile.<init>(JarFile.java:166) 
at java.util.jar.JarFile.<init>(JarFile.java:130) 
at org.jivesoftware.openfire.container.PluginManager$PluginMonitor.unzipPlugin(PluginManager.java:1069) 
at org.jivesoftware.openfire.container.PluginManager$PluginMonitor.run(PluginManager.java:961) 

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

如果您使用旧版本的openfire,则无法在请求的路径中使用JID。 (rajesh3 @孔雀马力)。 请尝试使用rajesh3。

答案 1 :(得分:0)

在文档中,可以阅读这些示例:

 /chatrooms/{roomName}/{roles}/{name}

所以你试图从名为“ chatrooms ”的聊天室中的“成员”用户“rajesh3 @ peacock-hp”中删除,我认为这不会起作用!

您需要聊天室名称(es:mychatroom@conference.peacock-hp),然后检查rajesh3@peacock-hp是否已成为此聊天室的成员 (检查Openfire管理员以避免错误:

Admin console -> Uppertab: Group Chat -> select the service -> select your chatroom -> on left "Permissions" ->  rajesh3@peacock-hp must figure out as "member")

如果您想在全局模式下删除rajesh3 @ peacock-hp,请将global设为roomName

编辑:顺便说一下,错误报告它是关于插件没有正确加载,它对删除房间成员操作没有影响。