Package org.glassfish.grizzly.websockets
Class BaseWebSocketFilter
java.lang.Object
org.glassfish.grizzly.filterchain.BaseFilter
org.glassfish.grizzly.websockets.BaseWebSocketFilter
- All Implemented Interfaces:
org.glassfish.grizzly.filterchain.Filter
- Direct Known Subclasses:
WebSocketClientFilter,WebSocketFilter
public abstract class BaseWebSocketFilter
extends org.glassfish.grizzly.filterchain.BaseFilter
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
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newBaseWebSocketFilterwith a default idle connection timeout of 15 minutes;BaseWebSocketFilter(long wsTimeoutInSeconds) Constructs a newBaseWebSocketFilterwith a default idle connection timeout of 15 minutes; -
Method Summary
Modifier and TypeMethodDescriptionorg.glassfish.grizzly.filterchain.NextActionhandleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx) Method handles GrizzlyConnectionclose phase.protected abstract org.glassfish.grizzly.filterchain.NextActionhandleHandshake(org.glassfish.grizzly.filterchain.FilterChainContext ctx, org.glassfish.grizzly.http.HttpContent content) Handle websocket handshakeorg.glassfish.grizzly.filterchain.NextActionhandleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx) Handle GrizzlyConnectionread phase.org.glassfish.grizzly.filterchain.NextActionhandleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx) Handle GrizzlyConnectionwrite phase.protected voidonHandshakeFailure(org.glassfish.grizzly.Connection connection, HandshakeException e) The method is called when WebSocket handshake fails for theConnection.protected voidsetIdleTimeout(org.glassfish.grizzly.filterchain.FilterChainContext ctx) protected static booleanwebSocketInProgress(org.glassfish.grizzly.Connection connection) Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, handleAccept, handleConnect, handleEvent, onAdded, onFilterChainChanged, onRemoved, toString
-
Constructor Details
-
BaseWebSocketFilter
public BaseWebSocketFilter()Constructs a newBaseWebSocketFilterwith a default idle connection timeout of 15 minutes; -
BaseWebSocketFilter
public BaseWebSocketFilter(long wsTimeoutInSeconds) Constructs a newBaseWebSocketFilterwith a default idle connection timeout of 15 minutes;
-
-
Method Details
-
handleClose
public org.glassfish.grizzly.filterchain.NextAction handleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException Method handles GrizzlyConnectionclose phase. Check if theConnectionis aWebSocket, if yes - tries to close the websocket gracefully (sending close frame) and callsWebSocket.onClose(DataFrame). If the GrizzlyConnectionis not websocket - passes processing to the next filter in the chain.- Specified by:
handleClosein interfaceorg.glassfish.grizzly.filterchain.Filter- Overrides:
handleClosein classorg.glassfish.grizzly.filterchain.BaseFilter- Parameters:
ctx-FilterChainContext- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
handleRead
public org.glassfish.grizzly.filterchain.NextAction handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException Handle GrizzlyConnectionread phase. If theConnectionhas associatedWebSocketobject (websocket connection), we check if websocket handshake has been completed for this connection, if not - initiate/validate handshake. If handshake has been completed - parse websocketDataFrames one by one and pass processing to appropriateWebSocket:WebSocketApplicationfor server- and client- side connections.- Specified by:
handleReadin interfaceorg.glassfish.grizzly.filterchain.Filter- Overrides:
handleReadin classorg.glassfish.grizzly.filterchain.BaseFilter- Parameters:
ctx-FilterChainContext- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
handleWrite
public org.glassfish.grizzly.filterchain.NextAction handleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException Handle GrizzlyConnectionwrite phase. If theConnectionhas associatedWebSocketobject (websocket connection), we assume that message is websocketDataFrameand serialize it into aBuffer.- Specified by:
handleWritein interfaceorg.glassfish.grizzly.filterchain.Filter- Overrides:
handleWritein classorg.glassfish.grizzly.filterchain.BaseFilter- Parameters:
ctx-FilterChainContext- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
handleHandshake
protected abstract org.glassfish.grizzly.filterchain.NextAction handleHandshake(org.glassfish.grizzly.filterchain.FilterChainContext ctx, org.glassfish.grizzly.http.HttpContent content) throws IOException Handle websocket handshake- Parameters:
ctx-FilterChainContextcontent- HTTP message- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
onHandshakeFailure
protected void onHandshakeFailure(org.glassfish.grizzly.Connection connection, HandshakeException e) The method is called when WebSocket handshake fails for theConnection.- Parameters:
connection-e-
-
webSocketInProgress
protected static boolean webSocketInProgress(org.glassfish.grizzly.Connection connection) -
setIdleTimeout
protected void setIdleTimeout(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
-