Example usage for io.netty.channel ChannelPipeline remove

List of usage examples for io.netty.channel ChannelPipeline remove

Introduction

In this page you can find the example usage for io.netty.channel ChannelPipeline remove.

Prototype

<T extends ChannelHandler> T remove(Class<T> handlerType);

Source Link

Document

Removes the ChannelHandler of the specified type from this pipeline.

Usage

From source file:org.infinispan.server.core.transport.SaslServerHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf buf = (ByteBuf) msg;//from www.  j  a  va 2s  . c  o  m
    Channel ch = ctx.channel();
    try {
        if (!firstPass) {
            readHeader(buf);
        } else {
            firstPass = false;
        }
        byte[] bytes = readBytes(buf);
        byte[] challenge = server.evaluateResponse(bytes);
        if (!server.isComplete()) {
            ch.writeAndFlush(newContinueMessage(ctx, Unpooled.wrappedBuffer(challenge)));
        } else {
            ch.writeAndFlush(newSuccessMessage(ctx, Unpooled.wrappedBuffer(challenge)));

            ChannelPipeline pipeline = ctx.pipeline();
            String qop = (String) server.getNegotiatedProperty(Sasl.QOP);
            if (qop != null && (qop.equalsIgnoreCase(AUTH_INT) || qop.equalsIgnoreCase(AUTO_CONF))) {
                SaslServer server = this.server;
                this.server = null;
                // Replace this handler now with the QopHandler
                // This is mainly done as the QopHandler itself will not block at all and so we can
                // get rid of the usage of the EventExecutorGroup after the negation took place.
                pipeline.replace(this, ctx.name(), new QopHandler(server));
            } else {
                // there is no need for any QOP handling so we are done now and can just remove ourself from the
                // pipeline
                pipeline.remove(this);
            }
        }
    } catch (SaslException e) {
        Object errorMsg = newErrorMessage(ctx, e);
        if (errorMsg != null) {
            ch.writeAndFlush(errorMsg).addListener(ChannelFutureListener.CLOSE);
        }
    }
}

From source file:org.jboss.arquillian.daemon.server.NettyServer.java

License:Apache License

private void resetPipeline(final ChannelPipeline pipeline) {
    // Remove all we've added
    for (final String handlerName : NAME_CHANNEL_HANDLERS) {
        try {//w ww  .  j  a  v  a2s . co m
            pipeline.remove(handlerName);
        } catch (final NoSuchElementException ignore) {
        }
    }
    // Manually set up pipeline for action controller
    pipeline.addLast(NAME_CHANNEL_HANDLER_EOF, EOF_DECODER);
    pipeline.addLast(NAME_CHANNEL_HANDLER_ACTION_CONTROLLER, new ActionControllerHandler());
}

From source file:org.jdiameter.client.impl.transport.tls.netty.StartTlsClientHandler.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from www  . ja v  a 2s.c  om
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
    logger.debug("StartTlsClientHandler");
    ByteBuf buf = (ByteBuf) msg;
    byte[] bytes = new byte[buf.readableBytes()];
    buf.getBytes(buf.readerIndex(), bytes);

    if ("StartTlsResponse".equals(new String(bytes))) {
        logger.debug("received StartTlsResponse");

        SslContext sslContext = SslContextFactory.getSslContextForClient(this.tlsTransportClient.getConfig());
        SSLEngine sslEngine = sslContext.newEngine(ctx.alloc());
        sslEngine.setUseClientMode(true);
        SslHandler sslHandler = new SslHandler(sslEngine, false);

        final ChannelPipeline pipeline = ctx.pipeline();
        pipeline.remove("startTlsClientHandler");
        pipeline.addLast("sslHandler", sslHandler);

        logger.debug("StartTls starting handshake");

        sslHandler.handshakeFuture().addListener(new GenericFutureListener() {
            @Override
            public void operationComplete(Future future) throws Exception {
                if (future.isSuccess()) {
                    logger.debug("StartTls handshake succesfull");

                    tlsTransportClient.setTlsHandshakingState(TlsHandshakingState.SHAKEN);

                    logger.debug("restoring all handlers");

                    pipeline.addLast("decoder",
                            new DiameterMessageDecoder(
                                    StartTlsClientHandler.this.tlsTransportClient.getParent(),
                                    StartTlsClientHandler.this.tlsTransportClient.getParser()));
                    pipeline.addLast("msgHandler", new DiameterMessageHandler(
                            StartTlsClientHandler.this.tlsTransportClient.getParent(), true));

                    pipeline.addLast("encoder", new DiameterMessageEncoder(
                            StartTlsClientHandler.this.tlsTransportClient.getParser()));
                    pipeline.addLast("inbandWriter", new InbandSecurityHandler());
                }
            }
        });

    }
}

