ctx.attr(REQUEST_KEY).set(req);
if (WebSocketHAProxyHandshaker.isHAProxyReqeust(req)) {
final String wsUrl = getWebSocketLocation(config.isTls(), req);
final WebSocketHAProxyHandshaker haHandshaker = new WebSocketHAProxyHandshaker(wsUrl, null, 65365);
final ChannelFuture handshakeFuture = haHandshaker.handshake(ctx.channel(), req);
handshakeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
if (future.isSuccess()) {
final ChannelPipeline pipeline = future.channel().pipeline();
pipeline.remove(SockJsHandler.class);
pipeline.remove(CorsInboundHandler.class);
pipeline.remove(CorsOutboundHandler.class);
pipeline.replace(WebSocketTransport.class, "websocket-ha-proxy",
new WebSocketHAProxyTransport(haHandshaker));
pipeline.addLast(new WebSocketSendHandler());
}
}
});
return;
}
final String wsUrl = getWebSocketLocation(config.isTls(), req, Transports.Type.WEBSOCKET.path());
final WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(wsUrl, null, false);
handshaker = wsFactory.newHandshaker(req);
if (handshaker == null) {
WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
} else {
final ChannelFuture handshakeFuture = handshaker.handshake(ctx.channel(), req);
handshakeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
if (future.isSuccess()) {
ctx.pipeline().remove(SockJsHandler.class);
ctx.pipeline().remove(CorsInboundHandler.class);