Search in sources :

Example 16 with NoResponseException

use of org.jivesoftware.smack.SmackException.NoResponseException in project xabber-android by redsolution.

the class XMPPTCPConnection method shutdown.

private void shutdown(boolean instant) {
    if (disconnectedButResumeable) {
        return;
    }
    // the server
    if (packetWriter != null) {
        LOGGER.finer("PacketWriter shutdown()");
        packetWriter.shutdown(instant);
    }
    LOGGER.finer("PacketWriter has been shut down");
    if (!instant) {
        try {
            // After we send the closing stream element, check if there was already a
            // closing stream element sent by the server or wait with a timeout for a
            // closing stream element to be received from the server.
            @SuppressWarnings("unused") Exception res = closingStreamReceived.checkIfSuccessOrWait();
        } catch (InterruptedException | NoResponseException e) {
            LOGGER.log(Level.INFO, "Exception while waiting for closing stream element from the server " + this, e);
        }
    }
    if (packetReader != null) {
        LOGGER.finer("PacketReader shutdown()");
        packetReader.shutdown();
    }
    LOGGER.finer("PacketReader has been shut down");
    try {
        socket.close();
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "shutdown", e);
    }
    setWasAuthenticated();
    // connected (e.g. sendStanza should not throw a NotConnectedException).
    if (isSmResumptionPossible() && instant) {
        disconnectedButResumeable = true;
    } else {
        disconnectedButResumeable = false;
        // Reset the stream management session id to null, since if the stream is cleanly closed, i.e. sending a closing
        // stream tag, there is no longer a stream to resume.
        smSessionId = null;
    }
    authenticated = false;
    connected = false;
    secureSocket = null;
    reader = null;
    writer = null;
    maybeCompressFeaturesReceived.init();
    compressSyncPoint.init();
    smResumedSyncPoint.init();
    smEnabledSyncPoint.init();
    initalOpenStreamSend.init();
}
Also used : NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) FailedNonzaException(org.jivesoftware.smack.XMPPException.FailedNonzaException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException) ConnectionException(org.jivesoftware.smack.SmackException.ConnectionException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) StreamErrorException(org.jivesoftware.smack.XMPPException.StreamErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) IOException(java.io.IOException) SmackException(org.jivesoftware.smack.SmackException) StreamManagementException(org.jivesoftware.smack.sm.StreamManagementException) AlreadyLoggedInException(org.jivesoftware.smack.SmackException.AlreadyLoggedInException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) StreamIdDoesNotMatchException(org.jivesoftware.smack.sm.StreamManagementException.StreamIdDoesNotMatchException) StreamManagementNotEnabledException(org.jivesoftware.smack.sm.StreamManagementException.StreamManagementNotEnabledException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException) SecurityRequiredByServerException(org.jivesoftware.smack.SmackException.SecurityRequiredByServerException) AlreadyConnectedException(org.jivesoftware.smack.SmackException.AlreadyConnectedException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 17 with NoResponseException

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

the class Socks5BytestreamManager method determineProxies.

/**
 * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are
 * in the same order as returned by the XMPP server.
 *
 * @return list of JIDs of SOCKS5 proxies
 * @throws XMPPErrorException if there was an error querying the XMPP server for SOCKS5 proxies
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    List<Jid> proxies = new ArrayList<>();
    // get all items from XMPP server
    DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getXMPPServiceDomain());
    // query all items if they are SOCKS5 proxies
    for (Item item : discoverItems.getItems()) {
        // skip blacklisted servers
        if (this.proxyBlacklist.contains(item.getEntityID())) {
            continue;
        }
        DiscoverInfo proxyInfo;
        try {
            proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
        } catch (NoResponseException | XMPPErrorException e) {
            // blacklist errornous server
            proxyBlacklist.add(item.getEntityID());
            continue;
        }
        if (proxyInfo.hasIdentity("proxy", "bytestreams")) {
            proxies.add(item.getEntityID());
        } else {
            /*
                 * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5
                 * bytestream should be established
                 */
            this.proxyBlacklist.add(item.getEntityID());
        }
    }
    return proxies;
}
Also used : Item(org.jivesoftware.smackx.disco.packet.DiscoverItems.Item) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPConnection(org.jivesoftware.smack.XMPPConnection) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 18 with NoResponseException

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

the class EntityCapsTest method testEntityCaps.

