final ServletWebSocketHttpExchange exchange = createHttpExchange(servletRequest, servletResponse);
exchange.putAttachment(HandshakeUtil.PATH_PARAMS, Collections.<String, String>emptyMap());
ServerWebSocketContainer wsContainer = (ServerWebSocketContainer) getContainer(servletRequest);
final EndpointSessionHandler endpointSessionHandler = new EndpointSessionHandler(wsContainer);
final ConfiguredServerEndpoint configuredServerEndpoint = createConfiguredServerEndpoint(
selectedProtocol, selectedExtensions, endpoint, servletRequest);
final Handshake handshake = getHandshakeToUse(exchange, configuredServerEndpoint);
exchange.upgradeChannel(new HttpUpgradeListener() {
@Override
public void handleUpgrade(StreamConnection connection, HttpServerExchange serverExchange) {
WebSocketChannel channel = handshake.createChannel(exchange, connection, exchange.getBufferPool());
if (peerConnections != null) {
peerConnections.add(channel);
}
endpointSessionHandler.onConnect(exchange, channel);
}
});
handshake.handshake(exchange);
}