Search in sources :

Example 1 with NoResponseException

use of org.jivesoftware.smack.SmackException.NoResponseException 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 2 with NoResponseException

use of org.jivesoftware.smack.SmackException.NoResponseException 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)

Example 3 with NoResponseException

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

the class Socks5ClientForInitiator method getSocket.

@Override
public Socket getSocket(int timeout) throws IOException, InterruptedException, TimeoutException, XMPPException, SmackException {
    Socket socket = null;
    // check if stream host is the local SOCKS5 proxy
    if (this.streamHost.getJID().equals(this.connection.get().getUser())) {
        Socks5Proxy socks5Server = Socks5Proxy.getSocks5Proxy();
        socket = socks5Server.getSocket(this.digest);
        if (socket == null) {
            throw new SmackException("target is not connected to SOCKS5 proxy");
        }
    } else {
        socket = super.getSocket(timeout);
        try {
            activate();
        } catch (XMPPException e1) {
            socket.close();
            throw e1;
        } catch (NoResponseException e2) {
            socket.close();
            throw e2;
        }
    }
    return socket;
}
Also used : SmackException(org.jivesoftware.smack.SmackException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPException(org.jivesoftware.smack.XMPPException) Socket(java.net.Socket)

Example 4 with NoResponseException

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

the class ServiceDiscoveryManager method findServicesDiscoverInfo.

/**
     * Find all services under the users service that provide a given feature.
     * 
     * @param feature the feature to search for
     * @param stopOnFirst if true, stop searching after the first service was found
     * @param useCache if true, query a cache first to avoid network I/O
     * @return a possible empty list of services providing the given feature
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException 
     */
public List<DiscoverInfo> findServicesDiscoverInfo(String feature, boolean stopOnFirst, boolean useCache) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<DiscoverInfo> serviceDiscoInfo = null;
    DomainBareJid serviceName = connection().getXMPPServiceDomain();
    if (useCache) {
        serviceDiscoInfo = services.lookup(feature);
        if (serviceDiscoInfo != null) {
            return serviceDiscoInfo;
        }
    }
    serviceDiscoInfo = new LinkedList<>();
    // Send the disco packet to the server itself
    DiscoverInfo info;
    try {
        info = discoverInfo(serviceName);
    } catch (XMPPErrorException e) {
        // Be extra robust here: Return the empty linked list and log this situation
        LOGGER.log(Level.WARNING, "Could not discover information about service", e);
        return serviceDiscoInfo;
    }
    // Check if the server supports the feature
    if (info.containsFeature(feature)) {
        serviceDiscoInfo.add(info);
        if (stopOnFirst) {
            if (useCache) {
                // Cache the discovered information
                services.put(feature, serviceDiscoInfo);
            }
            return serviceDiscoInfo;
        }
    }
    DiscoverItems items;
    try {
        // Get the disco items and send the disco packet to each server item
        items = discoverItems(serviceName);
    } catch (XMPPErrorException e) {
        LOGGER.log(Level.WARNING, "Could not discover items about service", e);
        return serviceDiscoInfo;
    }
    for (DiscoverItems.Item item : items.getItems()) {
        try {
            // TODO is it OK here in all cases to query without the node attribute?
            // MultipleRecipientManager queried initially also with the node attribute, but this
            // could be simply a fault instead of intentional.
            info = discoverInfo(item.getEntityID());
        } catch (XMPPErrorException | NoResponseException e) {
            // Don't throw this exceptions if one of the server's items fail
            LOGGER.log(Level.WARNING, "Exception while discovering info for feature " + feature + " of " + item.getEntityID() + " node: " + item.getNode(), e);
            continue;
        }
        if (info.containsFeature(feature)) {
            serviceDiscoInfo.add(info);
            //serviceAddresses.add(item.getEntityID().asDomainBareJid());
            if (stopOnFirst) {
                break;
            }
        }
    }
    if (useCache) {
        // Cache the discovered information
        services.put(feature, serviceDiscoInfo);
    }
    return serviceDiscoInfo;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 5 with NoResponseException

use of org.jivesoftware.smack.SmackException.NoResponseException in project opennms by OpenNMS.

the class XMPPNotificationManager method sendGroupChat.

/**
 * send an xmpp message to a specified Chat Room.
 *
 * @param xmppChatRoom
 *            room to send message to.
 * @param xmppMessage
 *            text to be sent in the body of the message
 * @return true if message is sent, false otherwise
 */
public boolean sendGroupChat(String xmppChatRoom, String xmppMessage) {
    MultiUserChat groupChat;
    if (rooms.containsKey(xmppChatRoom)) {
        groupChat = rooms.get(xmppChatRoom);
    } else {
        LOG.debug("Adding room: {}", xmppChatRoom);
        groupChat = new MultiUserChat(xmpp, xmppChatRoom);
        rooms.put(xmppChatRoom, groupChat);
    }
    if (!groupChat.isJoined()) {
        LOG.debug("Joining room: {}", xmppChatRoom);
        try {
            groupChat.join(xmppUser);
        } catch (XMPPException | NoResponseException | NotConnectedException e) {
            LOG.error("XMPP Exception joining chat room ", e);
            return false;
        }
    }
    try {
        groupChat.sendMessage(xmppMessage);
        LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom);
    } catch (XMPPException | NotConnectedException e) {
        LOG.error("XMPP Exception sending message to Chat room", e);
        return false;
    }
    return true;
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)21 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)15 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)14 SmackException (org.jivesoftware.smack.SmackException)7 XMPPException (org.jivesoftware.smack.XMPPException)7 IOException (java.io.IOException)6 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)3 AccountManager (org.jivesoftware.smackx.iqregister.AccountManager)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 InputStream (java.io.InputStream)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 AlreadyConnectedException (org.jivesoftware.smack.SmackException.AlreadyConnectedException)2 AlreadyLoggedInException (org.jivesoftware.smack.SmackException.AlreadyLoggedInException)2 ConnectionException (org.jivesoftware.smack.SmackException.ConnectionException)2