Search in sources :

Example 11 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project Smack by igniterealtime.

the class XMPPErrorTest method testCancel.

/**
     * Check the parser with an xml with the 404 error.
    */
public void testCancel() {
    // Make the XML to test
    String xml = "<error type='cancel'>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>";
    try {
        // Create the xml parser
        XmlPullParser parser = getParserFromXML(xml);
        // Create a packet from the xml
        XMPPError error = parseError(parser);
        assertNotNull(error);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XMPPError(org.jivesoftware.smack.packet.XMPPError) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 12 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project Smack by igniterealtime.

the class XMPPErrorTest method testLocalErrorCreation.

/**
     * Check the creation of a new xmppError locally.
    */
public void testLocalErrorCreation() {
    XMPPError error = new XMPPError(XMPPError.Condition.item_not_found);
    error.toXML();
    assertEquals(error.getCondition(), "item-not-found");
    assertEquals(error.getCode(), 404);
    assertEquals(error.getType(), XMPPError.Type.CANCEL);
    assertNull(error.getMessage());
}
Also used : XMPPError(org.jivesoftware.smack.packet.XMPPError)

Example 13 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project Smack by igniterealtime.

the class XMPPErrorTest method testLocalErrorWithCommentCreation.

/**
     * Check the creation of a new xmppError locally.
    */
public void testLocalErrorWithCommentCreation() {
    String message = "Error Message";
    XMPPError error = new XMPPError(XMPPError.Condition.item_not_found, message);
    error.toXML();
    assertEquals(error.getCondition(), "item-not-found");
    assertEquals(error.getCode(), 404);
    assertEquals(error.getType(), XMPPError.Type.CANCEL);
    assertEquals(error.getMessage(), message);
}
Also used : XMPPError(org.jivesoftware.smack.packet.XMPPError)

Example 14 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project Smack by igniterealtime.

the class XMPPErrorTest method testCancelWithMessageAndApplicationError.

/**
     * Check the parser with an xml with the 404 error.
    */
public void testCancelWithMessageAndApplicationError() {
    // Make the XML to test
    String xml = "<error type='cancel' code='10'>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" + "Some special application diagnostic information!" + "</text>" + "<application-defined-error xmlns='application-ns'/>" + "</error>";
    try {
        // Create the xml parser
        XmlPullParser parser = getParserFromXML(xml);
        // Create a packet from the xml
        XMPPError error = parseError(parser);
        assertNotNull(error);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XMPPError(org.jivesoftware.smack.packet.XMPPError) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 15 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project xabber-android by redsolution.

the class MUCManager method joinRoom.

/**
     * Requests to join to the room.
     *
     * @param requested Whether user request to join the room.
     */
public void joinRoom(final String account, final String room, boolean requested) {
    final XMPPConnection xmppConnection;
    final RoomChat roomChat;
    final String nickname;
    final String password;
    final Thread thread;
    roomChat = getRoomChat(account, room);
    if (roomChat == null) {
        Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
        return;
    }
    RoomState state = roomChat.getState();
    if (state == RoomState.available || state == RoomState.occupation) {
        Application.getInstance().onError(R.string.ALREADY_JOINED);
        return;
    }
    if (state == RoomState.creating || state == RoomState.joining) {
        Application.getInstance().onError(R.string.ALREADY_IN_PROGRESS);
        return;
    }
    nickname = roomChat.getNickname();
    password = roomChat.getPassword();
    requestToWriteRoom(account, room, nickname, password, true);
    ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
    if (connectionThread == null) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
        return;
    }
    xmppConnection = connectionThread.getXMPPConnection();
    if (xmppConnection == null) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
        return;
    }
    final MultiUserChat multiUserChat;
    try {
        multiUserChat = MultiUserChatManager.getInstanceFor(xmppConnection).getMultiUserChat(room);
    } catch (IllegalStateException e) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
        return;
    }
    roomChat.setState(RoomState.joining);
    roomChat.setMultiUserChat(multiUserChat);
    roomChat.setRequested(requested);
    thread = new Thread("Join to room " + room + " from " + account) {

        @Override
        public void run() {
            try {
                if (roomChat.getMultiUserChat() != multiUserChat) {
                    return;
                }
                multiUserChat.join(nickname, password);
                Application.getInstance().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (roomChat.getMultiUserChat() != multiUserChat) {
                            return;
                        }
                        if (roomChat.getState() == RoomState.joining) {
                            roomChat.setState(RoomState.occupation);
                        }
                        removeAuthorizationError(account, room);
                        RosterManager.getInstance().onContactChanged(account, room);
                    }
                });
                return;
            } catch (final XMPPException.XMPPErrorException e) {
                Application.getInstance().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (roomChat.getMultiUserChat() != multiUserChat) {
                            return;
                        }
                        roomChat.setState(RoomState.error);
                        addAuthorizationError(account, room);
                        XMPPError xmppError = e.getXMPPError();
                        if (xmppError != null && xmppError.getCondition() == XMPPError.Condition.conflict) {
                            Application.getInstance().onError(R.string.NICK_ALREADY_USED);
                        } else if (xmppError != null && xmppError.getCondition() == XMPPError.Condition.not_authorized) {
                            Application.getInstance().onError(R.string.AUTHENTICATION_FAILED);
                        } else {
                            Application.getInstance().onError(R.string.NOT_CONNECTED);
                        }
                        RosterManager.getInstance().onContactChanged(account, room);
                    }
                });
                return;
            } catch (IllegalStateException e) {
            } catch (Exception e) {
                LogManager.exception(this, e);
            }
            Application.getInstance().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (roomChat.getMultiUserChat() != multiUserChat) {
                        return;
                    }
                    roomChat.setState(RoomState.waiting);
                    Application.getInstance().onError(R.string.NOT_CONNECTED);
                    RosterManager.getInstance().onContactChanged(account, room);
                }
            });
        }
    };
    thread.setDaemon(true);
    thread.start();
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPError(org.jivesoftware.smack.packet.XMPPError) SmackException(org.jivesoftware.smack.SmackException) NetworkException(com.xabber.android.data.NetworkException) XMPPException(org.jivesoftware.smack.XMPPException) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) ConnectionThread(com.xabber.android.data.connection.ConnectionThread)

Aggregations

XMPPError (org.jivesoftware.smack.packet.XMPPError)15 XmlPullParser (org.xmlpull.v1.XmlPullParser)5 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)5 XMPPException (org.jivesoftware.smack.XMPPException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 IQ (org.jivesoftware.smack.packet.IQ)2 NetworkException (com.xabber.android.data.NetworkException)1 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 EmptyResultIQ (org.jivesoftware.smack.packet.EmptyResultIQ)1 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)1 Form (org.jivesoftware.smackx.Form)1 Action (org.jivesoftware.smackx.commands.AdHocCommand.Action)1 AdHocCommandData (org.jivesoftware.smackx.commands.packet.AdHocCommandData)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 Form (org.jivesoftware.smackx.xdata.Form)1