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);
}
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());
}
}
Aggregations