WebSocketClientProtocolHandshakeHandler Class — netty Architecture
Architecture documentation for the WebSocketClientProtocolHandshakeHandler class in WebSocketClientProtocolHandshakeHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 825155a9_3784_59cc_4b68_f6750284e255["WebSocketClientProtocolHandshakeHandler"] c757a985_d75e_ee90_b2d1_b794c4e7209f["WebSocketClientProtocolHandshakeHandler.java"] 825155a9_3784_59cc_4b68_f6750284e255 -->|defined in| c757a985_d75e_ee90_b2d1_b794c4e7209f 52564029_092c_597c_a8fb_3c62f0b456e9["WebSocketClientProtocolHandshakeHandler()"] 825155a9_3784_59cc_4b68_f6750284e255 -->|method| 52564029_092c_597c_a8fb_3c62f0b456e9 56ce14a0_bc29_49df_7331_16bc8723a3ee["handlerAdded()"] 825155a9_3784_59cc_4b68_f6750284e255 -->|method| 56ce14a0_bc29_49df_7331_16bc8723a3ee 24cd2522_914a_7d42_2e66_20f575aed17c["channelActive()"] 825155a9_3784_59cc_4b68_f6750284e255 -->|method| 24cd2522_914a_7d42_2e66_20f575aed17c cdcb2bf9_f5bc_0647_300d_8f2b064f60f1["channelInactive()"] 825155a9_3784_59cc_4b68_f6750284e255 -->|method| cdcb2bf9_f5bc_0647_300d_8f2b064f60f1 16cdeb07_0fb1_8497_1f32_a2b6b92effe8["channelRead()"] 825155a9_3784_59cc_4b68_f6750284e255 -->|method| 16cdeb07_0fb1_8497_1f32_a2b6b92effe8 7dce26db_1d92_f1c4_0087_d998f7086afe["applyHandshakeTimeout()"] 825155a9_3784_59cc_4b68_f6750284e255 -->|method| 7dce26db_1d92_f1c4_0087_d998f7086afe 556e512c_5a45_060a_052c_ae52674c8d4e["ChannelFuture()"] 825155a9_3784_59cc_4b68_f6750284e255 -->|method| 556e512c_5a45_060a_052c_ae52674c8d4e
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java lines 30–134
class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapter {
private static final long DEFAULT_HANDSHAKE_TIMEOUT_MS = 10000L;
private final WebSocketClientHandshaker handshaker;
private final long handshakeTimeoutMillis;
private ChannelHandlerContext ctx;
private ChannelPromise handshakePromise;
WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) {
this(handshaker, DEFAULT_HANDSHAKE_TIMEOUT_MS);
}
WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker, long handshakeTimeoutMillis) {
this.handshaker = handshaker;
this.handshakeTimeoutMillis = checkPositive(handshakeTimeoutMillis, "handshakeTimeoutMillis");
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
this.ctx = ctx;
handshakePromise = ctx.newPromise();
}
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelActive();
handshaker.handshake(ctx.channel()).addListener(future -> {
if (!future.isSuccess()) {
handshakePromise.tryFailure(future.cause());
ctx.fireExceptionCaught(future.cause());
} else {
ctx.fireUserEventTriggered(
ClientHandshakeStateEvent.HANDSHAKE_ISSUED);
}
});
applyHandshakeTimeout();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
if (!handshakePromise.isDone()) {
handshakePromise.tryFailure(new WebSocketClientHandshakeException("channel closed with handshake " +
"in progress"));
}
super.channelInactive(ctx);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (!(msg instanceof FullHttpResponse)) {
ctx.fireChannelRead(msg);
return;
}
FullHttpResponse response = (FullHttpResponse) msg;
try {
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ctx.channel(), response);
handshakePromise.trySuccess();
ctx.fireUserEventTriggered(
WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE);
ctx.pipeline().remove(this);
return;
}
throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet");
} finally {
response.release();
}
}
private void applyHandshakeTimeout() {
final ChannelPromise localHandshakePromise = handshakePromise;
if (handshakeTimeoutMillis <= 0 || localHandshakePromise.isDone()) {
return;
}
final Future<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
if (localHandshakePromise.isDone()) {
Source
Frequently Asked Questions
What is the WebSocketClientProtocolHandshakeHandler class?
WebSocketClientProtocolHandshakeHandler is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java.
Where is WebSocketClientProtocolHandshakeHandler defined?
WebSocketClientProtocolHandshakeHandler is defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java at line 30.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free