Search in sources :

Example 6 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class MucBookmarkAutojoinManager method autojoinBookmarkedConferences.

public void autojoinBookmarkedConferences() {
    List<BookmarkedConference> bookmarkedConferences;
    try {
        bookmarkedConferences = bookmarkManager.getBookmarkedConferences();
    } catch (NotConnectedException | InterruptedException e) {
        LOGGER.log(Level.FINER, "Could not get MUC bookmarks", e);
        return;
    } catch (NoResponseException | XMPPErrorException e) {
        LOGGER.log(Level.WARNING, "Could not get MUC bookmarks", e);
        return;
    }
    final XMPPConnection connection = connection();
    Resourcepart defaultNick = connection.getUser().getResourcepart();
    for (BookmarkedConference bookmarkedConference : bookmarkedConferences) {
        if (!bookmarkedConference.isAutoJoin()) {
            continue;
        }
        Resourcepart nick = bookmarkedConference.getNickname();
        if (nick == null) {
            nick = defaultNick;
        }
        String password = bookmarkedConference.getPassword();
        MultiUserChat muc = multiUserChatManager.getMultiUserChat(bookmarkedConference.getJid());
        try {
            MucCreateConfigFormHandle handle = muc.createOrJoinIfNecessary(nick, password);
            if (handle != null) {
                handle.makeInstant();
            }
        } catch (NotConnectedException | InterruptedException e) {
            LOGGER.log(Level.FINER, "Could not autojoin bookmarked MUC", e);
            // abort here
            break;
        } catch (NotAMucServiceException | NoResponseException | XMPPErrorException e) {
            // Do no abort, just log,
            LOGGER.log(Level.WARNING, "Could not autojoin bookmarked MUC", e);
        }
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)

Example 7 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class MultiUserChat method enter.

/**
     * Enter a room, as described in XEP-45 7.2.
     *
     * @param conf the configuration used to enter the room.
     * @return the returned presence by the service after the client send the initial presence in order to enter the room.
     * @throws NotConnectedException
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws InterruptedException
     * @throws NotAMucServiceException 
     * @see <a href="http://xmpp.org/extensions/xep-0045.html#enter">XEP-45 7.2 Entering a Room</a>
     */
private Presence enter(MucEnterConfiguration conf) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException, NotAMucServiceException {
    final DomainBareJid mucService = room.asDomainBareJid();
    if (!KNOWN_MUC_SERVICES.containsKey(mucService)) {
        if (multiUserChatManager.providesMucService(mucService)) {
            KNOWN_MUC_SERVICES.put(mucService, null);
        } else {
            throw new NotAMucServiceException(this);
        }
    }
    // We enter a room by sending a presence packet where the "to"
    // field is in the form "roomName@service/nickname"
    Presence joinPresence = conf.getJoinPresence(this);
    // Setup the messageListeners and presenceListeners *before* the join presence is send.
    connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
    connection.addSyncStanzaListener(presenceListener, new AndFilter(fromRoomFilter, StanzaTypeFilter.PRESENCE));
    connection.addSyncStanzaListener(subjectListener, new AndFilter(fromRoomFilter, MessageWithSubjectFilter.INSTANCE, new NotFilter(MessageTypeFilter.ERROR)));
    connection.addSyncStanzaListener(declinesListener, DECLINE_FILTER);
    connection.addPacketInterceptor(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room), StanzaTypeFilter.PRESENCE));
    messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
    // Wait for a presence packet back from the server.
    // @formatter:off
    StanzaFilter responseFilter = new AndFilter(StanzaTypeFilter.PRESENCE, new OrFilter(// We use a bare JID filter for positive responses, since the MUC service/room may rewrite the nickname.
    new AndFilter(FromMatchesFilter.createBare(getRoom()), MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF), // JID we send the join presence to.
    new AndFilter(FromMatchesFilter.createFull(joinPresence.getTo()), new StanzaIdFilter(joinPresence), PresenceTypeFilter.ERROR)));
    // @formatter:on
    Presence presence;
    try {
        presence = connection.createStanzaCollectorAndSend(responseFilter, joinPresence).nextResultOrThrow(conf.getTimeout());
    } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
        // Ensure that all callbacks are removed if there is an exception
        removeConnectionCallbacks();
        throw e;
    }
    // This presence must be send from a full JID. We use the resourcepart of this JID as nick, since the room may
    // performed roomnick rewriting
    this.nickname = presence.getFrom().asEntityFullJidIfPossible().getResourcepart();
    joined = true;
    // Update the list of joined rooms
    multiUserChatManager.addJoinedRoom(room);
    return presence;
}
Also used : StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) OrFilter(org.jivesoftware.smack.filter.OrFilter) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaIdFilter(org.jivesoftware.smack.filter.StanzaIdFilter) NotFilter(org.jivesoftware.smack.filter.NotFilter) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 8 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class MultiUserChatLight method create.

