Class XmppMethods
- java.lang.Object
-
- io.toro.martini.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 Summary
Constructors Constructor Description XmppMethods(io.toro.martini.jabber.JabberConnectionManager esbJabberConnectionManager)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XmppConnectioncreateXmppConnection(String name, Map configuration)Create a Xmpp connection using the provided configuration.static XmppConnectioncreateXmppConnection(String name, Map configuration, Closure closure)Create a Xmpp connection using the provided configuration.static voidsendGroupMessage(String endpointName, String nickname, String roomJID, boolean leaveOnFinish, String message)Send a message to a chat room.static voidsendGroupMessage(String endpointName, String nickname, String password, String roomJID, boolean leaveOnFinish, String message)Send a message to a chatroom.static voidsendMessage(String endpointName, String jid, String message)Send a message to a user.static voidxmpp(String endpointName, Closure closure)Invoke a closure which can operate on a providedJabberConnectionobject.static voidxmppChat(String endpointName, String jid, Closure closure)Invoke a closure which can operate on a providedChatobject.static voidxmppGroupchat(String endpointName, String roomJID, Closure closure)Invoke a closure which can operate on a providedMultiUserChatobject.
-
-
-
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 packagemessage- the message to sendjid- 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
Chatobject. TheChatobject 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 packagejid- the Jabber ID of the userclosure- 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 packagenickname- the name to use in the chat roomroomJID- the Jabber ID of the chat roomleaveOnFinish- determines whether or not to leave the chat room after message deliverymessage- 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 packagenickname- the name to use in the chat roompassword- the password of the chat roomroomJID- the Jabber ID of the chat roomleaveOnFinish- determines whether or not to leave the chat room after message deliverymessage- 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
MultiUserChatobject. TheMultiUserChatobject 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 packageroomJID- the Jabber ID of the chat roomclosure- 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
JabberConnectionobject. TheJabberConnectionobject 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 packageclosure- 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 createdconfiguration- configuration for the Xmpp connectionclosure- 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 createdconfiguration- configuration for the Xmpp connection- Returns:
- the Xmpp connection created from the configuration
- Throws:
ToroException- Since:
- 1.0
- See Also:
JabberConnection.buildConfiguration(Map)
-
-