Class 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.

    • 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 sent
        message - 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 sent
        payload - message to be sent
        headers - 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 sent
        message - 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 sent
        payload - message to be sent
        postProcessor - 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 sent
        payload - message to be sent
        headers - headers to include in the request
        postProcessor - 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 sent
        payload - message to be sent
        user - 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 sent
        payload - message to be sent
        user - 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 sent
        user - the recipient of the message
        payload - message to be sent
        postProcessor - 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 sent
        user - the recipient of the message
        payload - message to be sent
        headers - headers to include in the request
        postProcessor - processes a message after creation; returning the old, new, or modified message
        Throws:
        MessagingException
        Since:
        1.0