Search in sources :

Example 1 with SSLXMPPConnection

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;
}
Also used : SSLXMPPConnection(org.jivesoftware.smack.SSLXMPPConnection) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) SSLXMPPConnection(org.jivesoftware.smack.SSLXMPPConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 SSLXMPPConnection (org.jivesoftware.smack.SSLXMPPConnection)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1