List of usage examples for io.netty.channel ChannelPipeline remove
<T extends ChannelHandler> T remove(Class<T> handlerType);
From source file:com.ning.http.client.providers.netty_4.NettyAsyncHttpProvider.java
License:Apache License
private void upgradeProtocol(ChannelPipeline p, String scheme) throws IOException, GeneralSecurityException { if (p.get(HTTP_HANDLER) != null) { p.remove(HTTP_HANDLER); }//from w w w . ja v a 2s .c om if (isSecure(scheme)) { if (p.get(SSL_HANDLER) == null) { p.addFirst(HTTP_HANDLER, newHttpClientCodec()); p.addFirst(SSL_HANDLER, new SslHandler(createSSLEngine())); } else { p.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec()); } } else { p.addFirst(HTTP_HANDLER, newHttpClientCodec()); } }
From source file:com.quavo.osrs.network.handler.listener.WorldLoginListener.java
License:Open Source License
@Override public void handleMessage(ChannelHandlerContext ctx, WorldLoginRequest msg) { ClientMessage message = evaluateLogin(msg); if (message != ClientMessage.SUCCESSFUL) { ctx.write(new WorldLoginResponse(message)); return;/* w w w. j a va2 s . co m*/ } Player player = new Player(ctx.channel()); ctx.write(new WorldLoginResponse(player, message, msg.getIsaacPair())); ChannelPipeline pipeline = ctx.pipeline(); pipeline.remove("login.encoder"); // this isnt set automatically. pipeline.addAfter("world.decoder", "game.encoder", new GamePacketEncoder(msg.getIsaacPair().getEncoderRandom())); pipeline.replace("world.decoder", "game.decoder", new GamePacketDecoder(player, msg.getIsaacPair().getDecoderRandom())); player.init(msg.getDisplayInformation()); }
From source file:com.quavo.osrs.network.protocol.codec.connection.ConnectionEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, ConnectionResponse msg, ByteBuf out) throws Exception { ChannelPipeline pipeline = ctx.pipeline(); switch (msg.getType()) { case HANDSHAKE_CONNECTION: pipeline.addAfter("decoder", "handshake.encoder", new HandshakeEncoder()); pipeline.replace("decoder", "handshake.decoder", new HandshakeDecoder()); break;//from w ww .ja va2s. co m case LOGIN_CONNECTION: out.writeByte(ClientMessage.SUCCESSFUL_CONNECTION.getId()); pipeline.addAfter("decoder", "login.encoder", new LoginEncoder()); pipeline.replace("decoder", "login.decoder", new LoginDecoder()); break; } pipeline.remove(this); }
From source file:com.quavo.osrs.network.protocol.codec.handshake.HandshakeEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, HandshakeResponse msg, ByteBuf out) throws Exception { ChannelPipeline pipeline = ctx.pipeline(); ClientMessage message = msg.getMessage(); out.writeByte(message.getId());// w w w . jav a 2 s . co m if (message == ClientMessage.SUCCESSFUL_CONNECTION) { pipeline.addAfter("handshake.decoder", "xor.encrypt", new XOREncryptionEncoder()); pipeline.addAfter("xor.encrypt", "update.encoder", new UpdateEncoder()); pipeline.replace("handshake.decoder", "update.decoder", new UpdateDecoder()); } pipeline.remove(this); }
From source file:com.quavo.osrs.network.protocol.codec.login.LoginEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, LoginResponse msg, ByteBuf out) throws Exception { ClientMessage message = msg.getMessage(); ChannelPipeline pipeline = ctx.pipeline(); if (message != ClientMessage.SUCCESSFUL) { // dont write the id for successful. out.writeByte(message.getId());// w w w.ja va2 s . c om } else { pipeline.addAfter("login.decoder", "world.encoder", new WorldLoginEncoder()); pipeline.replace("login.decoder", "world.decoder", new WorldLoginDecoder(msg.getType())); } pipeline.remove(this); }
From source file:com.tc.websocket.server.handler.ProxyFrontendHandler.java
License:Apache License
@Override public void channelRead(final ChannelHandlerContext ctx, final Object msg) { ByteBuf buf = (ByteBuf) msg;/*from w w w . j av a2 s . c o m*/ String data = new String(ByteBufUtil.getBytes(buf)); if (data.contains(Const.UPGRADE_WEBSOCKET) || data.contains(Const.GET_WEBSOCKET)) { proxy.set(false); } else if (data.contains(StringCache.HTTP_1_1)) { proxy.set(true); } if (proxy.get() == false) { writeToFile("frontend." + ctx.channel().id(), ByteBufUtil.getBytes(buf)); } if (Config.getInstance().isCertAuth()) { SslHandler sslhandler = (SslHandler) ctx.channel().pipeline().get("ssl"); try { X509Certificate cert = sslhandler.engine().getSession().getPeerCertificateChain()[0]; Principal p = cert.getSubjectDN(); /* Added by Miguel */ LdapName ldapDN = new LdapName(p.getName()); String username = ""; String thumbprint = getThumbPrint(cert.getEncoded()); for (Rdn rdn : ldapDN.getRdns()) { //System.out.println(rdn.getType() + " -> " + rdn.getValue()); if (rdn.getType().equals("CN")) { username = rdn.getValue().toString(); break; } } /* End Added by Miguel*/ String sessionId = parseSessionID(data); if (sessionId != null) { String current = System.getProperty("user.dir"); //System.out.println("Current working directory in Java : " + current); //File sessionFile = new File("c:/sessions/" + sessionId + ".txt"); File sessionFile = new File(current + "/data/sessions/" + sessionId + ".txt"); //only write the file if it hasn't been written yet. if (sessionFile.createNewFile()) { FileUtils.write(sessionFile, p.getName().replaceAll("\"", "").replaceAll("\\+", ",") + "\n" + username + "\n" + thumbprint); } } } catch (Exception e) { LOG.log(Level.SEVERE, null, e); } } if (proxy.get()) { ctx.channel().config().setAutoRead(false); if (outboundChannel.isActive()) { outboundChannel.writeAndFlush(buf).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // was able to flush out data, start to read the next chunk ctx.channel().read(); } else { future.channel().close(); } } }); } } else { //make sure the backend handler knows its a websocket connection. this.handler.setWebsocket(true); //get handle on the pipeline. ChannelPipeline pipeline = ctx.pipeline(); //apply the websocket handlers builder.apply(pipeline); //remove this handler. pipeline.remove(this); //fire the event to move on to the next handler. ctx.fireChannelRead(msg); } }
From source file:com.tesora.dve.server.connectionmanager.loaddata.MSPLoadDataDecoder.java
License:Open Source License
private void sendResponseAndRemove(ChannelHandlerContext ctx) { ChannelPipeline pipeline = ctx.pipeline(); try {//from w ww . ja v a2s . com pauseInput(ctx);//stop incoming packets so we don't process the next request, we'll resume in the removal callback. MyMessage response; if (encounteredError == null) response = createLoadDataEOFMsg(myLoadDataInfileContext); else response = new MyErrorResponse(new PEException(encounteredError)); pipeline.writeAndFlush(response); pipeline.remove(this); } catch (Exception e) { ctx.channel().close(); } }
From source file:com.turo.pushy.apns.ApnsChannelFactory.java
License:Open Source License
ApnsChannelFactory(final SslContext sslContext, final ApnsSigningKey signingKey, final ProxyHandlerFactory proxyHandlerFactory, final int connectTimeoutMillis, final long idlePingIntervalMillis, final long gracefulShutdownTimeoutMillis, final Http2FrameLogger frameLogger, final InetSocketAddress apnsServerAddress, final EventLoopGroup eventLoopGroup) { this.sslContext = sslContext; if (this.sslContext instanceof ReferenceCounted) { ((ReferenceCounted) this.sslContext).retain(); }//from w ww . j a va 2s .co m this.addressResolverGroup = proxyHandlerFactory == null ? new RoundRobinDnsAddressResolverGroup( ClientChannelClassUtil.getDatagramChannelClass(eventLoopGroup), DefaultDnsServerAddressStreamProvider.INSTANCE) : NoopAddressResolverGroup.INSTANCE; this.bootstrapTemplate = new Bootstrap(); this.bootstrapTemplate.group(eventLoopGroup); this.bootstrapTemplate.option(ChannelOption.TCP_NODELAY, true); this.bootstrapTemplate.remoteAddress(apnsServerAddress); this.bootstrapTemplate.resolver(this.addressResolverGroup); if (connectTimeoutMillis > 0) { this.bootstrapTemplate.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis); } this.bootstrapTemplate.handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel channel) { final ChannelPipeline pipeline = channel.pipeline(); if (proxyHandlerFactory != null) { pipeline.addFirst(proxyHandlerFactory.createProxyHandler()); } final SslHandler sslHandler = sslContext.newHandler(channel.alloc()); sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(final Future<Channel> handshakeFuture) { if (handshakeFuture.isSuccess()) { final String authority = channel.remoteAddress().getHostName(); final ApnsClientHandler.ApnsClientHandlerBuilder clientHandlerBuilder; if (signingKey != null) { clientHandlerBuilder = new TokenAuthenticationApnsClientHandler.TokenAuthenticationApnsClientHandlerBuilder() .signingKey(signingKey).authority(authority) .idlePingIntervalMillis(idlePingIntervalMillis); } else { clientHandlerBuilder = new ApnsClientHandler.ApnsClientHandlerBuilder() .authority(authority).idlePingIntervalMillis(idlePingIntervalMillis); } if (frameLogger != null) { clientHandlerBuilder.frameLogger(frameLogger); } final ApnsClientHandler apnsClientHandler = clientHandlerBuilder.build(); if (gracefulShutdownTimeoutMillis > 0) { apnsClientHandler.gracefulShutdownTimeoutMillis(gracefulShutdownTimeoutMillis); } // TODO Use a named constant when https://github.com/netty/netty/pull/8683 is available pipeline.addLast(new FlushConsolidationHandler(256, true)); pipeline.addLast( new IdleStateHandler(idlePingIntervalMillis, 0, 0, TimeUnit.MILLISECONDS)); pipeline.addLast(apnsClientHandler); pipeline.remove(ConnectionNegotiationErrorHandler.INSTANCE); channel.attr(CHANNEL_READY_PROMISE_ATTRIBUTE_KEY).get().trySuccess(channel); } else { tryFailureAndLogRejectedCause(channel.attr(CHANNEL_READY_PROMISE_ATTRIBUTE_KEY).get(), handshakeFuture.cause()); } } }); pipeline.addLast(sslHandler); pipeline.addLast(ConnectionNegotiationErrorHandler.INSTANCE); } }); }
From source file:dorkbox.network.connection.registration.local.RegistrationLocalHandlerClient.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext context, Object message) throws Exception { // the "server" bounces back the registration message when it's valid. ReferenceCountUtil.release(message); Channel channel = context.channel(); MetaChannel metaChannel = channel.attr(META_CHANNEL).getAndSet(null); // have to setup new listeners if (metaChannel != null) { ChannelPipeline pipeline = channel.pipeline(); pipeline.remove(this); // Event though a local channel is XOR with everything else, we still have to make the client clean up it's state. registrationWrapper.startNextProtocolRegistration(); ConnectionImpl connection = registrationWrapper.connection0(metaChannel, null); // have to setup connection handler pipeline.addLast(CONNECTION_HANDLER, connection); registrationWrapper.connectionConnected0(connection); } else {/*from ww w . java 2s .co m*/ // this should NEVER happen! logger.error("Error registering LOCAL channel! MetaChannel is null!"); shutdown(channel, 0); } }
From source file:dorkbox.network.connection.registration.local.RegistrationLocalHandlerServer.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext context, Object message) throws Exception { Channel channel = context.channel(); ChannelPipeline pipeline = channel.pipeline(); if (!(message instanceof Registration)) { logger.error("Expected registration message was [{}] instead!", message.getClass()); shutdown(channel, 0);// w w w . java2 s .c o m ReferenceCountUtil.release(message); return; } MetaChannel metaChannel = channel.attr(META_CHANNEL).get(); if (metaChannel == null) { logger.error("Server MetaChannel was null. It shouldn't be."); shutdown(channel, 0); ReferenceCountUtil.release(message); return; } Registration registration = (Registration) message; // verify the class ID registration details. // the client will send their class registration data. VERIFY IT IS CORRECT! STATE state = registrationWrapper.verifyClassRegistration(metaChannel, registration); if (state == STATE.ERROR) { // abort! There was an error shutdown(channel, 0); return; } else if (state == STATE.WAIT) { return; } // else, continue. // have to remove the pipeline FIRST, since if we don't, and we expect to receive a message --- when we REMOVE "this" from the pipeline, // we will ALSO REMOVE all it's messages, which we want to receive! pipeline.remove(this); registration.payload = null; // we no longer need the meta channel, so remove it channel.attr(META_CHANNEL).set(null); channel.writeAndFlush(registration); ReferenceCountUtil.release(registration); logger.trace("Sent registration"); ConnectionImpl connection = registrationWrapper.connection0(metaChannel, null); if (connection != null) { // have to setup connection handler pipeline.addLast(CONNECTION_HANDLER, connection); registrationWrapper.connectionConnected0(connection); } }