*/
@Override
@SuppressWarnings("unchecked")
public NextAction handleRead(FilterChainContext ctx) throws IOException {
// Get the parsed HttpContent (we assume prev. filter was HTTP)
final HttpContent message = ctx.getMessage();
final org.glassfish.tyrus.spi.Connection tyrusConnection = getConnection(ctx);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "handleRead websocket: {0} content-size={1} headers=\n{2}",
new Object[]{tyrusConnection, message.getContent().remaining(), message.getHttpHeader()});
}
if (tyrusConnection == null) {
// Get the HTTP header
final HttpHeader header = message.getHttpHeader();
// If websocket is null - it means either non-websocket Connection
if (!UpgradeRequest.WEBSOCKET.equalsIgnoreCase(header.getUpgrade()) && message.getHttpHeader().isRequest()) {
// if it's not a websocket connection - pass the processing to the next filter
return ctx.getInvokeAction();
}
final String ATTR_NAME = "org.glassfish.tyrus.container.grizzly.WebSocketFilter.HANDSHAKE_PROCESSED";
final AttributeHolder attributeHolder = ctx.getAttributes();
if (attributeHolder != null) {
final Object attribute = attributeHolder.getAttribute(ATTR_NAME);
if (attribute != null) {
// handshake was already performed on this context.
return ctx.getInvokeAction();
} else {
attributeHolder.setAttribute(ATTR_NAME, true);
}
}
// Handle handshake
return handleHandshake(ctx, message);
}
// tyrusConnection is not null
// this is websocket with the completed handshake
if (message.getContent().hasRemaining()) {
// get the frame(s) content
Buffer buffer = message.getContent();
message.recycle();
final ReadHandler readHandler = tyrusConnection.getReadHandler();
if (!buffer.isComposite()) {
taskQueue.add(new ProcessTask(buffer.toByteBuffer(), readHandler));
} else {
final ByteBufferArray byteBufferArray = buffer.toByteBufferArray();