Annotation 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:
Web2SocketExchange
which is the WebSocket exchange to handleWeb2SocketExchange.Inbound
which is the WebSocket inboundWeb2SocketExchange.Outbound
which is the WebSocket outbound- Any publisher (i.e.
Publisher
,Flux
orMono
) ofByteBuf
,String
orT
as WebSocket inbound.
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
Modifier and TypeOptional ElementDescriptionString[]
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.String[]
The path that the absolute path of a request must match to be served by the route.String[]
The list of WebSocket subprotocols supported by the WebSocket route.
-
Element Details
-
path
String[] pathThe 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 matchTrailingSlashIndicates 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[] languageThe 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[] subprotocolThe list of WebSocket subprotocols supported by the WebSocket route.
- Returns:
- an array of subprotocols
- Default:
{}
-
messageType
WebSocketMessage.Kind messageTypeThe 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
-