Example usage for io.netty.handler.codec.http.websocketx WebSocketServerHandshakerFactory WebSocketServerHandshakerFactory

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

Introduction

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

Prototype

public WebSocketServerHandshakerFactory(String webSocketURL, String subprotocols, boolean allowExtensions,
        int maxFramePayloadLength, boolean allowMaskMismatch) 

Source Link

Document

Constructor specifying the destination web socket location

Usage

From source file:com.yeetor.androidcontrol.WSSocketHandler.java

License:Open Source License

private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) {
    if (!req.getDecoderResult().isSuccess() || (!"websocket".equals(req.headers().get("Upgrade")))) {
        if (event != null) {
            DefaultFullHttpResponse response = event.onHttpRequest(ctx, req);
            if (response != null) {
                sendHttpResponse(ctx, req, response);
                return;
            }// w  ww .ja v a  2  s .co  m
        }
        sendHttpResponse(ctx, req,
                new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST));
        return;
    }
    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(null, null, true,
            Integer.MAX_VALUE, true);
    handshaker = wsFactory.newHandshaker(req);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
    } else {
        handshaker.handshake(ctx.channel(), req);
    }
}

From source file:com.yeetor.server.handler.WSHandler.java

License:Open Source License

private void handleWSConnect(ChannelHandlerContext ctx, FullHttpRequest msg) {
    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(null, null, true,
            Integer.MAX_VALUE, true);
    handshaker = wsFactory.newHandshaker(msg);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
    } else {/*  ww  w.  j  a v  a 2s  .c  om*/
        handshaker.handshake(ctx.channel(), msg);
    }
}

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

License:Open Source License

private WebSocketServerHandshaker createHandshaker(HttpRequest request) {
    // As a fun part, Firefox 6.0.2 supports Websockets protocol '7'. But,
    // it doesn't send a normal 'Connection: Upgrade' header. Instead it
    // sends: 'Connection: keep-alive, Upgrade'. Brilliant.
    Channel ch = channel();/*from   w  w w .j  a  v  a2s .c o  m*/
    String connectionHeader = request.headers().get(io.vertx.core.http.HttpHeaders.CONNECTION);
    if (connectionHeader == null || !connectionHeader.toLowerCase().contains("upgrade")) {
        HttpUtils.sendError(ch, BAD_REQUEST, "\"Connection\" must be \"Upgrade\".");
        return null;
    }

    if (request.method() != HttpMethod.GET) {
        HttpUtils.sendError(ch, METHOD_NOT_ALLOWED, null);
        return null;
    }

    try {

        WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(
                HttpUtils.getWebSocketLocation(request, isSSL()), options.getWebsocketSubProtocols(),
                options.perMessageWebsocketCompressionSupported()
                        || options.perFrameWebsocketCompressionSupported(),
                options.getMaxWebsocketFrameSize(), options.isAcceptUnmaskedFrames());

        WebSocketServerHandshaker shake = factory.newHandshaker(request);

        if (shake == null) {
            log.error("Unrecognised websockets handshake");
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ch);
        }

        return shake;
    } catch (Exception e) {
        throw new VertxException(e);
    }
}

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

License:Open Source License

WebSocketServerHandshaker createHandshaker(Channel ch, HttpRequest request) {
    // As a fun part, Firefox 6.0.2 supports Websockets protocol '7'. But,
    // it doesn't send a normal 'Connection: Upgrade' header. Instead it
    // sends: 'Connection: keep-alive, Upgrade'. Brilliant.
    String connectionHeader = request.headers().get(io.vertx.core.http.HttpHeaders.CONNECTION);
    if (connectionHeader == null || !connectionHeader.toLowerCase().contains("upgrade")) {
        sendError("\"Connection\" must be \"Upgrade\".", BAD_REQUEST, ch);
        return null;
    }/*from   ww  w  . ja  va  2s.  com*/

    if (request.getMethod() != HttpMethod.GET) {
        sendError(null, METHOD_NOT_ALLOWED, ch);
        return null;
    }

    try {

        WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(
                getWebSocketLocation(ch.pipeline(), request), subProtocols, false,
                options.getMaxWebsocketFrameSize(), options.isAcceptUnmaskedFrames());
        WebSocketServerHandshaker shake = factory.newHandshaker(request);

        if (shake == null) {
            log.error("Unrecognised websockets handshake");
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ch);
        }

        return shake;
    } catch (Exception e) {
        throw new VertxException(e);
    }
}