0

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");

}

PC245
  • 21
  • 3

1 Answers1

0

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.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • Thanks for looking into this. Well I am connecting to server before joining the room. I just not posted it to keep question cleaner. BTW do you find any issues in my above code as such? – PC245 May 31 '22 at 14:48
  • So you are authenticated. In that case just check whether the room on the server side has privileges for you. Maybe create another chatroom that definitely does not exist. Your code looks ok to me, but it's been a while that I used Smack myself. – Queeg May 31 '22 at 21:22
  • Thanks again. Creating new room and test was good idea. After some alteration in openfire and few minor changes in code it worked like charm. – PC245 Jun 01 '22 at 14:09