public class RxNettyWebSocketClient extends WebSocketClientSupport implements WebSocketClient
WebSocketClient
implementation for use with RxNetty.
Note: RxNetty HttpClient
instances require a host
and port in order to be created. Hence it is not possible to configure a
single HttpClient
instance to use upfront. Instead the constructors
accept a function for obtaining client instances when establishing a
connection to a specific URI. By default new instances are created per
connection with a shared Netty EventLoopGroup
. See constructors for
more details.
Modifier and Type | Field and Description |
---|---|
private java.util.function.Function<java.net.URI,<any>> |
httpClientProvider |
logger
Constructor and Description |
---|
RxNettyWebSocketClient()
Default constructor that creates
HttpClient instances via
HttpClient#newClient(String, int) using port 80 or 443 depending
on the target URL scheme. |
RxNettyWebSocketClient(java.util.function.Function<java.net.URI,<any>> httpClientProvider)
Constructor with a function to use to obtain
HttpClient instances. |
Modifier and Type | Method and Description |
---|---|
private <any> |
createRequest(java.net.URI url,
HttpHeaders headers,
java.lang.String[] protocols) |
<any> |
execute(java.net.URI url,
HttpHeaders headers,
WebSocketHandler handler)
A variant of
WebSocketClient.execute(URI, WebSocketHandler) with custom headers. |
<any> |
execute(java.net.URI url,
WebSocketHandler handler)
Execute a handshake request to the given url and handle the resulting
WebSocket session with the given handler.
|
private <any> |
executeInternal(java.net.URI url,
HttpHeaders headers,
WebSocketHandler handler) |
private static <any> |
getDefaultHttpClientProvider(java.net.URI url) |
<any> |
getHttpClient(java.net.URI url)
Return an
HttpClient instance to use to connect to the given URI. |
java.util.function.Function<java.net.URI,<any>> |
getHttpClientProvider()
Return the configured
HttpClient provider depending on which
constructor was used. |
private HttpHeaders |
toHttpHeaders(<any> response) |
afterHandshake, beforeHandshake
private final java.util.function.Function<java.net.URI,<any>> httpClientProvider
public RxNettyWebSocketClient()
HttpClient
instances via
HttpClient#newClient(String, int)
using port 80 or 443 depending
on the target URL scheme.
Note: By default a new HttpClient
instance
is created per WebSocket connection. Those instances will share a global
EventLoopGroup
that RxNetty obtains via
RxEventLoopProvider#globalClientEventLoop(boolean)
.
public RxNettyWebSocketClient(java.util.function.Function<java.net.URI,<any>> httpClientProvider)
HttpClient
instances.private static <any> getDefaultHttpClientProvider(java.net.URI url)
public java.util.function.Function<java.net.URI,<any>> getHttpClientProvider()
HttpClient
provider depending on which
constructor was used.public <any> getHttpClient(java.net.URI url)
HttpClient
instance to use to connect to the given URI.
The default implementation invokes the getHttpClientProvider()
provider} function created or supplied at construction time.url
- the full URL of the WebSocket endpoint.public <any> execute(java.net.URI url, WebSocketHandler handler)
WebSocketClient
execute
in interface WebSocketClient
url
- the handshake urlhandler
- the handler of the WebSocket sessionMono<Void>
to indicate the outcome of the
WebSocket session handling.public <any> execute(java.net.URI url, HttpHeaders headers, WebSocketHandler handler)
WebSocketClient
WebSocketClient.execute(URI, WebSocketHandler)
with custom headers.execute
in interface WebSocketClient
url
- the handshake urlheaders
- custom headers for the handshake requesthandler
- the handler of the WebSocket sessionMono<Void>
to indicate the outcome of the
WebSocket session handling.private <any> executeInternal(java.net.URI url, HttpHeaders headers, WebSocketHandler handler)
private <any> createRequest(java.net.URI url, HttpHeaders headers, java.lang.String[] protocols)
private HttpHeaders toHttpHeaders(<any> response)