Example usage for io.netty.handler.codec.http.websocketx WebSocketServerHandshaker version

List of usage examples for io.netty.handler.codec.http.websocketx WebSocketServerHandshaker version

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.websocketx WebSocketServerHandshaker version.

Prototype

WebSocketVersion version

To view the source code for io.netty.handler.codec.http.websocketx WebSocketServerHandshaker version.

Click Source Link

Usage

From source file:io.vertx.core.http.impl.Http1xServerConnection.java

License:Open Source License

ServerWebSocketImpl createWebSocket(HttpServerRequestImpl request) {
    if (ws != null) {
        return ws;
    }//from  www  .java2s  . com
    if (!(request.getRequest() instanceof FullHttpRequest)) {
        throw new IllegalStateException();
    }
    FullHttpRequest nettyReq = (FullHttpRequest) request.getRequest();
    WebSocketServerHandshaker handshaker = createHandshaker(nettyReq);
    if (handshaker == null) {
        throw new IllegalStateException("Can't upgrade this request");
    }
    Function<ServerWebSocketImpl, String> f = ws -> {
        try {
            handshaker.handshake(chctx.channel(), nettyReq);
        } catch (WebSocketHandshakeException e) {
            handleException(e);
        } catch (Exception e) {
            log.error("Failed to generate shake response", e);
        }
        // remove compressor as its not needed anymore once connection was upgraded to websockets
        ChannelHandler handler = chctx.pipeline().get(HttpChunkContentCompressor.class);
        if (handler != null) {
            chctx.pipeline().remove(handler);
        }
        if (METRICS_ENABLED && metrics != null) {
            ws.setMetric(metrics.upgrade(request.metric(), ws));
        }
        ws.registerHandler(vertx.eventBus());
        return handshaker.selectedSubprotocol();
    };
    ws = new ServerWebSocketImpl(vertx, request.uri(), request.path(), request.query(), request.headers(), this,
            handshaker.version() != WebSocketVersion.V00, f, options.getMaxWebsocketFrameSize(),
            options.getMaxWebsocketMessageSize());
    return ws;
}