Search in sources :

Example 6 with ChannelInboundHandler

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

the class RequestDecoderDispatcherTest method shouldLogAWarningIfThereIsNoDecoderForTheMessageType.

@Test
public void shouldLogAWarningIfThereIsNoDecoderForTheMessageType() throws Exception {
    // given
    RequestDecoderDispatcher<State> dispatcher = new RequestDecoderDispatcher<>(protocol, logProvider);
    ChannelInboundHandler delegateOne = mock(ChannelInboundHandler.class);
    ChannelInboundHandler delegateThree = mock(ChannelInboundHandler.class);
    dispatcher.register(State.one, delegateOne);
    dispatcher.register(State.three, delegateThree);
    // when
    dispatcher.channelRead(mock(ChannelHandlerContext.class), new Object());
    // then
    AssertableLogProvider.LogMatcher matcher = inLog(RequestDecoderDispatcher.class).warn("Unregistered handler for protocol %s", protocol);
    logProvider.assertExactly(matcher);
    verifyZeroInteractions(delegateOne, delegateThree);
}
Also used : ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 7 with ChannelInboundHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project traccar by tananaev.

the class BasePipelineFactory method initChannel.

@Override
protected void initChannel(Channel channel) {
    final ChannelPipeline pipeline = channel.pipeline();
    addTransportHandlers(pipeline::addLast);
    if (timeout > 0 && !connector.isDatagram()) {
        pipeline.addLast(new IdleStateHandler(timeout, 0, 0));
    }
    pipeline.addLast(new OpenChannelHandler(connector));
    pipeline.addLast(new NetworkMessageHandler());
    pipeline.addLast(new StandardLoggingHandler(protocol));
    addProtocolHandlers(handler -> {
        if (!(handler instanceof BaseProtocolDecoder || handler instanceof BaseProtocolEncoder)) {
            if (handler instanceof ChannelInboundHandler) {
                handler = new WrapperInboundHandler((ChannelInboundHandler) handler);
            } else {
                handler = new WrapperOutboundHandler((ChannelOutboundHandler) handler);
            }
        }
        pipeline.addLast(handler);
    });
    addHandlers(pipeline, TimeHandler.class, GeolocationHandler.class, HemisphereHandler.class, DistanceHandler.class, RemoteAddressHandler.class, FilterHandler.class, GeocoderHandler.class, SpeedLimitHandler.class, MotionHandler.class, CopyAttributesHandler.class, EngineHoursHandler.class, ComputedAttributesHandler.class, WebDataHandler.class, DefaultDataHandler.class, CommandResultEventHandler.class, OverspeedEventHandler.class, BehaviorEventHandler.class, FuelDropEventHandler.class, MotionEventHandler.class, GeofenceEventHandler.class, AlertEventHandler.class, IgnitionEventHandler.class, MaintenanceEventHandler.class, DriverEventHandler.class);
    pipeline.addLast(new MainEventHandler());
}
Also used : ChannelOutboundHandler(io.netty.channel.ChannelOutboundHandler) NetworkMessageHandler(org.traccar.handler.NetworkMessageHandler) OpenChannelHandler(org.traccar.handler.OpenChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) StandardLoggingHandler(org.traccar.handler.StandardLoggingHandler) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler)

Example 8 with ChannelInboundHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method httpProxy_completes.

@Test
public void httpProxy_completes() throws Exception {
    DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
    // ProxyHandler is incompatible with EmbeddedChannel because when channelRegistered() is called
    // the channel is already active.
    LocalAddress proxy = new LocalAddress("httpProxy_completes");
    SocketAddress host = InetSocketAddress.createUnresolved("specialHost", 314);
    ChannelInboundHandler mockHandler = mock(ChannelInboundHandler.class);
    Channel serverChannel = new ServerBootstrap().group(elg).channel(LocalServerChannel.class).childHandler(mockHandler).bind(proxy).sync().channel();
    ProtocolNegotiator nego = ProtocolNegotiators.httpProxy(proxy, null, null, ProtocolNegotiators.plaintext());
    // normally NettyClientTransport will add WBAEH which kick start the ProtocolNegotiation,
    // mocking the behavior using KickStartHandler.
    ChannelHandler handler = new KickStartHandler(nego.newHandler(FakeGrpcHttp2ConnectionHandler.noopHandler()));
    Channel channel = new Bootstrap().group(elg).channel(LocalChannel.class).handler(handler).register().sync().channel();
    pipeline = channel.pipeline();
    // Wait for initialization to complete
    channel.eventLoop().submit(NOOP_RUNNABLE).sync();
    channel.connect(host).sync();
    serverChannel.close();
    ArgumentCaptor<ChannelHandlerContext> contextCaptor = ArgumentCaptor.forClass(ChannelHandlerContext.class);
    Mockito.verify(mockHandler).channelActive(contextCaptor.capture());
    ChannelHandlerContext serverContext = contextCaptor.getValue();
    final String golden = "isThisThingOn?";
    ChannelFuture negotiationFuture = channel.writeAndFlush(bb(golden, channel));
    // Wait for sending initial request to complete
    channel.eventLoop().submit(NOOP_RUNNABLE).sync();
    ArgumentCaptor<Object> objectCaptor = ArgumentCaptor.forClass(Object.class);
    Mockito.verify(mockHandler).channelRead(ArgumentMatchers.<ChannelHandlerContext>any(), objectCaptor.capture());
    ByteBuf b = (ByteBuf) objectCaptor.getValue();
    String request = b.toString(UTF_8);
    b.release();
    assertTrue("No trailing newline: " + request, request.endsWith("\r\n\r\n"));
    assertTrue("No CONNECT: " + request, request.startsWith("CONNECT specialHost:314 "));
    assertTrue("No host header: " + request, request.contains("host: specialHost:314"));
    assertFalse(negotiationFuture.isDone());
    serverContext.writeAndFlush(bb("HTTP/1.1 200 OK\r\n\r\n", serverContext.channel())).sync();
    negotiationFuture.sync();
    channel.eventLoop().submit(NOOP_RUNNABLE).sync();
    objectCaptor = ArgumentCaptor.forClass(Object.class);
    Mockito.verify(mockHandler, times(2)).channelRead(ArgumentMatchers.<ChannelHandlerContext>any(), objectCaptor.capture());
    b = (ByteBuf) objectCaptor.getAllValues().get(1);
    // If we were using the real grpcHandler, this would have been the HTTP/2 preface
    String preface = b.toString(UTF_8);
    b.release();
    assertEquals(golden, preface);
    channel.close();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LocalAddress(io.netty.channel.local.LocalAddress) LocalServerChannel(io.netty.channel.local.LocalServerChannel) Channel(io.netty.channel.Channel) LocalChannel(io.netty.channel.local.LocalChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) ByteBuf(io.netty.buffer.ByteBuf) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ClientTlsProtocolNegotiator(io.grpc.netty.ProtocolNegotiators.ClientTlsProtocolNegotiator) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) Test(org.junit.Test)

