Search in sources :

Example 31 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project reactor-netty by reactor.

the class NettyContextTest method addByteDecoderWhenFullReactorPipeline.

@Test
public void addByteDecoderWhenFullReactorPipeline() throws Exception {
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler()).addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
    });
    ChannelHandler decoder = new LineBasedFrameDecoder(12);
    testContext.addHandlerLast("decoder", decoder).addHandlerFirst("decoder$extract", NettyPipeline.inboundHandler(ADD_EXTRACTOR));
    assertEquals(channel.pipeline().names(), Arrays.asList(NettyPipeline.HttpCodec, NettyPipeline.HttpServerHandler, "decoder$extract", "decoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}
Also used : ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.Test)

Example 32 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project activemq-artemis by apache.

the class CertificateUtil method getCertsFromChannel.

public static X509Certificate[] getCertsFromChannel(Channel channel) {
    X509Certificate[] certificates = null;
    ChannelHandler channelHandler = channel.pipeline().get("ssl");
    if (channelHandler != null && channelHandler instanceof SslHandler) {
        SslHandler sslHandler = (SslHandler) channelHandler;
        try {
            certificates = sslHandler.engine().getSession().getPeerCertificateChain();
        } catch (SSLPeerUnverifiedException e) {
        // ignore
        }
    }
    return certificates;
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) ChannelHandler(io.netty.channel.ChannelHandler) X509Certificate(javax.security.cert.X509Certificate) SslHandler(io.netty.handler.ssl.SslHandler)

Example 33 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project activemq-artemis by apache.

the class CertificateUtil method getPeerPrincipalFromConnection.

public static Principal getPeerPrincipalFromConnection(RemotingConnection remotingConnection) {
    Principal result = null;
    if (remotingConnection != null) {
        Connection transportConnection = remotingConnection.getTransportConnection();
        if (transportConnection instanceof NettyConnection) {
            NettyConnection nettyConnection = (NettyConnection) transportConnection;
            ChannelHandler channelHandler = nettyConnection.getChannel().pipeline().get("ssl");
            if (channelHandler != null && channelHandler instanceof SslHandler) {
                SslHandler sslHandler = (SslHandler) channelHandler;
                try {
                    result = sslHandler.engine().getSession().getPeerPrincipal();
                } catch (SSLPeerUnverifiedException ignored) {
                }
            }
        }
    }
    return result;
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ChannelHandler(io.netty.channel.ChannelHandler) Principal(java.security.Principal) SslHandler(io.netty.handler.ssl.SslHandler)

Example 34 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project flink by apache.

the class RouterHandler method routed.

private void routed(ChannelHandlerContext channelHandlerContext, RouteResult<?> routeResult, HttpRequest httpRequest) {
    ChannelInboundHandler handler = (ChannelInboundHandler) routeResult.target();
    // The handler may have been added (keep alive)
    ChannelPipeline pipeline = channelHandlerContext.pipeline();
    ChannelHandler addedHandler = pipeline.get(ROUTED_HANDLER_NAME);
    if (handler != addedHandler) {
        if (addedHandler == null) {
            pipeline.addAfter(ROUTER_HANDLER_NAME, ROUTED_HANDLER_NAME, handler);
        } else {
            pipeline.replace(addedHandler, ROUTED_HANDLER_NAME, handler);
        }
    }
    RoutedRequest<?> request = new RoutedRequest<>(routeResult, httpRequest);
    channelHandlerContext.fireChannelRead(request.retain());
}
Also used : ChannelHandler(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler) SimpleChannelInboundHandler(org.apache.flink.shaded.netty4.io.netty.channel.SimpleChannelInboundHandler) ChannelInboundHandler(org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler) ChannelPipeline(org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline)

Example 35 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project flink by apache.

the class ClientTransportErrorHandlingTest method testExceptionOnWrite.

/**
 * Verifies that failed client requests via {@link PartitionRequestClient} are correctly
 * attributed to the respective {@link RemoteInputChannel}.
 */
@Test
public void testExceptionOnWrite() throws Exception {
    NettyProtocol protocol = new NettyProtocol(mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class)) {

        @Override
        public ChannelHandler[] getServerChannelHandlers() {
            return new ChannelHandler[0];
        }
    };
    // We need a real server and client in this test, because Netty's EmbeddedChannel is
    // not failing the ChannelPromise of failed writes.
    NettyServerAndClient serverAndClient = initServerAndClient(protocol, createConfig());
    Channel ch = connect(serverAndClient);
    NetworkClientHandler handler = getClientHandler(ch);
    // Last outbound handler throws Exception after 1st write
    ch.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {

        int writeNum = 0;

        @Override
        public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
            if (writeNum >= 1) {
                throw new RuntimeException("Expected test exception.");
            }
            writeNum++;
            ctx.write(msg, promise);
        }
    });
    PartitionRequestClient requestClient = new NettyPartitionRequestClient(ch, handler, mock(ConnectionID.class), mock(PartitionRequestClientFactory.class));
    // Create input channels
    RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(), createRemoteInputChannel() };
    final CountDownLatch sync = new CountDownLatch(1);
    // Do this with explicit synchronization. Otherwise this is not robust against slow timings
    // of the callback (e.g. we cannot just verify that it was called once, because there is
    // a chance that we do this too early).
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            sync.countDown();
            return null;
        }
    }).when(rich[1]).onError(isA(LocalTransportException.class));
    // First request is successful
    requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[0], 0);
    // Second request is *not* successful
    requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[1], 0);
    // Wait for the notification and it could confirm all the request operations are done
    if (!sync.await(TestingUtils.TESTING_DURATION.toMillis(), TimeUnit.MILLISECONDS)) {
        fail("Timed out after waiting for " + TestingUtils.TESTING_DURATION.toMillis() + " ms to be notified about the channel error.");
    }
    // Only the second channel should be notified about the error
    verify(rich[0], times(0)).onError(any(LocalTransportException.class));
    shutdown(serverAndClient);
}
Also used : ChannelHandlerContext(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext) ChannelPromise(org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise) PartitionRequestClient(org.apache.flink.runtime.io.network.PartitionRequestClient) ChannelHandler(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) NetworkClientHandler(org.apache.flink.runtime.io.network.NetworkClientHandler) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) ChannelOutboundHandlerAdapter(org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter) LocalTransportException(org.apache.flink.runtime.io.network.netty.exception.LocalTransportException) CountDownLatch(java.util.concurrent.CountDownLatch) LocalTransportException(org.apache.flink.runtime.io.network.netty.exception.LocalTransportException) RemoteTransportException(org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException) IOException(java.io.IOException) ConnectionID(org.apache.flink.runtime.io.network.ConnectionID) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) NettyServerAndClient(org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient) Test(org.junit.Test)

Aggregations

ChannelHandler (io.netty.channel.ChannelHandler)216 Test (org.junit.Test)88 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)44 Channel (io.netty.channel.Channel)27 ChannelPipeline (io.netty.channel.ChannelPipeline)26 SslHandler (io.netty.handler.ssl.SslHandler)25 Test (org.junit.jupiter.api.Test)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)23 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)21 FilterChainMatchingHandler (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler)20 ChannelFuture (io.netty.channel.ChannelFuture)20 FilterChainSelector (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler.FilterChainSelector)19 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)18 InetSocketAddress (java.net.InetSocketAddress)18 DownstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext)17 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)17 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 TcpIngester (com.wavefront.ingester.TcpIngester)15 ByteBuf (io.netty.buffer.ByteBuf)13