Top Description Fields Constructors Methods
org.glassfish.tyrus.servlet

public Class TyrusHttpUpgradeHandler

extends Object
implements HttpUpgradeHandler, ReadListener
Class Inheritance
All Implemented Interfaces
jakarta.servlet.ReadListener, java.util.EventListener, jakarta.servlet.http.HttpUpgradeHandler
Known Direct Subclasses
org.glassfish.tyrus.servlet.TyrusServletUpgrade.TyrusHttpUpgradeHandlerProxy
Imports
java.io.IOException, java.nio.Buffer, .ByteBuffer, java.util.concurrent.CountDownLatch, java.util.logging.Level, .Logger, jakarta.websocket.CloseReason, jakarta.servlet.ReadListener, .ServletInputStream, .ServletOutputStream, jakarta.servlet.http.HttpUpgradeHandler, .WebConnection, org.glassfish.tyrus.core.CloseReasons, org.glassfish.tyrus.spi.Connection, .WebSocketEngine, .Writer

HttpUpgradeHandler and ReadListener implementation.

Reads data from ServletInputStream and passes it further to the Tyrus runtime.

Authors
Jitendra Kotamraju, Pavel Bucek

Field Summary

Modifier and TypeField and Description
private boolean
private ByteBuffer
private volatile boolean
private Connection
private final CountDownLatch
public static final String
FRAME_BUFFER_SIZE

The size to precede OutOfMemory Exception and potentially DDoS attacks when buffering incoming WebSocket frames.

private int
private ServletInputStream
private static final Logger
private ServletOutputStream
private WebSocketEngine.UpgradeInfo
private WebConnection
private Writer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
close(int closeCode, String closeReason)

public void
destroy()

Implements jakarta.servlet.http.HttpUpgradeHandler.destroy.

It is called when the client is disconnected.

private int

Returns:

legth of actually read data.
fillBuf
(int
length of data available to read.
length
)

Fill the buf with some more websocket protocol data.

pack-priv WebConnection
private void
httpSessionForcedClose(int closeCode, String closeReason)

public void
init(WebConnection
the WebConnection object associated to this upgrade request
wc
)

Implements jakarta.servlet.http.HttpUpgradeHandler.init.

It is called once the HTTP Upgrade process has been completed and the upgraded connection is ready to start using the new protocol.

public void
onAllDataRead()

Implements jakarta.servlet.ReadListener.onAllDataRead.

Invoked when all data for the current request has been read.

public void
onDataAvailable()

Implements jakarta.servlet.ReadListener.onDataAvailable.

When an instance of the ReadListener is registered with a ServletInputStream, this method will be invoked by the container the first time when it is possible to read data.

public void
onError(Throwable
the throwable to indicate why the read operation failed
t
)

Implements jakarta.servlet.ReadListener.onError.

Invoked when an error occurs processing the request.

public void
preInit(WebSocketEngine.UpgradeInfo
The WebSocket UpgradeInfo.
upgradeInfo
,
Writer
The Tyrus SPI Writer.
writer
,
boolean
Whether the authentication has been used.
authenticated
)

Sets the required information before init(WebConnection) is invoked.

public void
sessionDestroyed()

Called when related jakarta.servlet.http.HttpSession is destroyed or invalidated.

public void
setIncomingBufferSize(int
The new incoming frame buffer size value.
incomingBufferSize
)

Override the default FRAME_BUFFER_SIZE.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

authenticatedback to summary
private boolean authenticated
bufback to summary
private ByteBuffer buf
closedback to summary
private volatile boolean closed
connectionback to summary
private Connection connection
connectionLatchback to summary
private final CountDownLatch connectionLatch
FRAME_BUFFER_SIZEback to summary
public static final String FRAME_BUFFER_SIZE

The size to precede OutOfMemory Exception and potentially DDoS attacks when buffering incoming WebSocket frames.

The default value is 4194315 bytes, which correspond to 4M plus few bytes to frame headers.

incomingBufferSizeback to summary
private int incomingBufferSize
isback to summary
private ServletInputStream is
LOGGERback to summary
private static final Logger LOGGER
osback to summary
private ServletOutputStream os
upgradeInfoback to summary
private WebSocketEngine.UpgradeInfo upgradeInfo
wcback to summary
private WebConnection wc
writerback to summary
private Writer writer

Constructor Detail

TyrusHttpUpgradeHandlerback to summary
public TyrusHttpUpgradeHandler()

Method Detail

closeback to summary
private void close(int closeCode, String closeReason)
destroyback to summary
public void destroy()

Implements jakarta.servlet.http.HttpUpgradeHandler.destroy.

Doc from jakarta.servlet.http.HttpUpgradeHandler.destroy.

It is called when the client is disconnected.

Annotations
@Override
fillBufback to summary
private int fillBuf(int length) throws IOException

Fill the buf with some more websocket protocol data.

Parameters
length:int

length of data available to read.

Returns:int

legth of actually read data.

Exceptions
IOException:
if some other I/O error occurs.
getWebConnectionback to summary
pack-priv WebConnection getWebConnection()
httpSessionForcedCloseback to summary
private void httpSessionForcedClose(int closeCode, String closeReason)
initback to summary
public void init(WebConnection wc)

Implements jakarta.servlet.http.HttpUpgradeHandler.init.

Doc from jakarta.servlet.http.HttpUpgradeHandler.init.

It is called once the HTTP Upgrade process has been completed and the upgraded connection is ready to start using the new protocol.

Parameters
wc:WebConnection

the WebConnection object associated to this upgrade request

Annotations
@Override
onAllDataReadback to summary
public void onAllDataRead()

Implements jakarta.servlet.ReadListener.onAllDataRead.

Doc from jakarta.servlet.ReadListener.onAllDataRead.

Invoked when all data for the current request has been read.

Annotations
@Override
onDataAvailableback to summary
public void onDataAvailable()

Implements jakarta.servlet.ReadListener.onDataAvailable.

Doc from jakarta.servlet.ReadListener.onDataAvailable.

When an instance of the ReadListener is registered with a ServletInputStream, this method will be invoked by the container the first time when it is possible to read data. Subsequently the container will invoke this method if and only if the jakarta.servlet.ServletInputStream#isReady() method has been called and has returned a value of false and data has subsequently become available to read.

Annotations
@Override
onErrorback to summary
public void onError(Throwable t)

Implements jakarta.servlet.ReadListener.onError.

Doc from jakarta.servlet.ReadListener.onError.

Invoked when an error occurs processing the request.

Parameters
t:Throwable

the throwable to indicate why the read operation failed

Annotations
@Override
preInitback to summary
public void preInit(WebSocketEngine.UpgradeInfo upgradeInfo, Writer writer, boolean authenticated)

Sets the required information before init(WebConnection) is invoked.

Parameters
upgradeInfo:WebSocketEngine.UpgradeInfo

The WebSocket UpgradeInfo.

writer:Writer

The Tyrus SPI Writer.

authenticated:boolean

Whether the authentication has been used.

sessionDestroyedback to summary
public void sessionDestroyed()

Called when related jakarta.servlet.http.HttpSession is destroyed or invalidated.

Implementation is required to call onClose() on server-side with corresponding close code (1008, see WebSocket spec 7.2) - only when there is an authorized user for this session.

setIncomingBufferSizeback to summary
public void setIncomingBufferSize(int incomingBufferSize)

Override the default FRAME_BUFFER_SIZE.

Parameters
incomingBufferSize:int

The new incoming frame buffer size value.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override