Package org.glassfish.grizzly.websockets
Class BaseWebSocketFilter
java.lang.Object
org.glassfish.grizzly.filterchain.BaseFilter
org.glassfish.grizzly.websockets.BaseWebSocketFilter
- All Implemented Interfaces:
Filter
- Direct Known Subclasses:
WebSocketClientFilter,WebSocketFilter
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 TypeMethodDescriptionMethod handles GrizzlyConnectionclose phase.protected abstract NextActionhandleHandshake(FilterChainContext ctx, HttpContent content) Handle websocket handshakeHandle GrizzlyConnectionread phase.Handle GrizzlyConnectionwrite phase.protected voidonHandshakeFailure(Connection connection, HandshakeException e) The method is called when WebSocket handshake fails for theConnection.protected voidprotected static booleanwebSocketInProgress(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
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 interfaceFilter- Overrides:
handleClosein classBaseFilter- Parameters:
ctx-FilterChainContext- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
handleRead
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 interfaceFilter- Overrides:
handleReadin classBaseFilter- Parameters:
ctx-FilterChainContext- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
handleWrite
Handle GrizzlyConnectionwrite phase. If theConnectionhas associatedWebSocketobject (websocket connection), we assume that message is websocketDataFrameand serialize it into aBuffer.- Specified by:
handleWritein interfaceFilter- Overrides:
handleWritein classBaseFilter- Parameters:
ctx-FilterChainContext- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
handleHandshake
protected abstract NextAction handleHandshake(FilterChainContext ctx, HttpContent content) throws IOException Handle websocket handshake- Parameters:
ctx-FilterChainContextcontent- HTTP message- Returns:
NextActioninstruction forFilterChain, how it should continue the execution- Throws:
IOException
-
onHandshakeFailure
The method is called when WebSocket handshake fails for theConnection.- Parameters:
connection-e-
-
webSocketInProgress
-
setIdleTimeout
-