final Connection grizzlyConnection = ctx.getConnection();
final org.glassfish.tyrus.spi.Connection tyrusConnection = TYRUS_CONNECTION.get(grizzlyConnection);
// Get the HTTP header
final HttpHeader header = message.getHttpHeader();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "handleRead websocket: {0} content-size={1} headers=\n{2}",
new Object[]{tyrusConnection, message.getContent().remaining(), header});
}
// client
if (tyrusConnection != null) {
// this is websocket with completed handshake
if (message.getContent().hasRemaining()) {
// get the frame(s) content
Buffer buffer = message.getContent();
final ByteBuffer webSocketBuffer = buffer.toByteBuffer();
message.recycle();
final ReadHandler readHandler = tyrusConnection.getReadHandler();
TaskProcessor taskProcessor = TASK_PROCESSOR.get(ctx.getConnection());
taskProcessor.processTask(new ProcessTask(webSocketBuffer, readHandler));
}
return ctx.getStopAction();
}
// tyrusConnection == null
// proxy
final HttpStatus httpStatus = ((HttpResponsePacket) message.getHttpHeader()).getHttpStatus();
if (httpStatus.getStatusCode() != 101) {
if (proxy && !PROXY_CONNECTED.get(grizzlyConnection)) {
if (httpStatus == HttpStatus.OK_200) {
PROXY_CONNECTED.set(grizzlyConnection, true);
// TYRUS-221: Proxy handshake is complete, we need to enable SSL layer for secure ("wss")
// connections now.
if (sslFilter != null) {
((GrizzlyClientSocket.FilterWrapper) sslFilter).enable();
}
httpCodecFilter.resetResponseProcessing(grizzlyConnection);
final UpgradeRequest upgradeRequest = UPGRADE_REQUEST.get(grizzlyConnection);
ctx.write(getHttpContent(upgradeRequest));
UPGRADE_REQUEST.remove(grizzlyConnection);
} else {
throw new IOException(String.format("Proxy error. %s: %s", httpStatus.getStatusCode(),
new String(httpStatus.getReasonPhraseBytes(), "UTF-8")));
}
return ctx.getInvokeAction();
}
}
// 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();
}
// Handle handshake