Search code examples
javaandroidopenfiresmack

Smack Openfire Android Unable to send message to Group/Room Error 403 forbidden


MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(xmppconnection.getConnection());
try {
    MultiUserChat muc = manager.getMultiUserChat("test2@conference.cca");

    muc.join("test2@conference.cca");

    Message msg = new Message("test2@conference.cca", Message.Type.groupchat);
    msg.setBody("Hi Testing..Group chat..");
    muc.sendMessage(msg);
    // muc.join("test", "1234");
} catch (SmackException.NotConnectedException e) {
    e.printStackTrace();
} catch (SmackException e) {
    e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
    e.printStackTrace();
} catch (XMPPException e) {
    e.printStackTrace();
}

Error is:

error code="403" type="auth" forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>**


Solution

  • There are several errors, logical and procedurals.

    With this invocation:

     MultiUserChat muc = manager.getMultiUserChat("test2@conference.cca");
    

    you have in muc object your groupchat. So you need to check if you already joined this groupchat or double join will raise an exception.

    so

    if (!muc.isJoined())
     muc.join("My nickname");
    

    more, when you join, you MUST provide an unique nickname per User to join, or you'll obtain an exception with the second user. Set as nickname the same name of the groupchat it's 99% a logical error.

    Finally, to send a message, just send it through MUC object or you'll risk, like in this case, to miss some information.

    So just send it with

    muc.send("Hi Testing..Group chat..");
    

    Last but not least: of course multiuserchat must exists or inititilized before properly, it's a prerequisite to do all this. As first step, just create it in Openfire with http-admin-panel (make it persistant)