org.glassfish.grizzly.websockets
Class WebSocketFilter

java.lang.Object
  extended by org.glassfish.grizzly.filterchain.BaseFilter
      extended by org.glassfish.grizzly.websockets.WebSocketFilter
All Implemented Interfaces:
Filter

public class WebSocketFilter
extends 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 WebSocketFilter 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
WebSocketFilter()
          Constructs a new WebSocketFilter with a default idle connection timeout of 15 minutes;
WebSocketFilter(long wsTimeoutInSeconds)
          Constructs a new WebSocketFilter with a default idle connection timeout of 15 minutes;
 
Method Summary
 NextAction handleClose(FilterChainContext ctx)
          Method handles Grizzly Connection close phase.
 NextAction handleConnect(FilterChainContext ctx)
          Method handles Grizzly Connection connect phase.
 NextAction handleRead(FilterChainContext ctx)
          Handle Grizzly Connection read phase.
 NextAction handleWrite(FilterChainContext ctx)
          Handle Grizzly Connection write phase.
 
Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, getFilterChain, getIndex, handleAccept, handleEvent, onAdded, onFilterChainChanged, onRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebSocketFilter

public WebSocketFilter()
Constructs a new WebSocketFilter with a default idle connection timeout of 15 minutes;


WebSocketFilter

public WebSocketFilter(long wsTimeoutInSeconds)
Constructs a new WebSocketFilter with a default idle connection timeout of 15 minutes;

Method Detail

handleConnect

public NextAction handleConnect(FilterChainContext ctx)
                         throws IOException
Method handles Grizzly Connection connect phase. Check if the Connection is a client-side WebSocket, if yes - creates websocket handshake packet and send it to a server. Otherwise, if it's not websocket connection - pass processing to the next Filter in a chain.

Specified by:
handleConnect in interface Filter
Overrides:
handleConnect in class BaseFilter
Parameters:
ctx - FilterChainContext
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - IOException}
IOException

handleClose

public NextAction handleClose(FilterChainContext ctx)
                       throws IOException
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.

Specified by:
handleClose in interface Filter
Overrides:
handleClose in class BaseFilter
Parameters:
ctx - FilterChainContext
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - IOException}
IOException

handleRead

public NextAction handleRead(FilterChainContext ctx)
                      throws IOException
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.

Specified by:
handleRead in interface Filter
Overrides:
handleRead in class BaseFilter
Parameters:
ctx - FilterChainContext
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - IOException}
IOException

handleWrite

public NextAction handleWrite(FilterChainContext ctx)
                       throws IOException
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.

Specified by:
handleWrite in interface Filter
Overrides:
handleWrite in class BaseFilter
Parameters:
ctx - FilterChainContext
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - IOException}
IOException


Copyright © 2013 Oracle Corporation. All Rights Reserved.