Class WebSocketServerHandshaker
- java.lang.Object
-
- org.jboss.netty.handler.codec.http.websocketx.WebSocketServerHandshaker
-
- Direct Known Subclasses:
WebSocketServerHandshaker00,WebSocketServerHandshaker07,WebSocketServerHandshaker08,WebSocketServerHandshaker13
public abstract class WebSocketServerHandshaker extends java.lang.ObjectBase class for server side web socket opening and closing handshakes
-
-
Field Summary
Fields Modifier and Type Field Description static ChannelFutureListenerHANDSHAKE_LISTENERChannelFutureListenerwhich will callChannels.fireExceptionCaught(ChannelHandlerContext, Throwable)if theChannelFuturewas not successful.private longmaxFramePayloadLengthprivate java.lang.StringselectedSubprotocolstatic java.lang.StringSUB_PROTOCOL_WILDCARDUse this as wildcard to support all requested sub-protocolsprivate java.lang.String[]subprotocolsprivate WebSocketVersionversionprivate java.lang.StringwebSocketUrl
-
Constructor Summary
Constructors Modifier Constructor Description protectedWebSocketServerHandshaker(WebSocketVersion version, java.lang.String webSocketUrl, java.lang.String subprotocols)Constructor using default valuesprotectedWebSocketServerHandshaker(WebSocketVersion version, java.lang.String webSocketUrl, java.lang.String subprotocols, long maxFramePayloadLength)Constructor specifying the destination web socket location
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ChannelFutureclose(Channel channel, CloseWebSocketFrame frame)Performs the closing handshakelonggetMaxFramePayloadLength()Returns the max length for any frame's payloadjava.lang.StringgetSelectedSubprotocol()Returns the selected subprotocol.java.util.Set<java.lang.String>getSubprotocols()Returns the CSV of supported sub protocolsWebSocketVersiongetVersion()Returns the version of the specification being supportedjava.lang.StringgetWebSocketUrl()Returns the URL of the web socketabstract ChannelFuturehandshake(Channel channel, HttpRequest req)Performs the opening handshakeprotected java.lang.StringselectSubprotocol(java.lang.String requestedSubprotocols)Selects the first matching supported sub protocolprotected voidsetSelectedSubprotocol(java.lang.String value)protected ChannelFuturewriteHandshakeResponse(Channel channel, HttpResponse res, ChannelHandler encoder, ChannelHandler decoder)Upgrades the connection and send the handshake response.
-
-
-
Field Detail
-
SUB_PROTOCOL_WILDCARD
public static final java.lang.String SUB_PROTOCOL_WILDCARD
Use this as wildcard to support all requested sub-protocols- See Also:
- Constant Field Values
-
webSocketUrl
private final java.lang.String webSocketUrl
-
subprotocols
private final java.lang.String[] subprotocols
-
version
private final WebSocketVersion version
-
maxFramePayloadLength
private final long maxFramePayloadLength
-
selectedSubprotocol
private java.lang.String selectedSubprotocol
-
HANDSHAKE_LISTENER
public static final ChannelFutureListener HANDSHAKE_LISTENER
ChannelFutureListenerwhich will callChannels.fireExceptionCaught(ChannelHandlerContext, Throwable)if theChannelFuturewas not successful.
-
-
Constructor Detail
-
WebSocketServerHandshaker
protected WebSocketServerHandshaker(WebSocketVersion version, java.lang.String webSocketUrl, java.lang.String subprotocols)
Constructor using default values- Parameters:
version- the protocol versionwebSocketUrl- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.subprotocols- CSV of supported protocols. Null if sub protocols not supported.
-
WebSocketServerHandshaker
protected WebSocketServerHandshaker(WebSocketVersion version, java.lang.String webSocketUrl, java.lang.String subprotocols, long maxFramePayloadLength)
Constructor specifying the destination web socket location- Parameters:
version- the protocol versionwebSocketUrl- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.subprotocols- CSV of supported protocols. Null if sub protocols not supported.maxFramePayloadLength- Maximum length of a frame's payload
-
-
Method Detail
-
getWebSocketUrl
public java.lang.String getWebSocketUrl()
Returns the URL of the web socket
-
getSubprotocols
public java.util.Set<java.lang.String> getSubprotocols()
Returns the CSV of supported sub protocols
-
getVersion
public WebSocketVersion getVersion()
Returns the version of the specification being supported
-
getMaxFramePayloadLength
public long getMaxFramePayloadLength()
Returns the max length for any frame's payload
-
handshake
public abstract ChannelFuture handshake(Channel channel, HttpRequest req)
Performs the opening handshake- Parameters:
channel- Channelreq- HTTP Request
-
writeHandshakeResponse
protected ChannelFuture writeHandshakeResponse(Channel channel, HttpResponse res, ChannelHandler encoder, ChannelHandler decoder)
Upgrades the connection and send the handshake response.
-
close
public abstract ChannelFuture close(Channel channel, CloseWebSocketFrame frame)
Performs the closing handshake- Parameters:
channel- Channelframe- Closing Frame that was received
-
selectSubprotocol
protected java.lang.String selectSubprotocol(java.lang.String requestedSubprotocols)
Selects the first matching supported sub protocol- Parameters:
requestedSubprotocols- CSV of protocols to be supported. e.g. "chat, superchat"- Returns:
- First matching supported sub protocol. Null if not found.
-
getSelectedSubprotocol
public java.lang.String getSelectedSubprotocol()
Returns the selected subprotocol. Null if no subprotocol has been selected.This is only available AFTER handshake() has been called.
-
setSelectedSubprotocol
protected void setSelectedSubprotocol(java.lang.String value)
-
-