Class XmppMethods


  • public final class XmppMethods
    extends Object
    Provides utility methods for easily creating, sending, and receiving instant messages from Xmpp endpoints. Xmpp an open technology for instant messaging and presence.
    • Constructor Detail

      • XmppMethods

        @Autowired
        XmppMethods​(io.toro.martini.jabber.JabberConnectionManager esbJabberConnectionManager)
    • Method Detail

      • sendMessage

        public static void sendMessage​(String endpointName,
                                       String jid,
                                       String message)
                                throws ToroException

        Send a message to a user. This will reuse the Xmpp connection created by the endpoint. This one-liner requires the endpoint to be started.

        Example usage:

         'endpoint'.sendMessage( 'user@your.org', 'Hello, earthling!' )
         

        Parameters:
        endpointName - the name of the endpoint belonging to the current package
        message - the message to send
        jid - the Jabber ID of the recipient
        Throws:
        ToroException
        Since:
        1.0
      • xmppChat

        public static void xmppChat​(String endpointName,
                                    String jid,
                                    Closure closure)
                             throws ToroException

        Invoke a closure which can operate on a provided Chat object. The Chat object is constructed based on the provided JID, and the Xmpp connection created by the endpoint. This one-liner requires the endpoint to be started.

        Example usage:

         'endpoint'.xmppChat('user@your.org') {
             chat -> chat.sendMessage('Hello, earthling!')
         }
         

        Parameters:
        endpointName - the name of the endpoint belonging to the current package
        jid - the Jabber ID of the user
        closure - the closure to invoke
        Throws:
        ToroException
        Since:
        1.0
      • sendGroupMessage

        public static void sendGroupMessage​(String endpointName,
                                            String nickname,
                                            String roomJID,
                                            boolean leaveOnFinish,
                                            String message)
                                     throws ToroException

        Send a message to a chat room. This will reuse the Xmpp connection created by the endpoint. This one-liner requires the endpoint to be started.

        Example usage:

         'endpoint'.sendGroupMessage( 'NotAnAlien' , 'room@your.org' , true, 'Hello, earthlings!' )
         

        Parameters:
        endpointName - the name of the endpoint belonging to the current package
        nickname - the name to use in the chat room
        roomJID - the Jabber ID of the chat room
        leaveOnFinish - determines whether or not to leave the chat room after message delivery
        message - the message to send
        Throws:
        ToroException
        Since:
        1.0
      • sendGroupMessage

        public static void sendGroupMessage​(String endpointName,
                                            String nickname,
                                            String password,
                                            String roomJID,
                                            boolean leaveOnFinish,
                                            String message)
                                     throws ToroException

        Send a message to a chatroom. This will reuse the Xmpp connection created by the endpoint. This one-liner requires the endpoint to be started.

        Example usage:

         'endpoint'.sendGroupMessage( 'NotAnAlien', 'room@your.org' , true, 'I can speak English.' )
         

        Parameters:
        endpointName - the name of the endpoint belonging to the current package
        nickname - the name to use in the chat room
        password - the password of the chat room
        roomJID - the Jabber ID of the chat room
        leaveOnFinish - determines whether or not to leave the chat room after message delivery
        message - the message to send
        Throws:
        ToroException
        Since:
        1.0
      • xmppGroupchat

        public static void xmppGroupchat​(String endpointName,
                                         String roomJID,
                                         Closure closure)
                                  throws ToroException

        Invoke a closure which can operate on a provided MultiUserChat object. The MultiUserChat object is constructed based on the provided JID, and the Xmpp connection created by the endpoint. This one-liner requires the endpoint to be started.

        Example usage:

         'endpoint'.xmppGroupchat( 'room@your.org' ) {
             chat -> chat.sendMessage( 'But can you do this?' )
         }
         

        Parameters:
        endpointName - the name of the endpoint belonging to the current package
        roomJID - the Jabber ID of the chat room
        closure - the closure to invoke
        Throws:
        ToroException
        Since:
        1.0
      • xmpp

        public static void xmpp​(String endpointName,
                                Closure closure)
                         throws ToroException

        Invoke a closure which can operate on a provided JabberConnection object. The JabberConnection object is obtained from the named endpoint. This one-liner requires the endpoint to be started.

        The closure must avoid disconnecting the connection. To properly disconnect the connection, stop the endpoint instead. If the connection is closed, this one-liner will attempt to reconnect the connection.

        Example usage:

         'endpoint'.xmpp() {
             connection -> connection.sendMessage( 'alien@not.earth', 'Why are you green?' )
         }
         

        Parameters:
        endpointName - the name of the endpoint belonging to the current package
        closure - the closure to execute
        Throws:
        ToroException
        Since:
        1.0
      • createXmppConnection

        public static XmppConnection createXmppConnection​(String name,
                                                          Map configuration,
                                                          Closure closure)
                                                   throws ToroException

        Create a Xmpp connection using the provided configuration.

        Example usage:

         def configuration = [ serviceName: 'service' , username: 'user@your.org', password: 'superS3CR3Tpa$$word' ]
         'connection'.createXmppConnection( configuration ) {
             connection -> println "${connection.getName()}"
         }
         

        Parameters:
        name - the name of the connection to be created
        configuration - configuration for the Xmpp connection
        closure - optional closure for executing more actions against the Xmpp connection (eg. send a message)
        Returns:
        the Xmpp connection created from the configuration
        Throws:
        ToroException
        Since:
        1.0
        See Also:
        JabberConnection.buildConfiguration(Map)
      • createXmppConnection

        public static XmppConnection createXmppConnection​(String name,
                                                          Map configuration)
                                                   throws ToroException

        Create a Xmpp connection using the provided configuration.

        Example usage:

         def configuration = [ serviceName: 'service' , username: 'user@your.org', password: 'superS3CR3Tpa$$word']
         def connection = 'connection'.createXmppConnection( configuration )
         
        Parameters:
        name - the name of the connection to be created
        configuration - configuration for the Xmpp connection
        Returns:
        the Xmpp connection created from the configuration
        Throws:
        ToroException
        Since:
        1.0
        See Also:
        JabberConnection.buildConfiguration(Map)