Class WebSocketAdapter
- java.lang.Object
-
- com.neovisionaries.ws.client.WebSocketAdapter
-
- All Implemented Interfaces:
WebSocketListener
public class WebSocketAdapter extends java.lang.Object implements WebSocketListener
An empty implementation ofWebSocketListenerinterface.- See Also:
WebSocketListener
-
-
Constructor Summary
Constructors Constructor Description WebSocketAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidhandleCallbackError(WebSocket websocket, java.lang.Throwable cause)Called when anonXxx()method threw aThrowable.voidonBinaryFrame(WebSocket websocket, WebSocketFrame frame)Called when a binary frame (opcode = 0x2) was received.voidonBinaryMessage(WebSocket websocket, byte[] binary)Called when a binary message was received.voidonCloseFrame(WebSocket websocket, WebSocketFrame frame)Called when a close frame (opcode = 0x8) was received.voidonConnected(WebSocket websocket, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)Called after the opening handshake of the WebSocket connection succeeded.voidonConnectError(WebSocket websocket, WebSocketException exception)Called whenWebSocket.connectAsynchronously()failed.voidonContinuationFrame(WebSocket websocket, WebSocketFrame frame)Called when a continuation frame (opcode = 0x0) was received.voidonDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer)Called after the WebSocket connection was closed.voidonError(WebSocket websocket, WebSocketException cause)Call when an error occurred.voidonFrame(WebSocket websocket, WebSocketFrame frame)Called when a frame was received.voidonFrameError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame)Called when a WebSocket frame failed to be read from the WebSocket.voidonFrameSent(WebSocket websocket, WebSocketFrame frame)Called when a WebSocket frame was sent to the server (but not flushed yet).voidonFrameUnsent(WebSocket websocket, WebSocketFrame frame)Called when a WebSocket frame was not sent to the server because a close frame has already been sent.voidonMessageDecompressionError(WebSocket websocket, WebSocketException cause, byte[] compressed)Called when a message failed to be decompressed.voidonMessageError(WebSocket websocket, WebSocketException cause, java.util.List<WebSocketFrame> frames)Called when it failed to concatenate payloads of multiple frames to construct a message.voidonPingFrame(WebSocket websocket, WebSocketFrame frame)Called when a ping frame (opcode = 0x9) was received.voidonPongFrame(WebSocket websocket, WebSocketFrame frame)Called when a pong frame (opcode = 0xA) was received.voidonSendError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame)Called when an error occurred when a frame was tried to be sent to the server.voidonSendingFrame(WebSocket websocket, WebSocketFrame frame)Called before a WebSocket frame is sent.voidonSendingHandshake(WebSocket websocket, java.lang.String requestLine, java.util.List<java.lang.String[]> headers)Called before an opening handshake is sent to the server.voidonStateChanged(WebSocket websocket, WebSocketState newState)Called after the state of the WebSocket changed.voidonTextFrame(WebSocket websocket, WebSocketFrame frame)Called when a text frame (opcode = 0x1) was received.voidonTextMessage(WebSocket websocket, byte[] data)Called when a text message was received instead ofWebSocketListener.onTextMessage(WebSocket, String)whenWebSocket.isDirectTextMessage()returnstrue.voidonTextMessage(WebSocket websocket, java.lang.String text)Called when a text message was received.voidonTextMessageError(WebSocket websocket, WebSocketException cause, byte[] data)Called when it failed to convert payload data into a string.voidonThreadCreated(WebSocket websocket, ThreadType threadType, java.lang.Thread thread)Called between after a thread is created and before the thread'sstart()method is called.voidonThreadStarted(WebSocket websocket, ThreadType threadType, java.lang.Thread thread)Called at the very beginning of the thread'srun()method implementation.voidonThreadStopping(WebSocket websocket, ThreadType threadType, java.lang.Thread thread)Called at the very end of the thread'srun()method implementation.voidonUnexpectedError(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).
-
-
-
Method Detail
-
onStateChanged
public void onStateChanged(WebSocket websocket, WebSocketState newState) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled after the state of the WebSocket changed.- Specified by:
onStateChangedin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.newState- The new state of the WebSocket.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onConnected
public void onConnected(WebSocket websocket, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled after the opening handshake of the WebSocket connection succeeded.- Specified by:
onConnectedin interfaceWebSocketListener- Parameters:
websocket- 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 isString.CASE_INSENSITIVE_ORDER.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onConnectError
public void onConnectError(WebSocket websocket, WebSocketException exception) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled whenWebSocket.connectAsynchronously()failed.Note that this method is called only when
connectAsynchronously()was used and theconnect()executed in the background thread failed. Neither direct synchronousconnect()norconnect(ExecutorService)will trigger this callback method.- Specified by:
onConnectErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.exception- The exception thrown byconnect()method.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onDisconnected
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled after the WebSocket connection was closed.- Specified by:
onDisconnectedin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.serverCloseFrame- The close frame which the server sent to this client. This may benull.clientCloseFrame- The close frame which this client sent to the server. This may benull.closedByServer-trueif the closing handshake was started by the server.falseif the closing handshake was started by the client.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onFrame
public void onFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a frame was received. This method is called before anonXxxFramemethod is called.- Specified by:
onFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onContinuationFrame
public void onContinuationFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a continuation frame (opcode = 0x0) was received.- Specified by:
onContinuationFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The continuation frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onTextFrame
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a text frame (opcode = 0x1) was received.- Specified by:
onTextFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The text frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onBinaryFrame
public void onBinaryFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a binary frame (opcode = 0x2) was received.- Specified by:
onBinaryFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The binary frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onCloseFrame
public void onCloseFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a close frame (opcode = 0x8) was received.- Specified by:
onCloseFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The close frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onPingFrame
public void onPingFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a ping frame (opcode = 0x9) was received.- Specified by:
onPingFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The ping frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onPongFrame
public void onPongFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a pong frame (opcode = 0xA) was received.- Specified by:
onPongFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The pong frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onTextMessage
public void onTextMessage(WebSocket websocket, java.lang.String text) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a text message was received.When
WebSocket.isDirectTextMessage()returnstrue,WebSocketListener.onTextMessage(WebSocket, byte[])will be called instead of this method (since version 2.6).- Specified by:
onTextMessagein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.text- The text message.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onTextMessage
public void onTextMessage(WebSocket websocket, byte[] data) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a text message was received instead ofWebSocketListener.onTextMessage(WebSocket, String)whenWebSocket.isDirectTextMessage()returnstrue.- Specified by:
onTextMessagein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.data- The UTF-8 byte sequence of the text message.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onBinaryMessage
public void onBinaryMessage(WebSocket websocket, byte[] binary) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a binary message was received.- Specified by:
onBinaryMessagein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.binary- The binary message.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onSendingFrame
public void onSendingFrame(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled before a WebSocket frame is sent.- Specified by:
onSendingFramein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The WebSocket frame to be sent.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onFrameSent
public void onFrameSent(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a WebSocket frame was sent to the server (but not flushed yet).- Specified by:
onFrameSentin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The sent frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onFrameUnsent
public void onFrameUnsent(WebSocket websocket, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a WebSocket frame was not sent to the server because a close frame has already been sent.Note that
onFrameUnsentis not called whenonSendErroris called.- Specified by:
onFrameUnsentin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.frame- The unsent frame.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onError
public void onError(WebSocket websocket, WebSocketException cause) throws java.lang.Exception
Description copied from interface:WebSocketListenerCall when an error occurred. This method is called before anonXxxErrormethod is called.- Specified by:
onErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.cause- An exception that represents the error.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onFrameError
public void onFrameError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a WebSocket frame failed to be read from the WebSocket.Some WebSocket server implementations close a WebSocket connection without sending a close frame to a client in some cases. Strictly speaking, this behavior is a violation against the specification (RFC 6455). 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 noronFrameError()method. If you want to make this library report an error in the case, passfalsetoWebSocket.setMissingCloseFrameAllowed(boolean)method.- Specified by:
onFrameErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.cause- An exception that represents the error. When the error occurred because ofInterruptedIOException,exception.getError()returnsWebSocketError.INTERRUPTED_IN_READING. For other IO errors,exception.getError()returnsWebSocketError.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 notnull, it means that verification of the frame failed.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onMessageError
public void onMessageError(WebSocket websocket, WebSocketException cause, java.util.List<WebSocketFrame> frames) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when it failed to concatenate payloads of multiple frames to construct a message. The reason of the failure is probably out-of-memory.- Specified by:
onMessageErrorin interfaceWebSocketListener- Parameters:
websocket- 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.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onMessageDecompressionError
public void onMessageDecompressionError(WebSocket websocket, WebSocketException cause, byte[] compressed) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when a message failed to be decompressed.- Specified by:
onMessageDecompressionErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.cause- An exception that represents the error.compressed- The compressed message that failed to be decompressed.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onTextMessageError
public void onTextMessageError(WebSocket websocket, WebSocketException cause, byte[] data) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when it failed to convert payload data into a string. The reason of the failure is probably out-of-memory.- Specified by:
onTextMessageErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.cause- An exception that represents the error.data- The payload data that failed to be converted to a string.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onSendError
public void onSendError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when an error occurred when a frame was tried to be sent to the server.- Specified by:
onSendErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.cause- An exception that represents the error.frame- The frame which was tried to be sent. This isnullwhen the error code of the exception isFLUSH_ERROR.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onUnexpectedError
public void onUnexpectedError(WebSocket websocket, WebSocketException cause) throws java.lang.Exception
Description copied from interface: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).- Specified by:
onUnexpectedErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.cause- The cause of the error.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
handleCallbackError
public void handleCallbackError(WebSocket websocket, java.lang.Throwable cause) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled when anonXxx()method threw aThrowable.- Specified by:
handleCallbackErrorin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.cause- TheThrowableanonXxxmethod threw.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is just ignored.
-
onSendingHandshake
public void onSendingHandshake(WebSocket websocket, java.lang.String requestLine, java.util.List<java.lang.String[]> headers) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled before an opening handshake is sent to the server.- Specified by:
onSendingHandshakein interfaceWebSocketListener- Parameters:
websocket- The WebSocket.requestLine- The request line. For example,"GET /chat HTTP/1.1".headers- The HTTP headers.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onThreadCreated
public void onThreadCreated(WebSocket websocket, ThreadType threadType, java.lang.Thread thread) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled between after a thread is created and before the thread'sstart()method is called.- Specified by:
onThreadCreatedin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.threadType- The thread type.thread- The newly created thread instance.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onThreadStarted
public void onThreadStarted(WebSocket websocket, ThreadType threadType, java.lang.Thread thread) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled at the very beginning of the thread'srun()method implementation.- Specified by:
onThreadStartedin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.threadType- The thread type.thread- The thread instance.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
onThreadStopping
public void onThreadStopping(WebSocket websocket, ThreadType threadType, java.lang.Thread thread) throws java.lang.Exception
Description copied from interface:WebSocketListenerCalled at the very end of the thread'srun()method implementation.- Specified by:
onThreadStoppingin interfaceWebSocketListener- Parameters:
websocket- The WebSocket.threadType- The thread type.thread- The thread instance.- Throws:
java.lang.Exception- An exception thrown by an implementation of this method. The exception is passed toWebSocketListener.handleCallbackError(WebSocket, Throwable).
-
-