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:
Web2SocketExchangewhich is the WebSocket exchange to handleBaseWeb2SocketExchange.Inboundwhich is the WebSocket inboundBaseWeb2SocketExchange.Outboundwhich is the WebSocket outbound- Any publisher (i.e.
Flow.Publisher,FluxorMono) ofByteBuf,StringorTas 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
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanSpecifies whether the WebSocket exchange should be closed when the outbound frames publisher completes successfully.String[]The list of languages that a request must match (i.e. accept at least one of them) to be served by the route.booleanIndicates 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
-
closeOnComplete
boolean closeOnCompleteSpecifies whether the WebSocket exchange should be closed when the outbound frames publisher completes successfully.
- Returns:
- true to close the WebSocket exchange when the outbound frames publisher completes, false otherwise
- See Also:
- Default:
true
-