/**
     * Create new MUCLight.
     * 
     * @param roomName
     * @param subject
     * @param customConfigs
     * @param occupants
     * @throws Exception
     */
public void create(String roomName, String subject, HashMap<String, String> customConfigs, List<Jid> occupants) throws Exception {
    MUCLightCreateIQ createMUCLightIQ = new MUCLightCreateIQ(room, roomName, occupants);
    messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
    try {
        connection.createStanzaCollectorAndSend(createMUCLightIQ).nextResultOrThrow();
    } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
        removeConnectionCallbacks();
        throw e;
    }
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) MUCLightCreateIQ(org.jivesoftware.smackx.muclight.element.MUCLightCreateIQ)

Example 9 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class IntTestUtil method deleteViaIbr.

public static void deleteViaIbr(XMPPTCPConnection connection) throws InterruptedException {
    // mechanisms
    if (!connection.isConnected()) {
        try {
            connection.connect().login();
        } catch (XMPPException | SmackException | IOException e) {
            LOGGER.log(Level.WARNING, "Exception reconnection account for deletion", e);
        }
    }
    final int maxAttempts = 3;
    AccountManager am = AccountManager.getInstance(connection);
    int attempts;
    for (attempts = 0; attempts < maxAttempts; attempts++) {
        try {
            am.deleteAccount();
        } catch (XMPPErrorException | NoResponseException e) {
            LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
            continue;
        } catch (NotConnectedException e) {
            LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
            try {
                connection.connect().login();
            } catch (XMPPException | SmackException | IOException e2) {
                LOGGER.log(Level.WARNING, "Exception while trying to re-connect " + connection, e);
            }
            continue;
        }
        LOGGER.info("Successfully deleted account of " + connection);
        break;
    }
    if (attempts > maxAttempts) {
        LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
    }
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) SmackException(org.jivesoftware.smack.SmackException) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager) IOException(java.io.IOException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 10 with NotConnectedException

use of org.jivesoftware.smack.SmackException.NotConnectedException in project Smack by igniterealtime.

the class IntTestUtil method deleteViaServiceAdministration.

public static void deleteViaServiceAdministration(XMPPTCPConnection connection, Configuration config) {
    EntityBareJid accountToDelete = connection.getUser().asEntityBareJid();
    final int maxAttempts = 3;
    int attempts;
    for (attempts = 0; attempts < maxAttempts; attempts++) {
        connection.disconnect();
        try {
            connection.connect().login(config.adminAccountUsername, config.adminAccountPassword);
        } catch (XMPPException | SmackException | IOException | InterruptedException e) {
            LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
            continue;
        }
        ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection);
        try {
            adminManager.deleteUser(accountToDelete);
        } catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) {
            LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
            continue;
        }
    }
    if (attempts > maxAttempts) {
        LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
    }
}
Also used : ServiceAdministrationManager(org.jivesoftware.smackx.admin.ServiceAdministrationManager) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPException(org.jivesoftware.smack.XMPPException) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Aggregations

NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)22 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)11 XMPPException (org.jivesoftware.smack.XMPPException)11 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)9 SmackException (org.jivesoftware.smack.SmackException)6 IOException (java.io.IOException)5 XMPPConnection (org.jivesoftware.smack.XMPPConnection)5 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)3 KeyManagementException (java.security.KeyManagementException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 LinkedList (java.util.LinkedList)2 ChatManager (org.jivesoftware.smack.ChatManager)2 AlreadyConnectedException (org.jivesoftware.smack.SmackException.AlreadyConnectedException)2 AlreadyLoggedInException (org.jivesoftware.smack.SmackException.AlreadyLoggedInException)2 StreamErrorException (org.jivesoftware.smack.XMPPException.StreamErrorException)2 AndFilter (org.jivesoftware.smack.filter.AndFilter)2 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)2 NotAMucServiceException (org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2 InetAddress (java.net.InetAddress)1