Search in sources :

Example 6 with ConnectionConfiguration

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

the class SmackTestCase method createConnection.

/**
     * Creates a new XMPPTCPConnection using the connection preferences. This is useful when
     * not using a connection from the connection pool in a test case.
     *
     * @return a new XMPP connection.
     */
protected XMPPTCPConnection createConnection() {
    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(host, port);
    config.setCompressionEnabled(compressionEnabled);
    config.setSendPresence(sendInitialPresence());
    if (getSocketFactory() == null) {
        config.setSocketFactory(getSocketFactory());
    }
    return new XMPPTCPConnection(config);
}
Also used : ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration)

Example 7 with ConnectionConfiguration

use of org.jivesoftware.smack.ConnectionConfiguration in project openhab1-addons by openhab.

the class XMPPConnect method establishConnection.

private static void establishConnection() {
    if (servername == null) {
        return;
    }
    ConnectionConfiguration config;
    // Create a connection to the jabber server on the given port
    if (proxy != null) {
        config = new ConnectionConfiguration(servername, port, proxy);
    } else {
        config = new ConnectionConfiguration(servername, port);
    }
    config.setSecurityMode(securityMode);
    if (tlsPin != null) {
        try {
            SSLContext sc = JavaPinning.forPin(tlsPin);
            config.setCustomSSLContext(sc);
        } catch (KeyManagementException | NoSuchAlgorithmException e) {
            logger.error("Could not create TLS Pin for XMPP connection", e);
        }
    }
    if (connection != null && connection.isConnected()) {
        try {
            connection.disconnect();
        } catch (NotConnectedException e) {
            logger.debug("Already disconnected", e);
        }
    }
    connection = new XMPPTCPConnection(config);
    try {
        connection.connect();
        connection.login(username, password, null);
        if (consoleUsers.length > 0) {
            ChatManager.getInstanceFor(connection).addChatListener(new XMPPConsole(consoleUsers));
            connection.addConnectionListener(new XMPPConnectionListener());
        }
        logger.info("Connection to XMPP as '{}' has been established. Is secure/encrypted: {}", connection.getUser(), connection.isSecureConnection());
        initialized = true;
    } catch (Exception e) {
        logger.error("Could not establish connection to XMPP server '" + servername + ":" + port + "': {}", e.getMessage());
    }
}
Also used : ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) SmackException(org.jivesoftware.smack.SmackException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) KeyManagementException(java.security.KeyManagementException) ConfigurationException(org.osgi.service.cm.ConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

ConnectionConfiguration (org.jivesoftware.smack.ConnectionConfiguration)7 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 XMPPException (org.jivesoftware.smack.XMPPException)3 Message (org.jivesoftware.smack.packet.Message)2 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)2 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 PerunNotifMessageDto (cz.metacentrum.perun.notif.dto.PerunNotifMessageDto)1 PoolMessage (cz.metacentrum.perun.notif.dto.PoolMessage)1 PerunNotifReceiver (cz.metacentrum.perun.notif.entities.PerunNotifReceiver)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SSLContext (javax.net.ssl.SSLContext)1 PacketCollector (org.jivesoftware.smack.PacketCollector)1 SmackException (org.jivesoftware.smack.SmackException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)1 IQ (org.jivesoftware.smack.packet.IQ)1 Packet (org.jivesoftware.smack.packet.Packet)1 Presence (org.jivesoftware.smack.packet.Presence)1