[英]Not able to join Chatroom smack/smackx, XMPP: Exception not-authorized (401)
I am new in working on MultiUserChat (groupchat) using smack/smackx libraries and having a difficult time in joining a existing public chatroom and getting error (Exceptionnot-authorized(401) ).我是使用 smack/smackx 库处理 MultiUserChat (groupchat) 的新手,在加入现有公共聊天室时遇到困难并遇到错误 (Exceptionnot-authorized(401) )。 The user is gets logged in thru client in chatroom and I can see it in openfire.用户通过聊天室的客户端登录,我可以在 openfire 中看到它。 As per my understanding to iniiate the groupchat, user needs to create/join again.根据我对发起群聊的理解,用户需要再次创建/加入。 Below is the code I have written so far (For breivity I am keeping it short).下面是我到目前为止编写的代码(为简洁起见,我保持简短)。 All seems to okay and user is able to log in to server but as soon as the program tries to join the room I get not-authorized (401) error.一切似乎都很好,用户可以登录服务器,但是一旦程序尝试加入房间,我就会收到未授权 (401) 错误。 I have tried to join with nickname and also with nickname with password but it is resulting into same.我曾尝试使用昵称加入,也尝试使用带密码的昵称加入,但结果相同。
I am going thru the materials available on web for this and tried available solution but in vain.为此,我正在浏览 web 上可用的材料,并尝试了可用的解决方案,但没有成功。 I am sure I am doing some basic mistake.我确定我犯了一些基本错误。 Any pointers in this direction will be appreciated.在这个方向上的任何指针将不胜感激。
@SuppressWarnings("deprecation")
public boolean isGroupChatAlreadyCreated(@NonNull final EntityBareJid groupId)
throws XmppStringprepException,
NotAMucServiceException,
NotConnectedException,
InterruptedException,
NoResponseException, XMPPException
{
muc = new MultiUserChat(connection, "xyz@conference.abc");
muc.create("xyz");
Form form = muc.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for(Iterator fields = form.getFields();fields.hasNext();) {
FormField field = (FormField)fields.next();
if(!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable()!= null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("#muc#roomconfig_publicroom", true);
muc.sendConfigurationForm(submitForm);
System.out.println("Reaching before join");
//Getting error NOT-AuTHORIZED (401) here
muc.join("xyz");
} }
First you need to create a connection.首先,您需要创建一个连接。 Connect and authenticate to the server.连接到服务器并进行身份验证。 Only then you create a MUC.只有这样你才能创建 MUC。
From your code I get the impression you are not authenticating and thus try to join or create the chat anonymously.从您的代码中我得到您没有进行身份验证的印象,因此尝试匿名加入或创建聊天。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.