public class ServerWebSocketWrapper extends Object implements ServerWebSocket
| Constructor and Description |
|---|
ServerWebSocketWrapper(ServerWebSocket delegate,
String host,
String scheme,
boolean isSsl,
SocketAddress remoteAddress) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept()
Accept the WebSocket and terminate the WebSocket handshake.
|
String |
binaryHandlerID()
When a
WebSocket is created it automatically registers an event handler with the event bus - the ID of that
handler is given by this method. |
WebSocketBase |
binaryMessageHandler(Handler<Buffer> handler)
Set a binary message handler on the connection.
|
Future<Void> |
close()
Close the WebSocket sending the default close frame.
|
void |
close(Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.close() but with an handler called when the operation completes |
Future<Void> |
close(short statusCode)
Close the WebSocket sending a close frame with specified status code.
|
void |
close(short statusCode,
Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.close(short) but with an handler called when the operation completes |
Future<Void> |
close(short statusCode,
String reason)
Close sending a close frame with specified status code and reason.
|
void |
close(short statusCode,
String reason,
Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.close(short, String) but with an handler called when the operation completes |
ServerWebSocket |
closeHandler(Handler<Void> handler)
Set a close handler.
|
String |
closeReason()
Returns the close reason message from the remote endpoint or
null when not yet received. |
Short |
closeStatusCode()
Returns the close status code received from the remote endpoint or
null when not yet received. |
ServerWebSocket |
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.
|
Future<Void> |
end()
Ends the stream.
|
void |
end(Handler<AsyncResult<Void>> handler)
Same as
WriteStream.end() but with an handler called when the operation completes |
ServerWebSocket |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
ServerWebSocket |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
ServerWebSocket |
fetch(long amount)
Fetch the specified
amount of elements. |
ServerWebSocket |
frameHandler(Handler<WebSocketFrame> handler)
Set a frame handler on the connection.
|
ServerWebSocket |
handler(Handler<Buffer> handler)
Set a data handler.
|
MultiMap |
headers()
Returns the HTTP headers when the WebSocket is first obtained in the handler.
|
String |
host() |
boolean |
isClosed() |
boolean |
isSsl() |
SocketAddress |
localAddress() |
String |
path() |
ServerWebSocket |
pause()
Pause the
ReadStream, it sets the buffer in fetch mode and clears the actual demand. |
X509Certificate[] |
peerCertificateChain()
Note: Java SE 5+ recommends to use javax.net.ssl.SSLSession#getPeerCertificates() instead of
of javax.net.ssl.SSLSession#getPeerCertificateChain() which this method is based on.
|
WebSocketBase |
pongHandler(Handler<Buffer> handler)
Set a pong frame handler on the connection.
|
String |
query() |
void |
reject()
Reject the WebSocket.
|
void |
reject(int status)
Like
ServerWebSocket.reject() but with a status. |
SocketAddress |
remoteAddress() |
ServerWebSocket |
resume()
Resume reading, and sets the buffer in
flowing mode. |
String |
scheme() |
Future<Integer> |
setHandshake(Future<Integer> future)
Like
ServerWebSocket.setHandshake(Future, Handler) but returns a Future of the asynchronous result |
void |
setHandshake(Future<Integer> future,
Handler<AsyncResult<Integer>> handler)
Set an asynchronous result for the handshake, upon completion of the specified
future, the
WebSocket will either be
accepted when the future succeeds with the HTTP 101 status code
rejected when the future is succeeds with an HTTP status code different than 101
rejected when the future fails with the HTTP status code 500
The provided future might be completed by the WebSocket itself, e.g calling the ServerWebSocket.close() method
will try to accept the handshake and close the WebSocket afterward. |
ServerWebSocket |
setWriteQueueMaxSize(int maxSize)
Set the maximum size of the write queue to
maxSize. |
SSLSession |
sslSession() |
String |
subProtocol()
Returns the WebSocket sub protocol selected by the WebSocket handshake.
|
String |
textHandlerID()
When a
WebSocket is created it automatically registers an event handler with the eventbus, the ID of that
handler is given by textHandlerID. |
WebSocketBase |
textMessageHandler(Handler<String> handler)
Set a text message handler on the connection.
|
String |
uri() |
Future<Void> |
write(Buffer data)
Write some data to the stream.
|
void |
write(Buffer data,
Handler<AsyncResult<Void>> handler)
Same as
#write(T) but with an handler called when the operation completes |
Future<Void> |
writeBinaryMessage(Buffer data)
Writes a (potentially large) piece of binary data to the connection.
|
ServerWebSocket |
writeBinaryMessage(Buffer data,
Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.writeBinaryMessage(Buffer) but with an handler called when the operation completes |
Future<Void> |
writeFinalBinaryFrame(Buffer data)
Write a final WebSocket binary frame to the connection
|
ServerWebSocket |
writeFinalBinaryFrame(Buffer data,
Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.writeFinalBinaryFrame(Buffer, Handler) but with an handler called when the operation completes |
Future<Void> |
writeFinalTextFrame(String text)
Write a final WebSocket text frame to the connection
|
ServerWebSocket |
writeFinalTextFrame(String text,
Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.writeFinalTextFrame(String, Handler) but with an handler called when the operation completes |
Future<Void> |
writeFrame(WebSocketFrame frame)
Write a WebSocket frame to the connection
|
ServerWebSocket |
writeFrame(WebSocketFrame frame,
Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.writeFrame(WebSocketFrame) but with an handler called when the operation completes |
Future<Void> |
writePing(Buffer data)
Like
WebSocketBase.writePing(Buffer, Handler) but with an handler called when the message has been written
or failed to be written. |
WebSocketBase |
writePing(Buffer data,
Handler<AsyncResult<Void>> handler)
Writes a ping frame to the connection.
|
Future<Void> |
writePong(Buffer data)
Like
WebSocketBase.writePong(Buffer, Handler) but with an handler called when the message has been written
or failed to be written. |
WebSocketBase |
writePong(Buffer data,
Handler<AsyncResult<Void>> handler)
Writes a pong frame to the connection.
|
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int) |
Future<Void> |
writeTextMessage(String text)
Writes a (potentially large) piece of text data to the connection.
|
ServerWebSocket |
writeTextMessage(String text,
Handler<AsyncResult<Void>> handler)
Same as
WebSocketBase.writeTextMessage(String) but with an handler called when the operation completes |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpipe, pipeTo, pipeToend, endpublic ServerWebSocketWrapper(ServerWebSocket delegate, String host, String scheme, boolean isSsl, SocketAddress remoteAddress)
public ServerWebSocket exceptionHandler(Handler<Throwable> handler)
ReadStreamexceptionHandler in interface ServerWebSocketexceptionHandler in interface WebSocketBaseexceptionHandler in interface ReadStream<Buffer>exceptionHandler in interface StreamBaseexceptionHandler in interface WriteStream<Buffer>handler - the exception handlerpublic Future<Void> write(Buffer data)
WriteStream The data is usually put on an internal write queue, and the write actually happens
asynchronously. To avoid running out of memory by putting too much on the write queue,
check the WriteStream.writeQueueFull() method before writing. This is done automatically if
using a Pipe.
When the data is moved from the queue to the actual medium, the returned
Future will be completed with the write result, e.g the future is succeeded
when a server HTTP response buffer is written to the socket and failed if the remote
client has closed the socket while the data was still pending for write.
write in interface WriteStream<Buffer>data - the data to writepublic void write(Buffer data, Handler<AsyncResult<Void>> handler)
WriteStream#write(T) but with an handler called when the operation completeswrite in interface WriteStream<Buffer>public ServerWebSocket handler(Handler<Buffer> handler)
ReadStreamhandler in interface ServerWebSockethandler in interface WebSocketBasehandler in interface ReadStream<Buffer>public ServerWebSocket pause()
ReadStreamReadStream, it sets the buffer in fetch mode and clears the actual demand.
While it's paused, no data will be sent to the data handler.
pause in interface ServerWebSocketpause in interface WebSocketBasepause in interface ReadStream<Buffer>public ServerWebSocket resume()
ReadStreamflowing mode.
If the ReadStream has been paused, reading will recommence on it.resume in interface ServerWebSocketresume in interface WebSocketBaseresume in interface ReadStream<Buffer>public ServerWebSocket fetch(long amount)
ReadStreamamount of elements. If the ReadStream has been paused, reading will
recommence with the specified amount of items, otherwise the specified amount will
be added to the current stream demand.fetch in interface ServerWebSocketfetch in interface WebSocketBasefetch in interface ReadStream<Buffer>public ServerWebSocket endHandler(Handler<Void> endHandler)
ReadStreamendHandler in interface ServerWebSocketendHandler in interface WebSocketBaseendHandler in interface ReadStream<Buffer>public ServerWebSocket setWriteQueueMaxSize(int maxSize)
WriteStreammaxSize. You will still be able to write to the stream even
if there is more than maxSize items in the write queue. This is used as an indicator by classes such as
Pipe to provide flow control.
The value is defined by the implementation of the stream, e.g in bytes for a
NetSocket, etc...setWriteQueueMaxSize in interface ServerWebSocketsetWriteQueueMaxSize in interface WebSocketBasesetWriteQueueMaxSize in interface WriteStream<Buffer>maxSize - the max size of the write streampublic boolean writeQueueFull()
WriteStreamtrue if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int)writeQueueFull in interface WriteStream<Buffer>true if write queue is fullpublic ServerWebSocket drainHandler(Handler<Void> handler)
WriteStreamPipe for an example of this being used.
The stream implementation defines when the drain handler, for example it could be when the queue size has been
reduced to maxSize / 2.
drainHandler in interface ServerWebSocketdrainHandler in interface WebSocketBasedrainHandler in interface WriteStream<Buffer>handler - the handlerpublic String binaryHandlerID()
WebSocketBaseWebSocket is created it automatically registers an event handler with the event bus - the ID of that
handler is given by this method.
Given this ID, a different event loop can send a binary frame to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other WebSockets which are owned by different event loops.
binaryHandlerID in interface WebSocketBasepublic String textHandlerID()
WebSocketBaseWebSocket is created it automatically registers an event handler with the eventbus, the ID of that
handler is given by textHandlerID.
Given this ID, a different event loop can send a text frame to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other WebSockets which are owned by different event loops.
textHandlerID in interface WebSocketBasepublic String subProtocol()
WebSocketBasenull when the handler receives the WebSocket callback as the
handshake will not be completed yet.subProtocol in interface WebSocketBasepublic Short closeStatusCode()
WebSocketBasenull when not yet received.closeStatusCode in interface WebSocketBasepublic String closeReason()
WebSocketBasenull when not yet received.closeReason in interface WebSocketBasepublic MultiMap headers()
WebSocketBasenull on subsequent interactions.headers in interface WebSocketBasepublic Future<Void> writeFrame(WebSocketFrame frame)
WebSocketBasewriteFrame in interface WebSocketBaseframe - the frame to writepublic ServerWebSocket writeFrame(WebSocketFrame frame, Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.writeFrame(WebSocketFrame) but with an handler called when the operation completeswriteFrame in interface ServerWebSocketwriteFrame in interface WebSocketBasepublic Future<Void> writeFinalTextFrame(String text)
WebSocketBasewriteFinalTextFrame in interface WebSocketBasetext - The text to writepublic ServerWebSocket writeFinalTextFrame(String text, Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.writeFinalTextFrame(String, Handler) but with an handler called when the operation completeswriteFinalTextFrame in interface ServerWebSocketwriteFinalTextFrame in interface WebSocketBasepublic Future<Void> writeFinalBinaryFrame(Buffer data)
WebSocketBasewriteFinalBinaryFrame in interface WebSocketBasedata - The data to writepublic ServerWebSocket writeFinalBinaryFrame(Buffer data, Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.writeFinalBinaryFrame(Buffer, Handler) but with an handler called when the operation completeswriteFinalBinaryFrame in interface ServerWebSocketwriteFinalBinaryFrame in interface WebSocketBasepublic Future<Void> writeBinaryMessage(Buffer data)
WebSocketBasewriteBinaryMessage in interface WebSocketBasedata - the data to writepublic ServerWebSocket writeBinaryMessage(Buffer data, Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.writeBinaryMessage(Buffer) but with an handler called when the operation completeswriteBinaryMessage in interface ServerWebSocketwriteBinaryMessage in interface WebSocketBasepublic Future<Void> writeTextMessage(String text)
WebSocketBasewriteTextMessage in interface WebSocketBasetext - the data to writepublic ServerWebSocket writeTextMessage(String text, Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.writeTextMessage(String) but with an handler called when the operation completeswriteTextMessage in interface ServerWebSocketwriteTextMessage in interface WebSocketBasepublic WebSocketBase writePing(Buffer data, Handler<AsyncResult<Void>> handler)
WebSocketBaseThis method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 Section section 5.5.2.
There is no handler for ping frames because RFC 6455 clearly states that the only response to a ping frame is a pong frame with identical contents.
writePing in interface WebSocketBasedata - the data to write, may be at most 125 byteshandler - called when the ping frame has been successfully writtenpublic Future<Void> writePing(Buffer data)
WebSocketBaseWebSocketBase.writePing(Buffer, Handler) but with an handler called when the message has been written
or failed to be written.writePing in interface WebSocketBasepublic WebSocketBase writePong(Buffer data, Handler<AsyncResult<Void>> handler)
WebSocketBaseThis method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 section 5.5.2.
There is no need to manually write a pong frame, as the server and client both handle responding to a ping from with a pong from automatically and this is exposed to users. RFC 6455 section 5.5.3 states that pongs may be sent unsolicited in order to implement a one way heartbeat.
writePong in interface WebSocketBasedata - the data to write, may be at most 125 byteshandler - called when the pong frame has been successfully writtenpublic Future<Void> writePong(Buffer data)
WebSocketBaseWebSocketBase.writePong(Buffer, Handler) but with an handler called when the message has been written
or failed to be written.writePong in interface WebSocketBasepublic ServerWebSocket closeHandler(Handler<Void> handler)
WebSocketBaseWebSocketBase.closeStatusCode() will return the status code and WebSocketBase.closeReason() will return the reason.closeHandler in interface ServerWebSocketcloseHandler in interface WebSocketBasehandler - the handlerpublic ServerWebSocket frameHandler(Handler<WebSocketFrame> handler)
WebSocketBaseframeHandler in interface ServerWebSocketframeHandler in interface WebSocketBasehandler - the handlerpublic WebSocketBase textMessageHandler(Handler<String> handler)
WebSocketBaseWebSocketBase.binaryMessageHandler(Handler), but the buffer will be converted to a String firsttextMessageHandler in interface WebSocketBasehandler - the handlerpublic WebSocketBase binaryMessageHandler(Handler<Buffer> handler)
WebSocketBaseWebSocketBase.handler(Handler)
except that if a message comes into the socket in multiple frames, the data from the frames will be aggregated
into a single buffer before calling the handler (using WebSocketFrame.isFinal() to find the boundaries).binaryMessageHandler in interface WebSocketBasehandler - the handlerpublic WebSocketBase pongHandler(Handler<Buffer> handler)
WebSocketBasePong frames may be at most 125 bytes (octets).
There is no ping handler since ping frames should immediately be responded to with a pong frame with identical content
Pong frames may be received unsolicited.
pongHandler in interface WebSocketBasehandler - the handlerpublic Future<Void> end()
WebSocketBase
Once the stream has ended, it cannot be used any more.
Calls WebSocketBase.close()
end in interface WebSocketBaseend in interface WriteStream<Buffer>public void end(Handler<AsyncResult<Void>> handler)
WebSocketBaseWriteStream.end() but with an handler called when the operation completes
Calls WebSocketBase.close(Handler)end in interface WebSocketBaseend in interface WriteStream<Buffer>public String scheme()
scheme in interface ServerWebSocketpublic String host()
host in interface ServerWebSocketpublic String uri()
uri in interface ServerWebSocketpublic String path()
path in interface ServerWebSocketpublic String query()
query in interface ServerWebSocketpublic void accept()
ServerWebSocketaccept in interface ServerWebSocketpublic void reject()
ServerWebSocketCalling this method from the WebSocket handler when it is first passed to you gives you the opportunity to reject the WebSocket, which will cause the WebSocket handshake to fail by returning a 502 response code.
You might use this method, if for example you only want to accept WebSockets with a particular path.
reject in interface ServerWebSocketpublic void reject(int status)
ServerWebSocketServerWebSocket.reject() but with a status.reject in interface ServerWebSocketpublic void setHandshake(Future<Integer> future, Handler<AsyncResult<Integer>> handler)
ServerWebSocketfuture, the
WebSocket will either be
future succeeds with the HTTP 101 status codefuture is succeeds with an HTTP status code different than 101future fails with the HTTP status code 500ServerWebSocket.close() method
will try to accept the handshake and close the WebSocket afterward. Thus it is advised to try to complete
the future with Promise.tryComplete(T) or Promise.tryFail(java.lang.Throwable).
This method should be called from the WebSocket handler to explicitly set an asynchronous handshake.
Calling this method will override the future completion handler.
setHandshake in interface ServerWebSocketfuture - the future to complete withhandler - the completion handlerpublic Future<Integer> setHandshake(Future<Integer> future)
ServerWebSocketServerWebSocket.setHandshake(Future, Handler) but returns a Future of the asynchronous resultsetHandshake in interface ServerWebSocketpublic Future<Void> close()
ServerWebSocketThe WebSocket handshake will be accepted when it hasn't yet been settled or when an asynchronous handshake is in progress.
close in interface ServerWebSocketclose in interface WebSocketBasepublic void close(Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.close() but with an handler called when the operation completesclose in interface WebSocketBasepublic Future<Void> close(short statusCode)
WebSocketBaseclose in interface WebSocketBasestatusCode - the status codepublic void close(short statusCode,
Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.close(short) but with an handler called when the operation completesclose in interface WebSocketBasepublic Future<Void> close(short statusCode, String reason)
WebSocketBaseclose in interface WebSocketBasestatusCode - the status codereason - reason of closurepublic void close(short statusCode,
String reason,
Handler<AsyncResult<Void>> handler)
WebSocketBaseWebSocketBase.close(short, String) but with an handler called when the operation completesclose in interface WebSocketBasepublic SocketAddress remoteAddress()
remoteAddress in interface WebSocketBasenull (e.g a server bound on a domain socket).
If useProxyProtocol is set to true, the address returned will be of the actual connecting client.public SocketAddress localAddress()
localAddress in interface WebSocketBasenull (e.g a server bound on a domain socket)
If useProxyProtocol is set to true, the address returned will be of the proxy.public boolean isSsl()
isSsl in interface WebSocketBaseHttpConnection is encrypted via SSL/TLS.public boolean isClosed()
isClosed in interface WebSocketBasetrue if the WebSocket is closedpublic SSLSession sslSession()
sslSession in interface ServerWebSocketsslSession in interface WebSocketBaseSSLSessionpublic X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException
ServerWebSocketServerWebSocket.sslSession() to
access that method.peerCertificateChain in interface ServerWebSocketpeerCertificateChain in interface WebSocketBaseSSLPeerUnverifiedException - SSL peer's identity has not been verified.SSLSession.getPeerCertificateChain(),
ServerWebSocket.sslSession()Copyright © 2021. All rights reserved.