Top Description Fields Constructors Methods
org.glassfish.grizzly.websockets

public abstract Class BaseWebSocketFilter

extends BaseFilter
Class Inheritance
Known Direct Subclasses
org.glassfish.grizzly.websockets.WebSocketClientFilter, org.glassfish.grizzly.websockets.WebSocketFilter
Imports
java.io.IOException, java.util.concurrent.TimeUnit, java.util.logging.Level, .Logger, org.glassfish.grizzly.Buffer, .Connection, .Grizzly, org.glassfish.grizzly.filterchain.BaseFilter, .Filter, .FilterChain, .FilterChainContext, .NextAction, org.glassfish.grizzly.http.HttpClientFilter, .HttpContent, .HttpHeader, .HttpServerFilter, org.glassfish.grizzly.memory.Buffers, org.glassfish.grizzly.utils.IdleTimeoutFilter

WebSocket Filter implementation, which supposed to be placed into a FilterChain right after HTTP Filter: HttpServerFilter, HttpClientFilter; depending whether it's server or client side. The BaseWebSocketFilter handles websocket connection, handshake phases and, when receives a websocket frame - redirects it to appropriate connection (WebSocketApplication, WebSocket) for processing.
Author
Alexey Stashok

Field Summary

Modifier and TypeField and Description
private static final long
private static final Logger
private final long

Constructor Summary

AccessConstructor and Description
public
BaseWebSocketFilter()

Constructs a new BaseWebSocketFilter with a default idle connection timeout of 15 minutes;

public
BaseWebSocketFilter(final long wsTimeoutInSeconds)

Constructs a new BaseWebSocketFilter with a default idle connection timeout of 15 minutes;

Method Summary

Modifier and TypeMethod and Description
private static WebSocket
getWebSocket(final Connection<L> connection)

public NextAction

Returns:

NextAction instruction for FilterChain, how it should continue the execution
handleClose
(FilterChainContext ctx)

Overrides org.glassfish.grizzly.filterchain.BaseFilter.handleClose.

Implements org.glassfish.grizzly.filterchain.Filter.handleClose.

Method handles Grizzly Connection close phase.

protected abstract NextAction

Returns:

NextAction instruction for FilterChain, how it should continue the execution
handleHandshake
(FilterChainContext ctx, HttpContent
HTTP message
content
)

Handle websocket handshake

public NextAction

Returns:

NextAction instruction for FilterChain, how it should continue the execution
handleRead
(FilterChainContext ctx)

Overrides org.glassfish.grizzly.filterchain.BaseFilter.handleRead.

Implements org.glassfish.grizzly.filterchain.Filter.handleRead.

Handle Grizzly Connection read phase.

public NextAction

Returns:

NextAction instruction for FilterChain, how it should continue the execution
handleWrite
(FilterChainContext ctx)

Overrides org.glassfish.grizzly.filterchain.BaseFilter.handleWrite.

Implements org.glassfish.grizzly.filterchain.Filter.handleWrite.

Handle Grizzly Connection write phase.

protected void
onHandshakeFailure(final Connection<L> connection, final HandshakeException e)

The method is called when WebSocket handshake fails for the Connection.

protected void
protected static boolean
webSocketInProgress(final Connection<L> connection)

Inherited from org.glassfish.grizzly.filterchain.BaseFilter:
createContextexceptionOccurredhandleAccepthandleConnecthandleEventonAddedonFilterChainChangedonRemovedtoString

Field Detail

DEFAULT_WS_IDLE_TIMEOUT_IN_SECONDSback to summary
private static final long DEFAULT_WS_IDLE_TIMEOUT_IN_SECONDS
LOGGERback to summary
private static final Logger LOGGER
wsTimeoutMSback to summary
private final long wsTimeoutMS

Constructor Detail

BaseWebSocketFilterback to summary
public BaseWebSocketFilter()

Constructs a new BaseWebSocketFilter with a default idle connection timeout of 15 minutes;

BaseWebSocketFilterback to summary
public BaseWebSocketFilter(final long wsTimeoutInSeconds)

Constructs a new BaseWebSocketFilter with a default idle connection timeout of 15 minutes;

Method Detail

getWebSocketback to summary
private static WebSocket getWebSocket(final Connection<L> connection)
handleCloseback to summary
public NextAction handleClose(FilterChainContext ctx) throws IOException

Overrides org.glassfish.grizzly.filterchain.BaseFilter.handleClose.

Implements org.glassfish.grizzly.filterchain.Filter.handleClose.

Method handles Grizzly Connection close phase. Check if the Connection is a WebSocket, if yes - tries to close the websocket gracefully (sending close frame) and calls WebSocket#onClose(DataFrame). If the Grizzly Connection is not websocket - passes processing to the next filter in the chain.

Parameters
ctx:FilterChainContext

FilterChainContext

Returns:NextAction

NextAction instruction for FilterChain, how it should continue the execution

Annotations
@Override
handleHandshakeback to summary
protected abstract NextAction handleHandshake(FilterChainContext ctx, HttpContent content) throws IOException

Handle websocket handshake

Parameters
ctx:FilterChainContext

FilterChainContext

content:HttpContent

HTTP message

Returns:NextAction

NextAction instruction for FilterChain, how it should continue the execution

handleReadback to summary
public NextAction handleRead(FilterChainContext ctx) throws IOException

Overrides org.glassfish.grizzly.filterchain.BaseFilter.handleRead.

Implements org.glassfish.grizzly.filterchain.Filter.handleRead.

Handle Grizzly Connection read phase. If the Connection has associated WebSocket object (websocket connection), we check if websocket handshake has been completed for this connection, if not - initiate/validate handshake. If handshake has been completed - parse websocket DataFrames one by one and pass processing to appropriate WebSocket: WebSocketApplication for server- and client- side connections.

Parameters
ctx:FilterChainContext

FilterChainContext

Returns:NextAction

NextAction instruction for FilterChain, how it should continue the execution

Annotations
@Override
@SuppressWarnings:unchecked
handleWriteback to summary
public NextAction handleWrite(FilterChainContext ctx) throws IOException

Overrides org.glassfish.grizzly.filterchain.BaseFilter.handleWrite.

Implements org.glassfish.grizzly.filterchain.Filter.handleWrite.

Handle Grizzly Connection write phase. If the Connection has associated WebSocket object (websocket connection), we assume that message is websocket DataFrame and serialize it into a Buffer.

Parameters
ctx:FilterChainContext

FilterChainContext

Returns:NextAction

NextAction instruction for FilterChain, how it should continue the execution

Annotations
@Override
onHandshakeFailureback to summary
protected void onHandshakeFailure(final Connection<L> connection, final HandshakeException e)

The method is called when WebSocket handshake fails for the Connection.

setIdleTimeoutback to summary
protected void setIdleTimeout(final FilterChainContext ctx)
webSocketInProgressback to summary
protected static boolean webSocketInProgress(final Connection<L> connection)