Example usage for io.netty.channel ChannelHandlerContext fireChannelRead

List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext fireChannelRead.

Prototype

@Override
    ChannelHandlerContext fireChannelRead(Object msg);

Source Link

Usage

From source file:ws.wamp.jawampa.transport.netty.WampClientWebsocketHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof CloseWebSocketFrame) {
        //readState = ReadState.Closed;
        handshaker.close(ctx.channel(), (CloseWebSocketFrame) msg).addListener(ChannelFutureListener.CLOSE);
    } else {/*from   w ww.j a  v  a 2s .  c  om*/
        ctx.fireChannelRead(msg);
    }
}

From source file:ws.wamp.jawampa.transport.netty.WampServerWebsocketHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    FullHttpRequest request = (msg instanceof FullHttpRequest) ? (FullHttpRequest) msg : null;

    // Check for invalid http messages during handshake
    if (request != null && handshakeInProgress) {
        request.release();/*from   w w w  .  j  a  va  2 s  .  c  o  m*/
        sendBadRequestAndClose(ctx, null);
        return;
    }

    // Transform this when we have an upgrade for our path,
    // otherwise pass the message
    if (request != null && isUpgradeRequest(request)) {
        try {
            tryWebsocketHandshake(ctx, (FullHttpRequest) msg);
        } finally {
            request.release();
        }
    } else {
        ctx.fireChannelRead(msg);
    }
}

From source file:zixin.socket.handler.AuthorizeHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof FullHttpRequest) {
        FullHttpRequest req = (FullHttpRequest) msg;
        Channel channel = ctx.channel();
        QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());

        if (!configuration.isAllowCustomRequests() && !queryDecoder.path().startsWith(connectPath)) {
            HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
            channel.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
            req.release();/*from ww  w .ja  v a2 s  .  c om*/
            log.warn("Blocked wrong request! url: {}, ip: {}", queryDecoder.path(), channel.remoteAddress());
            return;
        }

        List<String> sid = queryDecoder.parameters().get("sid");
        if (queryDecoder.path().equals(connectPath) && sid == null) {
            String origin = req.headers().get(HttpHeaders.Names.ORIGIN);
            if (!authorize(ctx, channel, origin, queryDecoder.parameters(), req)) {
                req.release();
                return;
            }
            // forward message to polling or websocket handler to bind channel
        }
    }
    ctx.fireChannelRead(msg);
}