Example 9 with ChannelInboundHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method httpProxy_500.

@Test
public void httpProxy_500() throws Exception {
    DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
    // ProxyHandler is incompatible with EmbeddedChannel because when channelRegistered() is called
    // the channel is already active.
    LocalAddress proxy = new LocalAddress("httpProxy_500");
    SocketAddress host = InetSocketAddress.createUnresolved("specialHost", 314);
    ChannelInboundHandler mockHandler = mock(ChannelInboundHandler.class);
    Channel serverChannel = new ServerBootstrap().group(elg).channel(LocalServerChannel.class).childHandler(mockHandler).bind(proxy).sync().channel();
    ProtocolNegotiator nego = ProtocolNegotiators.httpProxy(proxy, null, null, ProtocolNegotiators.plaintext());
    // normally NettyClientTransport will add WBAEH which kick start the ProtocolNegotiation,
    // mocking the behavior using KickStartHandler.
    ChannelHandler handler = new KickStartHandler(nego.newHandler(FakeGrpcHttp2ConnectionHandler.noopHandler()));
    Channel channel = new Bootstrap().group(elg).channel(LocalChannel.class).handler(handler).register().sync().channel();
    pipeline = channel.pipeline();
    // Wait for initialization to complete
    channel.eventLoop().submit(NOOP_RUNNABLE).sync();
    channel.connect(host).sync();
    serverChannel.close();
    ArgumentCaptor<ChannelHandlerContext> contextCaptor = ArgumentCaptor.forClass(ChannelHandlerContext.class);
    Mockito.verify(mockHandler).channelActive(contextCaptor.capture());
    ChannelHandlerContext serverContext = contextCaptor.getValue();
    final String golden = "isThisThingOn?";
    ChannelFuture negotiationFuture = channel.writeAndFlush(bb(golden, channel));
    // Wait for sending initial request to complete
    channel.eventLoop().submit(NOOP_RUNNABLE).sync();
    ArgumentCaptor<Object> objectCaptor = ArgumentCaptor.forClass(Object.class);
    Mockito.verify(mockHandler).channelRead(any(ChannelHandlerContext.class), objectCaptor.capture());
    ByteBuf request = (ByteBuf) objectCaptor.getValue();
    request.release();
    assertFalse(negotiationFuture.isDone());
    String response = "HTTP/1.1 500 OMG\r\nContent-Length: 4\r\n\r\noops";
    serverContext.writeAndFlush(bb(response, serverContext.channel())).sync();
    thrown.expect(ProxyConnectException.class);
    try {
        negotiationFuture.sync();
    } finally {
        channel.close();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LocalAddress(io.netty.channel.local.LocalAddress) LocalServerChannel(io.netty.channel.local.LocalServerChannel) Channel(io.netty.channel.Channel) LocalChannel(io.netty.channel.local.LocalChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) ByteBuf(io.netty.buffer.ByteBuf) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ClientTlsProtocolNegotiator(io.grpc.netty.ProtocolNegotiators.ClientTlsProtocolNegotiator) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) Test(org.junit.Test)

Example 10 with ChannelInboundHandler

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

the class HouseKeeperTest method shouldNotPropagateChannelInactive.

@Test
void shouldNotPropagateChannelInactive() throws Exception {
    ChannelInboundHandler next = mock(ChannelInboundHandler.class);
    BoltConnection connection = mock(BoltConnection.class);
    channel = new EmbeddedChannel(new HouseKeeper(connection, NullLog.getInstance()), next);
    channel.pipeline().fireChannelInactive();
    verify(next, never()).channelInactive(any());
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelInboundHandler (io.netty.channel.ChannelInboundHandler)10 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 Channel (io.netty.channel.Channel)4 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 Test (org.junit.Test)4 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)3 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)3 LocalChannel (io.netty.channel.local.LocalChannel)3 LocalServerChannel (io.netty.channel.local.LocalServerChannel)3 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 ChannelInboundHandler (org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler)3 ClientTlsProtocolNegotiator (io.grpc.netty.ProtocolNegotiators.ClientTlsProtocolNegotiator)2 Bootstrap (io.netty.bootstrap.Bootstrap)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 LocalAddress (io.netty.channel.local.LocalAddress)2 File (java.io.File)2