From source file:org.jdiameter.client.impl.transport.tls.netty.StartTlsInitiator.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from   w ww.  j a v  a 2  s.c  o  m
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof IMessage) {
        IMessage m = (IMessage) msg;
        logger.debug("StartTlsInitiator");
        if (m.getCommandCode() == IMessage.CAPABILITIES_EXCHANGE_ANSWER
                && this.tlsTransportClient.getTlsHandshakingState() == TlsHandshakingState.INIT) {
            AvpSet set = m.getAvps();
            Avp inbandAvp = set.getAvp(Avp.INBAND_SECURITY_ID);
            if (inbandAvp != null && inbandAvp.getUnsigned32() == 1) {
                this.tlsTransportClient.setTlsHandshakingState(TlsHandshakingState.SHAKING);

                final ChannelPipeline pipeline = ctx.pipeline();
                pipeline.remove("decoder");
                pipeline.remove("msgHandler");
                pipeline.remove(this);
                pipeline.remove("encoder");
                pipeline.remove("inbandWriter");

                pipeline.addLast("startTlsClientHandler", new StartTlsClientHandler(this.tlsTransportClient));

                logger.debug("Sending StartTlsRequest");
                ctx.writeAndFlush(Unpooled.wrappedBuffer("StartTlsRequest".getBytes()))
                        .addListener(new GenericFutureListener() {

                            @Override
                            public void operationComplete(Future f) throws Exception {
                                if (!f.isSuccess()) {
                                    logger.error(f.cause().getMessage(), f.cause());
                                }
                            }
                        });

            }
        }
    }

    ReferenceCountUtil.release(msg);
}

From source file:org.jdiameter.client.impl.transport.tls.netty.StartTlsServerHandler.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from w w w  .j a v a 2 s.c o m*/
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    logger.debug("StartTlsServerHandler");
    ByteBuf buf = (ByteBuf) msg;
    byte[] bytes = new byte[buf.readableBytes()];
    buf.getBytes(buf.readerIndex(), bytes);

    if ("StartTlsRequest".equals(new String(bytes))) {
        logger.debug("Received StartTlsRequest");
        SslContext sslContext = SslContextFactory.getSslContextForServer(this.tlsTransportClient.getConfig());
        SSLEngine sslEngine = sslContext.newEngine(ctx.alloc());
        sslEngine.setUseClientMode(false);
        SslHandler sslHandler = new SslHandler(sslEngine, false);

        final ChannelPipeline pipeline = ctx.pipeline();

        pipeline.remove("decoder");
        pipeline.remove("msgHandler");
        pipeline.remove("encoder");
        pipeline.remove("inbandWriter");
        pipeline.remove(this);

        pipeline.addLast("sslHandler", sslHandler);

        sslHandler.handshakeFuture().addListener(new GenericFutureListener() {

            @Override
            public void operationComplete(Future future) throws Exception {
                if (future.isSuccess()) {
                    logger.debug("StartTls server handshake succesfull");

                    tlsTransportClient.setTlsHandshakingState(TlsHandshakingState.SHAKEN);

                    logger.debug("restoring all handlers");

                    pipeline.addLast("decoder",
                            new DiameterMessageDecoder(
                                    StartTlsServerHandler.this.tlsTransportClient.getParent(),
                                    StartTlsServerHandler.this.tlsTransportClient.getParser()));
                    pipeline.addLast("msgHandler", new DiameterMessageHandler(
                            StartTlsServerHandler.this.tlsTransportClient.getParent(), true));

                    pipeline.addLast("encoder", new DiameterMessageEncoder(
                            StartTlsServerHandler.this.tlsTransportClient.getParser()));
                    pipeline.addLast("inbandWriter", new InbandSecurityHandler());

                }
            }
        });

        ReferenceCountUtil.release(msg);
        logger.debug("Sending StartTlsResponse");
        ctx.writeAndFlush(Unpooled.wrappedBuffer("StartTlsResponse".getBytes()))
                .addListener(new GenericFutureListener() {

                    @Override
                    public void operationComplete(Future f) throws Exception {
                        if (!f.isSuccess()) {
                            logger.error(f.cause().getMessage(), f.cause());
                        }

                    }
                });
    } else {
        ctx.fireChannelRead(msg);
    }

}

