}
return loc;
}
private void handshake(final FullHttpRequest request, final Channel ch, ChannelHandlerContext ctx) throws Exception {
final WebSocketServerHandshaker shake;
WebSocketServerHandshakerFactory factory =
new WebSocketServerHandshakerFactory(getWebSocketLocation(ch.pipeline(), request), subProtocols, false,
options.getMaxWebsocketFrameSize());
shake = factory.newHandshaker(request);
if (shake == null) {
log.error("Unrecognised websockets handshake");
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ch);
return;
}
HandlerHolder<ServerWebSocket> firstHandler = null;
HandlerHolder<ServerWebSocket> wsHandler = wsHandlerManager.chooseHandler(ch.eventLoop());
while (true) {
if (wsHandler == null) {
break;
}
// Set context manually
vertx.setContext(wsHandler.context);
if (firstHandler == wsHandler) {
break;
}
URI theURI;
try {
theURI = new URI(request.getUri());
} catch (URISyntaxException e2) {
throw new IllegalArgumentException("Invalid uri " + request.getUri()); //Should never happen
}
final ServerConnection wsConn = new ServerConnection(vertx, HttpServerImpl.this, ch, wsHandler.context,
serverOrigin, shake, metrics);
wsConn.wsHandler(wsHandler.handler);
Runnable connectRunnable = () -> {
connectionMap.put(ch, wsConn);
try {
shake.handshake(ch, request);
} catch (WebSocketHandshakeException e) {
wsConn.handleException(e);
} catch (Exception e) {
log.error("Failed to generate shake response", e);
}
};
final ServerWebSocketImpl ws = new ServerWebSocketImpl(vertx, theURI.toString(), theURI.getPath(),
theURI.getQuery(), new HeadersAdaptor(request.headers()), wsConn, shake.version() != WebSocketVersion.V00,
connectRunnable, options.getMaxWebsocketFrameSize());
wsConn.handleWebsocketConnect(ws);
if (ws.isRejected()) {
if (firstHandler == null) {
firstHandler = wsHandler;