Package io.toro.martini
Class WebSocketMethods
- java.lang.Object
-
- io.toro.martini.WebSocketMethods
-
public final class WebSocketMethods extends Object
A utility class for WebSocket-related operations, with one-liners that make it easy to send WebSocket messages.
WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.
-
-
Constructor Summary
Constructors Constructor Description WebSocketMethods(SimpMessageSendingOperations messaging)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
sendWSMessage(String destination, Object message)
Send a WebSocket message.static void
sendWSMessage(String destination, Object payload, Map<String,Object> headers)
Send a WebSocket message.static void
sendWSMessage(String destination, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor)
Send a WebSocket message.static void
sendWSMessage(String destination, Object payload, MessagePostProcessor postProcessor)
Send a WebSocket message.static void
sendWSMessage(String destination, String user, Object payload)
Send a WebSocket message.static void
sendWSMessage(String destination, String user, Object payload, Map<String,Object> headers)
Send a WebSocket message.static void
sendWSMessage(String destination, String user, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor)
Send a WebSocket message.static void
sendWSMessage(String destination, String user, Object payload, MessagePostProcessor postProcessor)
Send a WebSocket message.static void
sendWSMessage(String destination, Message<?> message)
Send a WebSocket message.
-
-
-
Constructor Detail
-
WebSocketMethods
@Autowired WebSocketMethods(SimpMessageSendingOperations messaging)
-
-
Method Detail
-
sendWSMessage
public static void sendWSMessage(String destination, Object message)
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' destination.sendWSMessage( 'Hello, world' )
- Parameters:
destination
- where the message will be sentmessage
- message to be sent- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, Object payload, Map<String,Object> headers) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] destination.sendWSMessage( 'Hello, world' , headers )
- Parameters:
destination
- where the message will be sentpayload
- message to be sentheaders
- headers to include in the request- Throws:
MessagingException
- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, Message<?> message) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' Message message = new Message(); destination.sendWSMessage( message, headers )
- Parameters:
destination
- where the message will be sentmessage
- message to be sent- Throws:
MessagingException
- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, Object payload, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' MessageProcessor processor = { message -> 'Hello, world' return message } destination.sendWSMessage( payload, processor )
- Parameters:
destination
- where the message will be sentpayload
- message to be sentpostProcessor
- processes a message after creation; returning the old, new, or modified message- Throws:
MessagingException
- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] MessageProcessor processor = { message -> 'Hello, world' return message } destination.sendWSMessage( payload, headers, processor )
- Parameters:
destination
- where the message will be sentpayload
- message to be sentheaders
- headers to include in the requestpostProcessor
- processes a message after creation; returning the old, new, or modified message- Throws:
MessagingException
- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, String user, Object payload) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' destination.sendWSMessage( 'john', 'Hello, world' )
- Parameters:
destination
- where the message will be sentpayload
- message to be sentuser
- the recipient of the message- Throws:
MessagingException
- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, String user, Object payload, Map<String,Object> headers) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] destination.sendWSMessage( 'john', 'Hello, world', headers )
- Parameters:
destination
- where the message will be sentpayload
- message to be sentuser
- the recipient of the message- Throws:
MessagingException
- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, String user, Object payload, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' MessageProcessor processor = { message -> 'Hello, world' return message } destination.sendWSMessage( 'jane', payload , processor )
- Parameters:
destination
- where the message will be sentuser
- the recipient of the messagepayload
- message to be sentpostProcessor
- processes a message after creation; returning the old, new, or modified message- Throws:
MessagingException
- Since:
- 1.0
-
sendWSMessage
public static void sendWSMessage(String destination, String user, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] MessageProcessor processor = { message -> 'This is a sample message' return message } destination.sendWSMessage( 'john', payload , headers, processor )
- Parameters:
destination
- where the message will be sentuser
- the recipient of the messagepayload
- message to be sentheaders
- headers to include in the requestpostProcessor
- processes a message after creation; returning the old, new, or modified message- Throws:
MessagingException
- Since:
- 1.0
-
-