Top Description Inners Fields Constructors Methods
jakarta.websocket

public Class CloseReason

extends Object
Class Inheritance
Imports
java.io.UnsupportedEncodingException

A class encapsulating the reason why a web socket has been closed, or why it is being asked to close. Note the acceptable uses of codes and reason phrase are defined in more detail by RFC 6455.
Author
dannycoward

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
CloseReason.CloseCode

A marker interface for the close codes.

public static enum
CloseReason.CloseCodes

An Enumeration of status codes for a web socket close that are defined in the specification.

Field Summary

Modifier and TypeField and Description
private final CloseReason.CloseCode
private final String

Constructor Summary

AccessConstructor and Description
public
CloseReason(CloseReason.CloseCode
the close code, may not be null
closeCode
,
String
the reason phrase, may be null.
reasonPhrase
)

Creates a reason for closing a web socket connection with the given code and reason phrase.

Method Summary

Modifier and TypeMethod and Description
public CloseReason.CloseCode

Returns:

the close code.
getCloseCode
()

The Close code associated with this CloseReason.

public String

Returns:

the reason phrase. If there is no reason phrase, this returns the empty string
getReasonPhrase
()

The reason phrase associated with this CloseReason.

public String

Returns:

A String representation of this CloseReason
toString
()

Overrides java.lang.Object.toString.

Converts the CloseReason to a debug-friendly string.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

closeCodeback to summary
private final CloseReason.CloseCode closeCode
reasonPhraseback to summary
private final String reasonPhrase

Constructor Detail

CloseReasonback to summary
public CloseReason(CloseReason.CloseCode closeCode, String reasonPhrase)

Creates a reason for closing a web socket connection with the given code and reason phrase.

Parameters
closeCode:CloseReason.CloseCode

the close code, may not be null

reasonPhrase:String

the reason phrase, may be null.

Method Detail

getCloseCodeback to summary
public CloseReason.CloseCode getCloseCode()

The Close code associated with this CloseReason.

Returns:CloseReason.CloseCode

the close code.

getReasonPhraseback to summary
public String getReasonPhrase()

The reason phrase associated with this CloseReason.

Returns:String

the reason phrase. If there is no reason phrase, this returns the empty string

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Converts the CloseReason to a debug-friendly string. The exact format is not defined by the specification and may change in future releases.

Returns:String

A String representation of this CloseReason

Annotations
@Override
jakarta.websocket back to summary

public Interface CloseReason.CloseCode

Known Direct Implementers
jakarta.websocket.CloseReason.CloseCodes

A marker interface for the close codes. This interface may be implemented by enumerations that contain web socket close codes, for example enumerations that contain all the in use close codes as of web socket 1.0, or an enumeration that contains close codes that are currently reserved for special use by the web socket specification.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the code number
getCode
()

Returns the code number, for example the integer '1000' for normal closure.

Method Detail

getCodeback to summary
public int getCode()

Returns the code number, for example the integer '1000' for normal closure.

Returns:int

the code number

jakarta.websocket back to summary

public final Enum CloseReason.CloseCodes

extends Enum<CloseReason.CloseCodes>
implements CloseCode
Class Inheritance
All Implemented Interfaces
jakarta.websocket.CloseReason.CloseCode

An Enumeration of status codes for a web socket close that are defined in the specification.

Field Summary

Modifier and TypeField and Description
public static final CloseReason.CloseCodes
CANNOT_ACCEPT

1003 indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message).

public static final CloseReason.CloseCodes
CLOSED_ABNORMALLY

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

private int
public static final CloseReason.CloseCodes
GOING_AWAY

1001 indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page.

public static final CloseReason.CloseCodes
NO_EXTENSION

1010 indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake.

public static final CloseReason.CloseCodes
NO_STATUS_CODE

1005 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

public static final CloseReason.CloseCodes
NORMAL_CLOSURE

1000 indicates a normal closure, meaning that the purpose for which the connection was established has been fulfilled.

public static final CloseReason.CloseCodes
NOT_CONSISTENT

1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 data within a text message).

public static final CloseReason.CloseCodes
PROTOCOL_ERROR

1002 indicates that an endpoint is terminating the connection due to a protocol error.

public static final CloseReason.CloseCodes
RESERVED

Reserved.

public static final CloseReason.CloseCodes
SERVICE_RESTART

1012 indicates that the service will be restarted.

public static final CloseReason.CloseCodes
TLS_HANDSHAKE_FAILURE

1015 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