@SmackIntegrationTest
public void testEntityCaps() throws XMPPException, InterruptedException, NoResponseException, NotConnectedException, TimeoutException {
    final String dummyFeature = getNewDummyFeature();
    dropWholeEntityCapsCache();
    performActionAndWaitUntilStanzaReceived(new Runnable() {

        @Override
        public void run() {
            sdmTwo.addFeature(dummyFeature);
        }
    }, connection, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser())));
    waitUntilTrue(new Condition() {

        @Override
        public boolean evaluate() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
            DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
            return info.containsFeature(dummyFeature);
        }
    });
    DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
    String u1ver = EntityCapsManager.getNodeVersionByJid(conTwo.getUser());
    assertNotNull(u1ver);
    DiscoverInfo entityInfo = EntityCapsManager.CAPS_CACHE.lookup(u1ver);
    assertNotNull(entityInfo);
    assertEquals(info.toXML().toString(), entityInfo.toXML().toString());
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) ThrowingRunnable(org.jivesoftware.smack.util.Async.ThrowingRunnable) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 19 with NoResponseException

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

the class XmppConnectionManager method disconnectAndCleanup.

void disconnectAndCleanup() throws InterruptedException {
    int successfullyDeletedAccountsCount = 0;
    for (AbstractXMPPConnection connection : connections.keySet()) {
        if (sinttestConfiguration.accountRegistration == AccountRegistration.inBandRegistration) {
            // Note that we use the account manager from the to-be-deleted connection.
            AccountManager accountManager = AccountManager.getInstance(connection);
            try {
                accountManager.deleteAccount();
                successfullyDeletedAccountsCount++;
            } catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
                LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
            }
        }
        connection.disconnect();
        if (sinttestConfiguration.accountRegistration == AccountRegistration.serviceAdministration) {
            String username = connection.getConfiguration().getUsername().toString();
            Localpart usernameAsLocalpart;
            try {
                usernameAsLocalpart = Localpart.from(username);
            } catch (XmppStringprepException e) {
                throw new AssertionError(e);
            }
            EntityBareJid connectionAddress = JidCreate.entityBareFrom(usernameAsLocalpart, sinttestConfiguration.service);
            try {
                adminManager.deleteUser(connectionAddress);
                successfullyDeletedAccountsCount++;
            } catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
                LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
            }
        }
    }
    if (sinttestConfiguration.isAccountRegistrationPossible()) {
        int unsuccessfullyDeletedAccountsCount = connections.size() - successfullyDeletedAccountsCount;
        if (unsuccessfullyDeletedAccountsCount == 0) {
            LOGGER.info("Successfully deleted all created accounts ✔");
        } else {
            LOGGER.warning("Could not delete all created accounts, " + unsuccessfullyDeletedAccountsCount + " remainaing");
        }
    }
    connections.clear();
    if (accountRegistrationConnection != null) {
        accountRegistrationConnection.disconnect();
    }
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Localpart(org.jxmpp.jid.parts.Localpart) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) EntityBareJid(org.jxmpp.jid.EntityBareJid) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 20 with NoResponseException

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

the class ServiceDiscoveryManager method findServicesDiscoverInfo.

/**
 * Find all services under a given service that provide a given feature.
 *
 * @param serviceName the service to query
 * @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
 * @param encounteredExceptions an optional map which will be filled with the exceptions encountered
 * @return a possible empty list of services providing the given feature
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @since 4.3.0
 */
public List<DiscoverInfo> findServicesDiscoverInfo(DomainBareJid serviceName, String feature, boolean stopOnFirst, boolean useCache, Map<? super Jid, Exception> encounteredExceptions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<DiscoverInfo> serviceDiscoInfo;
    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) {
        if (encounteredExceptions != null) {
            encounteredExceptions.put(serviceName, 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) {
        if (encounteredExceptions != null) {
            encounteredExceptions.put(serviceName, e);
        }
        return serviceDiscoInfo;
    }
    for (DiscoverItems.Item item : items.getItems()) {
        Jid address = item.getEntityID();
        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(address);
        } catch (XMPPErrorException | NoResponseException e) {
            if (encounteredExceptions != null) {
                encounteredExceptions.put(address, e);
            }
            continue;
        }
        if (info.containsFeature(feature)) {
            serviceDiscoInfo.add(info);
            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) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException)

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