Search in sources :

Example 11 with SmackException

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

the class XMPPTCPConnection method afterFeaturesReceived.

@Override
protected void afterFeaturesReceived() throws NotConnectedException, InterruptedException {
    StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE);
    if (startTlsFeature != null) {
        if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) {
            SmackException smackException = new SecurityRequiredByServerException();
            tlsHandled.reportFailure(smackException);
            notifyConnectionError(smackException);
            return;
        }
        if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) {
            sendNonza(new StartTls());
        } else {
            tlsHandled.reportSuccess();
        }
    } else {
        tlsHandled.reportSuccess();
    }
    if (getSASLAuthentication().authenticationSuccessful()) {
        // If we have received features after the SASL has been successfully completed, then we
        // have also *maybe* received, as it is an optional feature, the compression feature
        // from the server.
        maybeCompressFeaturesReceived.reportSuccess();
    }
}
Also used : SecurityRequiredByServerException(org.jivesoftware.smack.SmackException.SecurityRequiredByServerException) SmackException(org.jivesoftware.smack.SmackException) StartTls(org.jivesoftware.smack.packet.StartTls)

Example 12 with SmackException

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

the class XMPPBOSHConnection method connectInternal.

@Override
protected void connectInternal() throws SmackException, InterruptedException {
    done = false;
    notified = false;
    try {
        // Ensure a clean starting state
        if (client != null) {
            client.close();
            client = null;
        }
        sessionID = null;
        // Initialize BOSH client
        BOSHClientConfig.Builder cfgBuilder = BOSHClientConfig.Builder.create(config.getURI(), config.getXMPPServiceDomain().toString());
        if (config.isProxyEnabled()) {
            cfgBuilder.setProxy(config.getProxyAddress(), config.getProxyPort());
        }
        client = BOSHClient.create(cfgBuilder.build());
        client.addBOSHClientConnListener(new BOSHConnectionListener());
        client.addBOSHClientResponseListener(new BOSHPacketReader());
        // Initialize the debugger
        if (config.isDebuggerEnabled()) {
            initDebugger();
            if (isFirstInitialization) {
                if (debugger.getReaderListener() != null) {
                    addAsyncStanzaListener(debugger.getReaderListener(), null);
                }
                if (debugger.getWriterListener() != null) {
                    addPacketSendingListener(debugger.getWriterListener(), null);
                }
            }
        }
        // Send the session creation request
        client.send(ComposableBody.builder().setNamespaceDefinition("xmpp", XMPP_BOSH_NS).setAttribute(BodyQName.createWithPrefix(XMPP_BOSH_NS, "version", "xmpp"), "1.0").build());
    } catch (Exception e) {
        throw new ConnectionException(e);
    }
    // Wait for the response from the server
    synchronized (this) {
        if (!connected) {
            final long deadline = System.currentTimeMillis() + getReplyTimeout();
            while (!notified) {
                final long now = System.currentTimeMillis();
                if (now >= deadline)
                    break;
                wait(deadline - now);
            }
        }
    }
    // If there is no feedback, throw an remote server timeout error
    if (!connected && !done) {
        done = true;
        String errorMessage = "Timeout reached for the connection to " + getHost() + ":" + getPort() + ".";
        throw new SmackException(errorMessage);
    }
    tlsHandled.reportSuccess();
    saslFeatureReceived.reportSuccess();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) BOSHClientConfig(org.igniterealtime.jbosh.BOSHClientConfig) SmackException(org.jivesoftware.smack.SmackException) ConnectionException(org.jivesoftware.smack.SmackException.ConnectionException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) StreamErrorException(org.jivesoftware.smack.XMPPException.StreamErrorException) BOSHException(org.igniterealtime.jbosh.BOSHException) IOException(java.io.IOException) XMPPException(org.jivesoftware.smack.XMPPException) ConnectionException(org.jivesoftware.smack.SmackException.ConnectionException)

Example 13 with SmackException

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

the class PrivacyProvider method parseItem.

// Parse the list complex type
private static PrivacyItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
    // CHECKSTYLE:ON
    // Retrieves the required attributes
    String actionValue = parser.getAttributeValue("", "action");
    // Set the order number, this attribute is required
    long order = ParserUtils.getLongAttribute(parser, "order");
    // If type is not set, then it's the fall-through case
    String type = parser.getAttributeValue("", "type");
    /* 
         * According the action value it sets the allow status. The fall-through action is assumed 
         * to be "allow"
         */
    boolean allow;
    switch(actionValue) {
        case "allow":
            allow = true;
            break;
        case "deny":
            allow = false;
            break;
        default:
            throw new SmackException("Unkown action value '" + actionValue + "'");
    }
    PrivacyItem item;
    if (type != null) {
        // If the type is not null, then we are dealing with a standard privacy item
        String value = parser.getAttributeValue("", "value");
        item = new PrivacyItem(PrivacyItem.Type.valueOf(type), value, allow, order);
    } else {
        // If the type is null, then we are dealing with the fall-through privacy item.
        item = new PrivacyItem(allow, order);
    }
    parseItemChildElements(parser, item);
    return item;
// CHECKSTYLE:OFF
}
Also used : SmackException(org.jivesoftware.smack.SmackException) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem)

Example 14 with SmackException

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

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

SmackException (org.jivesoftware.smack.SmackException)48 IOException (java.io.IOException)20 XMPPException (org.jivesoftware.smack.XMPPException)13 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)10 Test (org.junit.Test)9 Socket (java.net.Socket)8 StreamHost (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost)6 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)5 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)5 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)5 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)5 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 ConnectException (java.net.ConnectException)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4 InputStream (java.io.InputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ServerSocket (java.net.ServerSocket)3 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)3