public static final CloseReason.CloseCodes
TOO_BIG

1009 indicates that an endpoint is terminating the connection because it has received a message that is too big for it to process.

public static final CloseReason.CloseCodes
TRY_AGAIN_LATER

1013 indicates that the service is experiencing overload

public static final CloseReason.CloseCodes
UNEXPECTED_CONDITION

1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

public static final CloseReason.CloseCodes
VIOLATED_POLICY

1008 indicates that an endpoint is terminating the connection because it has received a message that violates its policy.

Constructor Summary

AccessConstructor and Description
private
CloseCodes(int code)

Method Summary

Modifier and TypeMethod and Description
public static CloseReason.CloseCode

Returns:

a new CloseCode with the given code number
getCloseCode
(final int
the integer code number
code
)

Creates a CloseCode from the given int code number.

public int

Returns:

the code.
getCode
()

Implements jakarta.websocket.CloseReason.CloseCode.getCode.

Return the code number of this status code.
public static CloseReason.CloseCodes
public static CloseReason.CloseCodes[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CANNOT_ACCEPTback to summary
public static final CloseReason.CloseCodes CANNOT_ACCEPT

1003 indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message).

CLOSED_ABNORMALLYback to summary
public static final CloseReason.CloseCodes CLOSED_ABNORMALLY

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g., without sending or receiving a Close control frame.

codeback to summary
private int code
GOING_AWAYback to summary
public static final CloseReason.CloseCodes GOING_AWAY

1001 indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page.

NO_EXTENSIONback to summary
public static final CloseReason.CloseCodes NO_EXTENSION

1010 indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. The list of extensions that are needed SHOULD appear in the /reason/ part of the Close frame. Note that this status code is not used by the server, because it can fail the WebSocket handshake instead.

NO_STATUS_CODEback to summary
public static final CloseReason.CloseCodes NO_STATUS_CODE

1005 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that no status code was actually present.

NORMAL_CLOSUREback to summary
public static final CloseReason.CloseCodes NORMAL_CLOSURE

1000 indicates a normal closure, meaning that the purpose for which the connection was established has been fulfilled.

NOT_CONSISTENTback to summary
public static final CloseReason.CloseCodes NOT_CONSISTENT

1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 data within a text message).

PROTOCOL_ERRORback to summary
public static final CloseReason.CloseCodes PROTOCOL_ERROR

1002 indicates that an endpoint is terminating the connection due to a protocol error.

RESERVEDback to summary
public static final CloseReason.CloseCodes RESERVED

Reserved. The specific meaning might be defined in the future.

SERVICE_RESTARTback to summary
public static final CloseReason.CloseCodes SERVICE_RESTART

1012 indicates that the service will be restarted.

TLS_HANDSHAKE_FAILUREback to summary
public static final CloseReason.CloseCodes TLS_HANDSHAKE_FAILURE

1015 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).

TOO_BIGback to summary
public static final CloseReason.CloseCodes TOO_BIG

1009 indicates that an endpoint is terminating the connection because it has received a message that is too big for it to process.

TRY_AGAIN_LATERback to summary
public static final CloseReason.CloseCodes TRY_AGAIN_LATER

1013 indicates that the service is experiencing overload

UNEXPECTED_CONDITIONback to summary
public static final CloseReason.CloseCodes UNEXPECTED_CONDITION

1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

VIOLATED_POLICYback to summary
public static final CloseReason.CloseCodes VIOLATED_POLICY

1008 indicates that an endpoint is terminating the connection because it has received a message that violates its policy. This is a generic status code that can be returned when there is no other more suitable status code (e.g., 1003 or 1009) or if there is a need to hide specific details about the policy.

Constructor Detail

CloseCodesback to summary
private CloseCodes(int code)

Method Detail

getCloseCodeback to summary
public static CloseReason.CloseCode getCloseCode(final int code)

Creates a CloseCode from the given int code number. This method throws an IllegalArgumentException if the int is not one of the

Parameters
code:int

the integer code number

Returns:CloseReason.CloseCode

a new CloseCode with the given code number

Exceptions
IllegalArgumentException:
if the code is not a valid close code
getCodeback to summary
public int getCode()

Implements jakarta.websocket.CloseReason.CloseCode.getCode.

Return the code number of this status code.

Returns:int

the code.

Annotations
@Override
valueOfback to summary
public static CloseReason.CloseCodes valueOf(String name)
valuesback to summary
public static CloseReason.CloseCodes[] values()