Example usage for io.netty.handler.codec.http QueryStringDecoder parameters

List of usage examples for io.netty.handler.codec.http QueryStringDecoder parameters

Introduction

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

Prototype

public Map<String, List<String>> parameters() 

Source Link

Document

Returns the decoded key-value parameter pairs of the URI.

Usage

From source file:whitespell.net.websockets.socketio.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);
            ChannelFuture f = channel.write(res);
            f.addListener(ChannelFutureListener.CLOSE);
            req.release();//from  ww  w . java 2  s .  c  o  m
            return;
        }
        if (queryDecoder.path().equals(connectPath)) {
            String origin = req.headers().get(HttpHeaders.Names.ORIGIN);
            authorize(channel, origin, queryDecoder.parameters());
            req.release();
            return;
        }
    }
    ctx.fireChannelRead(msg);
}

From source file:whitespell.net.websockets.socketio.transport.XHRPollingTransport.java

License:Apache License

private void handleMessage(FullHttpRequest req, QueryStringDecoder queryDecoder, ChannelHandlerContext ctx)
        throws IOException {
    String[] parts = queryDecoder.path().split("/");
    if (parts.length > 3) {
        UUID sessionId = UUID.fromString(parts[4]);

        String origin = req.headers().get(HttpHeaders.Names.ORIGIN);
        if (queryDecoder.parameters().containsKey("disconnect")) {
            BaseClient client = sessionId2Client.get(sessionId);
            client.onChannelDisconnect();
            ctx.channel().write(new XHROutMessage(origin, sessionId));
        } else if (HttpMethod.POST.equals(req.getMethod())) {
            onPost(sessionId, ctx, origin, req.content());
        } else if (HttpMethod.GET.equals(req.getMethod())) {
            onGet(sessionId, ctx, origin);
        }//from ww w  .  j  a va  2s .  c om
    } else {
        log.warn("Wrong {} method request path: {}, from ip: {}. Channel closed!", req.getMethod(), path,
                ctx.channel().remoteAddress());
        ctx.channel().close();
    }
}

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();//w w  w.ja  va  2s.com
            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);
}