Reputation: 21
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) ). The user is gets logged in thru client in chatroom and I can see it in 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. 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. 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, "[email protected]");
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");
}
Upvotes: 0
Views: 71
Reputation: 9473
First you need to create a connection. Connect and authenticate to the server. Only then you create a MUC.
From your code I get the impression you are not authenticating and thus try to join or create the chat anonymously.
Upvotes: 0