简体   繁体   中英

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) ). 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, "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.

From your code I get the impression you are not authenticating and thus try to join or create the chat anonymously.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM