Annotation Interface WebSocketRoute


@Documented @Retention(SOURCE) @Target(METHOD) @Inherited public @interface WebSocketRoute

Specifies a WebSocket route in a web controller.

A WebSocket route is an annotated method in a web controller which basically implement the WebSocket exchange handler logic. It accepts any combination of the following parameters:

The method's return type can also be used to specify the WebSocket outbound as a publisher of ByteBuf, String or T, in which case it is not possible to specify it as a method parameter.

When an inbound or outbound publisher is specified with T other than ByteBuf or String, WebSocket messages are automcatically decoded or encoded using the MediaTypeConverter corresponding to the negotiated subprotocol as defined by Web2SocketExchange.

A simple Websocket route can be defined as follows in a web controller bean:


 @WebController( path = "/chat" )
 @Bean
 public class ChatController {
 
     @WebRoute( path = "ws", subprotocol = json" )
     public Flux<Message> chatWebSocket(Flux<Message> inbound) {
         ...
     }
 }
 
Since:
1.5
Author:
Jeremy Kuhn
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The list of languages that a request must match (i.e. accept at least one of them) to be served by the route.
    boolean
    Indicates whether trailing slash in the request path should be matched by the route.
    The type of WebSocket messages consumed and produced by the WebSocket route.
    The path that the absolute path of a request must match to be served by the route.
    The list of WebSocket subprotocols supported by the WebSocket route.
  • Element Details

    • path

      String[] path

      The path that the absolute path of a request must match to be served by the route.

      A path can be a parameterized path parameters as defined by URIBuilder.

      Note that this path will be normalized in the resulting route.

      Returns:
      an array of path
      Default:
      {}
    • matchTrailingSlash

      boolean matchTrailingSlash

      Indicates whether trailing slash in the request path should be matched by the route.

      When activated, the route matches a path regardless of whether it ends with a slash as long as the path matches one of the paths specified in the route with or without trailing slash.

      Returns:
      true to match path with or without trailing slash, false otherwise
      Default:
      false
    • language

      String[] language

      The list of languages that a request must match (i.e. accept at least one of them) to be served by the route.

      Returns:
      an array of language tags
      Default:
      {}
    • subprotocol

      String[] subprotocol

      The list of WebSocket subprotocols supported by the WebSocket route.

      Returns:
      an array of subprotocols
      Default:
      {}
    • messageType

      The type of WebSocket messages consumed and produced by the WebSocket route.

      This is only relevant when the route is defined with inbound and outbound publishers otherwise the message type shall be determined in the WebSocket route handler.

      Returns:
      a WebSocket message type
      Default:
      TEXT