List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:reactor.ipc.netty.channel.NettyChannelHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg == null) { return;//from w w w.j ava2s. co m } try { if (msg == Unpooled.EMPTY_BUFFER || msg instanceof EmptyByteBuf) { return; } operations(ctx).onInboundNext(msg); ctx.fireChannelRead(msg); } catch (Throwable err) { Exceptions.throwIfFatal(err); operations(ctx).onChannelError(err); } }
From source file:reactor.ipc.netty.http.server.HttpServerHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // read message and track if it was keepAlive if (msg instanceof HttpRequest) { final HttpRequest request = (HttpRequest) msg; if (persistentConnection) { pendingResponses += 1;//from w w w. ja va 2 s .c om persistentConnection = isKeepAlive(request); } else { if (HttpServerOperations.log.isDebugEnabled()) { HttpServerOperations.log.debug( "dropping pipelined HTTP request, " + "previous response requested connection close"); } ReferenceCountUtil.release(msg); return; } if (overflow || pendingResponses > 1) { if (HttpServerOperations.log.isDebugEnabled()) { HttpServerOperations.log.debug( "buffering pipelined HTTP request, " + "pending response count: {}, queue: {}", pendingResponses, pipelined != null ? pipelined.size() : 0); } overflow = true; doPipeline(ctx, msg); return; } else { overflow = false; parentContext.createOperations(ctx.channel(), msg); if (!(msg instanceof FullHttpRequest)) { return; } } } else if (overflow) { if (HttpServerOperations.log.isDebugEnabled()) { HttpServerOperations.log.debug( "buffering pipelined HTTP content, " + "pending response count: {}, pending pipeline:{}", pendingResponses, pipelined != null ? pipelined.size() : 0); } doPipeline(ctx, msg); return; } ctx.fireChannelRead(msg); }
From source file:ru.calypso.ogar.server.net.WebSocketHandler.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object req) throws Exception { if (req instanceof FullHttpRequest) { FullHttpRequest request = (FullHttpRequest) req; // ----- Client authenticity check code ----- // !!!!! WARNING !!!!! // THE BELOW SECTION OF CODE CHECKS TO ENSURE THAT CONNECTIONS ARE COMING // FROM THE OFFICIAL AGAR.IO CLIENT. IF YOU REMOVE OR MODIFY THE BELOW // SECTION OF CODE TO ALLOW CONNECTIONS FROM A CLIENT ON A DIFFERENT DOMAIN, // YOU MAY BE COMMITTING COPYRIGHT INFRINGEMENT AND LEGAL ACTION MAY BE TAKEN // AGAINST YOU. THIS SECTION OF CODE WAS ADDED ON JULY 9, 2015 AT THE REQUEST // OF THE AGAR.IO DEVELOPERS. String origin = request.headers().get(HttpHeaders.ORIGIN); switch (origin) { // TODO move to config case "http://agar.io": case "https://agar.io": case "http://localhost": case "https://localhost": case "http://127.0.0.1": case "https://127.0.0.1": case "http://ogar.pp.ua": break; default://from w ww.ja v a 2s . co m _log.info(String.format("User kicked by invalid origin! IP %s, ORIGIN %s", ctx.channel().remoteAddress(), origin)); ctx.channel().close(); return; } // -----/Client authenticity check code ----- WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory( "ws://" + request.headers().get(HttpHeaders.HOST) + "/", null, true); handshaker = wsFactory.newHandshaker(request); if (handshaker == null) { WebSocketServerHandshakerFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel()); } else { handshaker.handshake(ctx.channel(), request); } } else if (req instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) req; if (req instanceof CloseWebSocketFrame) { if (handshaker != null) { handshaker.close(ctx.channel(), ((CloseWebSocketFrame) req).retain()); } } else if (req instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); } else { ctx.fireChannelRead(frame.retain()); } } }
From source file:sailfish.remoting.handler.NegotiateChannelHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Protocol msg) throws Exception { if (!ChannelUtil.clientSide(ctx) && msg.request() && msg.heartbeat()) { dealNegotiate(ctx, msg);//from ww w.j a va 2 s . co m return; } // no sense to Protocol in fact ReferenceCountUtil.retain(msg); ctx.fireChannelRead(msg); }
From source file:sas.systems.imflux.network.ControlPacketDecoder.java
License:Apache License
/** * Decodes {@link ByteBuf}fers to {@link ControlPacket}s and then put them into a {@link CompoundControlPacket} to pass * it to the next {@link ChannelHandler} in the {@link ChannelPipeline}. * //from w w w .j av a 2s .co m * @param ctx ChannelHandlerContext * @param msg the message to be written */ @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { // only decode if msg is of type ByteBuf if (!(msg instanceof ByteBuf)) { return; } ByteBuf buffer = (ByteBuf) msg; if ((buffer.readableBytes() % 4) != 0) { LOG.debug("Invalid RTCP packet received: total length should be multiple of 4 but is {}", buffer.readableBytes()); return; } // Usually 2 packets per UDP frame... List<ControlPacket> controlPacketList = new ArrayList<>(2); // While there's data to read, keep on decoding. while (buffer.readableBytes() > 0) { try { // to steps to prevent adding null ControlPacket packet = ControlPacket.decode(buffer); if (packet != null) { controlPacketList.add(packet); } } catch (Exception e1) { LOG.debug("Exception caught while decoding RTCP packet.", e1); break; } } if (!controlPacketList.isEmpty()) { // Only send to next ChannelHandler when there were more than one valid decoded packets. // TODO shouldn't the whole compound packet be discarded when one of them has errors?! ctx.fireChannelRead(new CompoundControlPacket(controlPacketList)); } }
From source file:uk.co.thinkofdeath.thinkcraft.bukkit.web.ServerEndPoint.java
License:Apache License
@Override public void handle(ChannelHandlerContext context, URI uri, FullHttpRequest request) throws Exception { context.fireChannelRead(request); }
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 www . j av a 2 s. co 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.FlashPolicyHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { ByteBuf message = (ByteBuf) msg; ByteBuf data = message.slice(0, requestBuffer.readableBytes()); if (data.equals(requestBuffer)) { message.release();/*from www .ja v a 2 s . c om*/ ChannelFuture f = ctx.writeAndFlush(responseBuffer); f.addListener(ChannelFutureListener.CLOSE); return; } ctx.pipeline().remove(this); } ctx.fireChannelRead(msg); }
From source file:whitespell.net.websockets.socketio.transport.WebSocketTransport.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof CloseWebSocketFrame) { ctx.channel().close();/*from ww w. j a v a2 s .co m*/ ((CloseWebSocketFrame) msg).release(); } else if (msg instanceof TextWebSocketFrame) { TextWebSocketFrame frame = (TextWebSocketFrame) msg; WebSocketClient client = channelId2Client.get(ctx.channel()); ctx.pipeline().fireChannelRead(new PacketsMessage(client, frame.content())); frame.release(); } else if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg; QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri()); String path = queryDecoder.path(); if (path.startsWith(this.path)) { handshake(ctx, path, req); req.release(); } else { ctx.fireChannelRead(msg); } } else { ctx.fireChannelRead(msg); } }
From source file:whitespell.net.websockets.socketio.transport.XHRPollingTransport.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg; QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri()); if (queryDecoder.path().startsWith(path)) { handleMessage(req, queryDecoder, ctx); req.release();//from w w w . j ava2 s . co m return; } } ctx.fireChannelRead(msg); }