public class WebSocketAdapter extends Object implements WebSocketListener
An empty implementation of WebSocketListener interface.
WebSocketListener| Constructor and Description |
|---|
WebSocketAdapter() |
| Modifier and Type | Method and Description |
|---|---|
void |
handleCallbackError(WebSocket websocket,
Throwable cause)
Called when an <code>on<i>Xxx</i>()</code> method threw a
Throwable. |
void |
onBinaryFrame(WebSocket websocket,
WebSocketFrame frame)
Called when a binary frame (opcode = 0x2) was received.
|
void |
onBinaryMessage(WebSocket websocket,
byte[] binary)
Called when a binary message was received.
|
void |
onCloseFrame(WebSocket websocket,
WebSocketFrame frame)
Called when a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1"
>close frame</a> (opcode = 0x8) was received.
|
void |
onConnected(WebSocket websocket,
Map<String,List<String>> headers)
Called after the opening handshake of the WebSocket connection succeeded.
|
void |
onConnectError(WebSocket websocket,
WebSocketException exception)
Called when
WebSocket.connectAsynchronously() failed. |
void |
onContinuationFrame(WebSocket websocket,
WebSocketFrame frame)
Called when a continuation frame (opcode = 0x0) was received.
|
void |
onDisconnected(WebSocket websocket,
WebSocketFrame serverCloseFrame,
WebSocketFrame clientCloseFrame,
boolean closedByServer)
Called after the WebSocket connection was closed.
|
void |
onError(WebSocket websocket,
WebSocketException cause)
Call when an error occurred.
|
void |
onFrame(WebSocket websocket,
WebSocketFrame frame)
Called when a frame was received.
|
void |
onFrameError(WebSocket websocket,
WebSocketException cause,
WebSocketFrame frame)
Called when a WebSocket frame failed to be read from the WebSocket.
|
void |
onFrameSent(WebSocket websocket,
WebSocketFrame frame)
Called when a WebSocket frame was sent to the server
(but not flushed yet).
|
void |
onFrameUnsent(WebSocket websocket,
WebSocketFrame frame)
Called when a WebSocket frame was not sent to the server
because a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1"
>close frame</a> has already been sent.
|
void |
onMessageDecompressionError(WebSocket websocket,
WebSocketException cause,
byte[] compressed)
Called when a message failed to be decompressed.
|
void |
onMessageError(WebSocket websocket,
WebSocketException cause,
List<WebSocketFrame> frames)
Called when it failed to concatenate payloads of multiple frames
to construct a message.
|
void |
onPingFrame(WebSocket websocket,
WebSocketFrame frame)
Called when a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2"
>ping frame</a> (opcode = 0x9) was received.
|
void |
onPongFrame(WebSocket websocket,
WebSocketFrame frame)
Called when a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3"
>pong frame</a> (opcode = 0xA) was received.
|
void |
onSendError(WebSocket websocket,
WebSocketException cause,
WebSocketFrame frame)
Called when an error occurred when a frame was tried to be sent
to the server.
|
void |
onSendingFrame(WebSocket websocket,
WebSocketFrame frame)
Called before a WebSocket frame is sent.
|
void |
onSendingHandshake(WebSocket websocket,
String requestLine,
List<String[]> headers)
Called before an opening handshake is sent to the server.
|
void |
onStateChanged(WebSocket websocket,
WebSocketState newState)
Called after the state of the WebSocket changed.
|
void |
onTextFrame(WebSocket websocket,
WebSocketFrame frame)
Called when a text frame (opcode = 0x1) was received.
|
void |
onTextMessage(WebSocket websocket,
byte[] data)
Called when a text message was received instead of
WebSocketListener.onTextMessage(WebSocket, String) when WebSocket.isDirectTextMessage()
returns true. |
void |
onTextMessage(WebSocket websocket,
String text)
Called when a text message was received.
|
void |
onTextMessageError(WebSocket websocket,
WebSocketException cause,
byte[] data)
Called when it failed to convert payload data into a string.
|
void |
onThreadCreated(WebSocket websocket,
ThreadType threadType,
Thread thread)
Called between after a thread is created and before the thread’s
start() method is called. |
void |
onThreadStarted(WebSocket websocket,
ThreadType threadType,
Thread thread)
Called at the very beginning of the thread’s
run() method implementation. |
void |
onThreadStopping(WebSocket websocket,
ThreadType threadType,
Thread thread)
Called at the very end of the thread’s
run() method implementation. |
void |
onUnexpectedError(WebSocket websocket,
WebSocketException cause)
Called when an uncaught throwable was detected in either the
reading thread (which reads frames from the server) or the
writing thread (which sends frames to the server).
|
public void onStateChanged(WebSocket websocket, WebSocketState newState) throws Exception
WebSocketListenerCalled after the state of the WebSocket changed.
onStateChanged in interface WebSocketListenerwebsocket - The WebSocket.newState - The new state of the WebSocket.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onConnected(WebSocket websocket, Map<String,List<String>> headers) throws Exception
WebSocketListenerCalled after the opening handshake of the WebSocket connection succeeded.
onConnected in interface WebSocketListenerwebsocket - The WebSsocket.headers - HTTP headers received from the server. Keys of the map are
HTTP header names such as "Sec-WebSocket-Accept".
Note that the comparator used by the map is String.CASE_INSENSITIVE_ORDER.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onConnectError(WebSocket websocket, WebSocketException exception) throws Exception
WebSocketListenerCalled when WebSocket.connectAsynchronously() failed.
<p>
Note that this method is called only when connectAsynchronously()
was used and the connect() executed in the
background thread failed. Neither direct synchronous connect()
nor connect(ExecutorService) will trigger this callback method.
</p>
onConnectError in interface WebSocketListenerwebsocket - The WebSocket.exception - The exception thrown by connect()
method.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception
WebSocketListenerCalled after the WebSocket connection was closed.
onDisconnected in interface WebSocketListenerwebsocket - The WebSocket.serverCloseFrame - The <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1"
>close frame</a> which the server sent to this client.
This may be null.clientCloseFrame - The <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1"
>close frame</a> which this client sent to the server.
This may be null.closedByServer - true if the closing handshake was started by the server.
false if the closing handshake was started by the client.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a frame was received. This method is called before an <code>on<i>Xxx</i>Frame</code> method is called.
onFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The frame.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onContinuationFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a continuation frame (opcode = 0x0) was received.
onContinuationFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The continuation frame.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a text frame (opcode = 0x1) was received.
onTextFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The text frame.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onBinaryFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a binary frame (opcode = 0x2) was received.
onBinaryFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The binary frame.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onCloseFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1" >close frame</a> (opcode = 0x8) was received.
onCloseFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onPingFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2" >ping frame</a> (opcode = 0x9) was received.
onPingFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">ping frame</a>.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onPongFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3" >pong frame</a> (opcode = 0xA) was received.
onPongFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pong frame</a>.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onTextMessage(WebSocket websocket, String text) throws Exception
WebSocketListenerCalled when a text message was received.
<p>
When WebSocket.isDirectTextMessage() returns true,
WebSocketListener.onTextMessage(WebSocket, byte[]) will be called instead of
this method (since version 2.6).
</p>
onTextMessage in interface WebSocketListenerwebsocket - The WebSocket.text - The text message.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onTextMessage(WebSocket websocket, byte[] data) throws Exception
WebSocketListenerCalled when a text message was received instead of
WebSocketListener.onTextMessage(WebSocket, String) when WebSocket.isDirectTextMessage()
returns true.
onTextMessage in interface WebSocketListenerwebsocket - The WebSocket.data - The UTF-8 byte sequence of the text message.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onBinaryMessage(WebSocket websocket, byte[] binary) throws Exception
WebSocketListenerCalled when a binary message was received.
onBinaryMessage in interface WebSocketListenerwebsocket - The WebSocket.binary - The binary message.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onSendingFrame(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled before a WebSocket frame is sent.
onSendingFrame in interface WebSocketListenerwebsocket - The WebSocket.frame - The WebSocket frame to be sent.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a WebSocket frame was sent to the server (but not flushed yet).
onFrameSent in interface WebSocketListenerwebsocket - The WebSocket.frame - The sent frame.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onFrameUnsent(WebSocket websocket, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a WebSocket frame was not sent to the server because a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1" >close frame</a> has already been sent.
<p>
Note that onFrameUnsent is not called when onSendError is called.
</p>
onFrameUnsent in interface WebSocketListenerwebsocket - The WebSocket.frame - The unsent frame.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onError(WebSocket websocket, WebSocketException cause) throws Exception
WebSocketListenerCall when an error occurred. This method is called before an <code>on<i>Xxx</i>Error</code> method is called.
onError in interface WebSocketListenerwebsocket - The WebSocket.cause - An exception that represents the error.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onFrameError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when a WebSocket frame failed to be read from the WebSocket.
<p>
Some WebSocket server implementations close a WebSocket connection without sending
a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a> to a
client in some cases. Strictly speaking, this behavior is a violation against the
specification (<a href="https://tools.ietf.org/html/rfc6455">RFC 6455</a>). However,
this library has allowed the behavior by default since the version 1.29. Even if
the end of the input stream of a WebSocket connection were reached without a
close frame being received, it would trigger neither onError() method nor onFrameError() method. If you want to make
this library report an error in the case, pass false to WebSocket.setMissingCloseFrameAllowed(boolean) method.
</p>
onFrameError in interface WebSocketListenerwebsocket - The WebSocket.cause - An exception that represents the error. When the error occurred
because of InterruptedIOException,
exception.getError() returns WebSocketError.INTERRUPTED_IN_READING.
For other IO errors, exception.getError() returns WebSocketError.IO_ERROR_IN_READING. Other error codes denote
protocol errors, which imply that some bugs may exist in either
or both of the client-side and the server-side implementations.frame - The WebSocket frame. If this is not null, it means that
verification of the frame failed.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onMessageError(WebSocket websocket, WebSocketException cause, List<WebSocketFrame> frames) throws Exception
WebSocketListenerCalled when it failed to concatenate payloads of multiple frames to construct a message. The reason of the failure is probably out-of-memory.
onMessageError in interface WebSocketListenerwebsocket - The WebSocket.cause - An exception that represents the error.frames - The list of frames that form a message. The first element
is either a text frame and a binary frame, and the other
frames are continuation frames.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onMessageDecompressionError(WebSocket websocket, WebSocketException cause, byte[] compressed) throws Exception
WebSocketListenerCalled when a message failed to be decompressed.
onMessageDecompressionError in interface WebSocketListenerwebsocket - The WebSocket.cause - An exception that represents the error.compressed - The compressed message that failed to be decompressed.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onTextMessageError(WebSocket websocket, WebSocketException cause, byte[] data) throws Exception
WebSocketListenerCalled when it failed to convert payload data into a string. The reason of the failure is probably out-of-memory.
onTextMessageError in interface WebSocketListenerwebsocket - The WebSocket.cause - An exception that represents the error.data - The payload data that failed to be converted to a string.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onSendError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame) throws Exception
WebSocketListenerCalled when an error occurred when a frame was tried to be sent to the server.
onSendError in interface WebSocketListenerwebsocket - The WebSocket.cause - An exception that represents the error.frame - The frame which was tried to be sent. This is null
when the error code of the exception is FLUSH_ERROR.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onUnexpectedError(WebSocket websocket, WebSocketException cause) throws Exception
WebSocketListenerCalled when an uncaught throwable was detected in either the reading thread (which reads frames from the server) or the writing thread (which sends frames to the server).
onUnexpectedError in interface WebSocketListenerwebsocket - The WebSocket.cause - The cause of the error.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception
WebSocketListenerCalled when an <code>on<i>Xxx</i>()</code> method threw a Throwable.
handleCallbackError in interface WebSocketListenerwebsocket - The WebSocket.cause - The Throwable an <code>on<i>Xxx</i></code> method threw.Exception - An exception thrown by an implementation of this method.
The exception is just ignored.public void onSendingHandshake(WebSocket websocket, String requestLine, List<String[]> headers) throws Exception
WebSocketListenerCalled before an opening handshake is sent to the server.
onSendingHandshake in interface WebSocketListenerwebsocket - The WebSocket.requestLine - The request line. For example, "GET /chat HTTP/1.1".headers - The HTTP headers.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onThreadCreated(WebSocket websocket, ThreadType threadType, Thread thread) throws Exception
WebSocketListenerCalled between after a thread is created and before the thread’s
start() method is called.
onThreadCreated in interface WebSocketListenerwebsocket - The WebSocket.threadType - The thread type.thread - The newly created thread instance.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onThreadStarted(WebSocket websocket, ThreadType threadType, Thread thread) throws Exception
WebSocketListenerCalled at the very beginning of the thread’s run() method implementation.
onThreadStarted in interface WebSocketListenerwebsocket - The WebSocket.threadType - The thread type.thread - The thread instance.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).public void onThreadStopping(WebSocket websocket, ThreadType threadType, Thread thread) throws Exception
WebSocketListenerCalled at the very end of the thread’s run() method implementation.
onThreadStopping in interface WebSocketListenerwebsocket - The WebSocket.threadType - The thread type.thread - The thread instance.Exception - An exception thrown by an implementation of this method.
The exception is passed to WebSocketListener.handleCallbackError(WebSocket, Throwable).Copyright © 2021. All Rights Reserved.