Search in sources :

Example 31 with ChannelOutboundHandlerAdapter

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

the class DynamicAddressConnectHandlerTest method testReplaceAddresses.

@Test
public void testReplaceAddresses() {
    EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {

        @Override
        public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
            try {
                assertSame(REMOTE_NEW, remoteAddress);
                assertSame(LOCAL_NEW, localAddress);
                promise.setSuccess();
            } catch (Throwable cause) {
                promise.setFailure(cause);
            }
        }
    }, new DynamicAddressConnectHandler() {

        @Override
        protected SocketAddress localAddress(SocketAddress remoteAddress, SocketAddress localAddress) {
            assertSame(REMOTE, remoteAddress);
            assertSame(LOCAL, localAddress);
            return LOCAL_NEW;
        }

        @Override
        protected SocketAddress remoteAddress(SocketAddress remoteAddress, SocketAddress localAddress) {
            assertSame(REMOTE, remoteAddress);
            assertSame(LOCAL, localAddress);
            return REMOTE_NEW;
        }
    });
    channel.connect(REMOTE, LOCAL).syncUninterruptibly();
    assertNull(channel.pipeline().get(DynamicAddressConnectHandler.class));
    assertFalse(channel.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) SocketAddress(java.net.SocketAddress) Test(org.junit.jupiter.api.Test)

Example 32 with ChannelOutboundHandlerAdapter

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project zuul by Netflix.

the class SslHandshakeInfoHandlerTest method sslEarlyHandshakeFailure.

@Test
public void sslEarlyHandshakeFailure() throws Exception {
    EmbeddedChannel clientChannel = new EmbeddedChannel();
    SSLEngine clientEngine = SslContextBuilder.forClient().build().newEngine(clientChannel.alloc());
    clientChannel.pipeline().addLast(new SslHandler(clientEngine));
    EmbeddedChannel serverChannel = new EmbeddedChannel();
    SelfSignedCertificate cert = new SelfSignedCertificate("localhorse");
    SSLEngine serverEngine = SslContextBuilder.forServer(cert.key(), cert.cert()).build().newEngine(serverChannel.alloc());
    serverChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() {

        @Override
        public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
            // Simulate an early closure form the client.
            ReferenceCountUtil.safeRelease(msg);
            promise.setFailure(new ClosedChannelException());
        }
    });
    serverChannel.pipeline().addLast(new SslHandler(serverEngine));
    serverChannel.pipeline().addLast(new SslHandshakeInfoHandler());
    Object clientHello = clientChannel.readOutbound();
    assertNotNull(clientHello);
    ReferenceCountUtil.retain(clientHello);
    serverChannel.writeInbound(clientHello);
    // Assert that the handler removes itself from the pipeline, since it was torn down.
    assertNull(serverChannel.pipeline().context(SslHandshakeInfoHandler.class));
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) SSLEngine(javax.net.ssl.SSLEngine) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.Test)

Example 33 with ChannelOutboundHandlerAdapter

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

the class DefaultPooledConnectionProviderTest method doTestSslEngineClosed.

private void doTestSslEngineClosed(HttpClient client, AtomicInteger closeCount, Class<? extends Throwable> expectedExc, String expectedMsg) {
    Mono<String> response = client.doOnChannelInit((o, c, address) -> c.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {

        @Override
        public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
            super.connect(ctx, remoteAddress, localAddress, new TestPromise(ctx.channel(), promise, closeCount));
        }
    })).get().uri("/").responseContent().aggregate().asString();
    StepVerifier.create(response).expectErrorMatches(t -> t.getClass().isAssignableFrom(expectedExc) && t.getMessage().startsWith(expectedMsg)).verify(Duration.ofSeconds(30));
}
Also used : StepVerifier(reactor.test.StepVerifier) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) SocketAddress(java.net.SocketAddress) PoolShutdownException(reactor.netty.internal.shaded.reactor.pool.PoolShutdownException) HttpProtocol(reactor.netty.http.HttpProtocol) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) BaseHttpTest(reactor.netty.BaseHttpTest) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ConnectionObserver(reactor.netty.ConnectionObserver) ChannelPromise(io.netty.channel.ChannelPromise) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ByteBufMono(reactor.netty.ByteBufMono) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) SslContext(io.netty.handler.ssl.SslContext) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) InstrumentedPool(reactor.netty.internal.shaded.reactor.pool.InstrumentedPool) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) Signal(reactor.core.publisher.Signal) CertificateException(java.security.cert.CertificateException) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HttpServer(reactor.netty.http.server.HttpServer) SSLException(javax.net.ssl.SSLException) List(java.util.List) SslProvider(io.netty.handler.ssl.SslProvider) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) HttpClient(reactor.netty.http.client.HttpClient) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) PoolShutdownException(reactor.netty.internal.shaded.reactor.pool.PoolShutdownException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SSLException(javax.net.ssl.SSLException)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)32 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)32 ChannelPromise (io.netty.channel.ChannelPromise)30 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)18 Test (org.junit.jupiter.api.Test)17 ByteBuf (io.netty.buffer.ByteBuf)10 Test (org.junit.Test)9 IOException (java.io.IOException)7 ClosedChannelException (java.nio.channels.ClosedChannelException)7 ChannelFuture (io.netty.channel.ChannelFuture)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Channel (io.netty.channel.Channel)3 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)3 SslContext (io.netty.handler.ssl.SslContext)3 ByteBuffer (java.nio.ByteBuffer)3 WritableByteChannel (java.nio.channels.WritableByteChannel)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ApiErrorWithMetadata (com.nike.backstopper.apierror.ApiErrorWithMetadata)2 NettyHttpClientRequestBuilder (com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder)2 NettyHttpClientResponse (com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse)2