From source file:org.jfxvnc.net.rfb.codec.handshaker.RfbClientHandshaker.java

License:Apache License

public final void finishHandshake(Channel channel, ProtocolVersion response) {
    setHandshakeComplete();//  w  w w  . j  a  v a2s  .co m

    ChannelPipeline p = channel.pipeline();
    p.remove("rfb-handshake-decoder");
    p.remove("rfb-handshake-encoder");

    logger.debug("server {} - client {}", version, response);

}

From source file:org.jfxvnc.net.rfb.codec.ProtocolHandshakeHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

    if (msg instanceof ProtocolVersion) {
        handleServerVersion(ctx, (ProtocolVersion) msg);
        return;//  w w w  .  ja v  a  2  s.  c  o  m
    }
    if (msg instanceof SecurityTypesEvent) {
        handleSecurityTypes(ctx, (SecurityTypesEvent) msg);
        return;
    }

    if (msg instanceof RfbSecurityMessage) {
        handleSecurityMessage(ctx, (RfbSecurityMessage) msg);
        return;
    }

    if (msg instanceof SecurityResultEvent) {
        handleSecurityResult(ctx, (SecurityResultEvent) msg);
        return;
    }

    if (msg instanceof ServerInitEvent) {
        handshaker.finishHandshake(ctx.channel(), config.versionProperty().get());
        ChannelPipeline cp = ctx.pipeline();
        cp.fireUserEventTriggered(ProtocolState.HANDSHAKE_COMPLETE);
        cp.remove(this);
        cp.fireChannelRead(msg);
        return;
    }

    throw new ProtocolException("unknown message occurred: " + msg);

}

From source file:org.jfxvnc.net.rfb.codec.security.RfbSecurityHandshaker.java

License:Apache License

public final void finishHandshake(Channel channel, RfbSecurityMessage message) {
    setHandshakeComplete();//w w  w.  j a  va  2 s. c  o  m

    ChannelPipeline p = channel.pipeline();
    p.remove("rfb-security-decoder");
    p.remove("rfb-security-encoder");

}

From source file:org.neo4j.bolt.transport.TransportSelectionHandler.java

License:Open Source License

private void enableSsl(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(sslCtx.newHandler(ctx.alloc()));
    p.addLast(new TransportSelectionHandler(null, true, logging, protocolVersions));
    p.remove(this);
}

From source file:org.neo4j.bolt.transport.TransportSelectionHandler.java

License:Open Source License

private void switchToSocket(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(new SocketTransportHandler(
            new SocketTransportHandler.ProtocolChooser(protocolVersions, isEncrypted), logging));
    p.remove(this);
}