use of org.jivesoftware.smack.SSLXMPPConnection in project cayenne by apache.
the class XMPPBridge method startupExternal.
@Override
protected void startupExternal() throws Exception {
// validate settings
if (xmppHost == null) {
throw new CayenneRuntimeException("Null 'xmppHost', can't start XMPPBridge");
}
// shutdown old bridge
if (connected) {
shutdownExternal();
}
try {
// connect and log in to chat
if (secureConnection) {
int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_SECURE_PORT;
this.connection = new SSLXMPPConnection(xmppHost, port);
} else {
int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_PORT;
this.connection = new XMPPConnection(xmppHost, port);
}
if (loginId != null) {
// it is important to provide a (pseudo) globally unique string as the
// third argument ("sessionHandle" is such string); without it same
// loginId can not be reused from the same machine.
connection.login(loginId, password, sessionHandle);
} else {
connection.loginAnonymously();
}
} catch (XMPPException e) {
throw new CayenneRuntimeException("Error connecting to XMPP Server: %s", e.getLocalizedMessage());
}
String service = chatService != null ? chatService : DEFAULT_CHAT_SERVICE;
try {
groupChat = connection.createGroupChat(externalSubject + '@' + service + "." + connection.getHost());
groupChat.join(sessionHandle);
groupChat.addMessageListener(new XMPPListener());
} catch (XMPPException e) {
throw new CayenneRuntimeException("Error setting up a group chat: %s", e.getLocalizedMessage());
}
this.connected = true;
}
Aggregations