List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:com.corundumstudio.socketio.transport.WebSocketTransport.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof CloseWebSocketFrame) { ctx.channel().close();/* www. j av a2 s.c o m*/ ReferenceCountUtil.release(msg); } else if (msg instanceof BinaryWebSocketFrame || msg instanceof TextWebSocketFrame) { ByteBufHolder frame = (ByteBufHolder) msg; ClientHead client = clientsBox.get(ctx.channel()); if (client == null) { log.debug("Client with was already disconnected. Channel closed!"); ctx.channel().close(); frame.release(); return; } ctx.pipeline().fireChannelRead(new PacketsMessage(client, frame.content(), Transport.WEBSOCKET)); frame.release(); } else if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg; QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri()); String path = queryDecoder.path(); List<String> transport = queryDecoder.parameters().get("transport"); List<String> sid = queryDecoder.parameters().get("sid"); if (transport != null && NAME.equals(transport.get(0))) { try { if (!configuration.getTransports().contains(Transport.WEBSOCKET)) { log.debug("{} transport not supported by configuration.", Transport.WEBSOCKET); ctx.channel().close(); return; } if (sid != null && sid.get(0) != null) { final UUID sessionId = UUID.fromString(sid.get(0)); handshake(ctx, sessionId, path, req); } else { ClientHead client = ctx.channel().attr(ClientHead.CLIENT).get(); // first connection handshake(ctx, client.getSessionId(), path, req); } } finally { req.release(); } } else { ctx.fireChannelRead(msg); } } else { ctx.fireChannelRead(msg); } }
From source file:com.corundumstudio.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)) { try { handleMessage(req, queryDecoder, ctx); } finally { req.release();//www. j av a 2 s .c om } return; } } ctx.fireChannelRead(msg); }
From source file:com.dempe.ketty.srv.http.HttpStaticFileServerHandler.java
License:Apache License
@Override protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception { ctx.fireChannelRead(msg); }
From source file:com.ebay.jetstream.http.netty.server.KeepAliveHandler.java
License:MIT License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Attribute<AtomicInteger> attr = ctx.attr(REQUEST_COUNT); if (attr.get() == null) { attr.setIfAbsent(new AtomicInteger()); }/*from w w w . ja v a 2s.com*/ attr.get().incrementAndGet(); ctx.fireChannelRead(msg); }
From source file:com.ebay.jetstream.messaging.transport.netty.serializer.StreamMessageDecoder.java
License:MIT License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.fireChannelRead(EventProducerSessionHandler.BATCH_START_EVENT); try {//from www.j av a 2 s . co m super.channelRead(ctx, msg); } finally { ctx.fireChannelRead(EventProducerSessionHandler.BATCH_END_EVENT); } }
From source file:com.farsunset.cim.sdk.android.filter.CIMLoggingHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (debug) {// w w w .j a va2 s. c om Log.i(TAG, String.format("RECEIVED" + getSessionInfo(ctx.channel()) + "\n%s", msg.toString())); } ctx.fireChannelRead(msg); }
From source file:com.flowpowered.networking.pipeline.MessageDecoder.java
License:MIT License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception { Protocol protocol = messageHandler.getSession().getProtocol(); Codec<?> codec = null;/*from w w w . ja va 2 s . co m*/ try { codec = protocol.readHeader(buf); } catch (UnknownPacketException e) { // We want to catch this and read the length if possible int length = e.getLength(); if (length != -1 && length != 0) { buf.readBytes(length); } throw e; } if (codec == null) { throw new UnsupportedOperationException("Protocol#readHeader cannot return null!"); } Message decoded = codec.decode(buf); ctx.fireChannelRead(decoded); }
From source file:com.flysoloing.learning.network.netty.http2.helloworld.multiplex.server.Http2ServerInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0 */// w w w .ja v a 2 s.co m private void configureClearText(SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); final HttpServerCodec sourceCodec = new HttpServerCodec(); p.addLast(sourceCodec); p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory)); p.addLast(new SimpleChannelInboundHandler<HttpMessage>() { @Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)"); ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); pipeline.addAfter(thisCtx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted.")); pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength)); ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } }); p.addLast(new UserEventLogger()); }
From source file:com.flysoloing.learning.network.netty.socksproxy.SocksServerHandler.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, SocksMessage socksRequest) throws Exception { switch (socksRequest.version()) { case SOCKS4a: Socks4CommandRequest socksV4CmdRequest = (Socks4CommandRequest) socksRequest; if (socksV4CmdRequest.type() == Socks4CommandType.CONNECT) { ctx.pipeline().addLast(new SocksServerConnectHandler()); ctx.pipeline().remove(this); ctx.fireChannelRead(socksRequest); } else {/*from w w w. ja va 2s.c om*/ ctx.close(); } break; case SOCKS5: if (socksRequest instanceof Socks5InitialRequest) { // auth support example //ctx.pipeline().addFirst(new Socks5PasswordAuthRequestDecoder()); //ctx.write(new DefaultSocks5AuthMethodResponse(Socks5AuthMethod.PASSWORD)); ctx.pipeline().addFirst(new Socks5CommandRequestDecoder()); ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH)); } else if (socksRequest instanceof Socks5PasswordAuthRequest) { ctx.pipeline().addFirst(new Socks5CommandRequestDecoder()); ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS)); } else if (socksRequest instanceof Socks5CommandRequest) { Socks5CommandRequest socks5CmdRequest = (Socks5CommandRequest) socksRequest; if (socks5CmdRequest.type() == Socks5CommandType.CONNECT) { ctx.pipeline().addLast(new SocksServerConnectHandler()); ctx.pipeline().remove(this); ctx.fireChannelRead(socksRequest); } else { ctx.close(); } } else { ctx.close(); } break; case UNKNOWN: ctx.close(); break; } }
From source file:com.flysoloing.learning.network.netty.spdy.client.SpdyFrameLogger.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (acceptMessage(msg)) { log((SpdyFrame) msg, Direction.INBOUND); }//www.jav a 2 s.c om ctx.fireChannelRead(msg); }