use of io.undertow.websockets.spi.AsyncWebSocketHttpServerExchange in project undertow by undertow-io.
the class WebSocketProtocolHandshakeHandler method handleRequest.
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (!exchange.getRequestMethod().equals(Methods.GET)) {
// Only GET is supported to start the handshake
next.handleRequest(exchange);
return;
}
final AsyncWebSocketHttpServerExchange facade = new AsyncWebSocketHttpServerExchange(exchange, peerConnections);
Handshake handshaker = null;
for (Handshake method : handshakes) {
if (method.matches(facade)) {
handshaker = method;
break;
}
}
if (handshaker == null) {
next.handleRequest(exchange);
} else {
WebSocketLogger.REQUEST_LOGGER.debugf("Attempting websocket handshake with %s on %s", handshaker, exchange);
final Handshake selected = handshaker;
if (upgradeListener == null) {
exchange.upgradeChannel(new HttpUpgradeListener() {
@Override
public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) {
WebSocketChannel channel = selected.createChannel(facade, streamConnection, facade.getBufferPool());
peerConnections.add(channel);
callback.onConnect(facade, channel);
}
});
} else {
exchange.upgradeChannel(upgradeListener);
}
handshaker.handshake(facade);
}
}
Aggregations