Search in sources :

Example 1 with Http2AlpnHandler

use of com.linkedin.r2.netty.handler.http2.Http2AlpnHandler in project rest.li by linkedin.

the class TestHttp2AlpnHandler method testChannelCloseBeforeNegotiation.

@Test(timeOut = 10000)
@SuppressWarnings("unchecked")
public void testChannelCloseBeforeNegotiation() throws Exception {
    SslContext sslContext = Mockito.mock(SslContext.class);
    Http2StreamCodec http2StreamCodec = Mockito.mock(Http2StreamCodec.class);
    Http2AlpnHandler handler = new Http2AlpnHandler(sslContext, http2StreamCodec, true, Integer.MAX_VALUE);
    EmbeddedChannel channel = new EmbeddedChannel(handler);
    RequestWithCallback request = Mockito.mock(RequestWithCallback.class);
    TimeoutAsyncPoolHandle handle = Mockito.mock(TimeoutAsyncPoolHandle.class);
    TimeoutTransportCallback callback = Mockito.mock(TimeoutTransportCallback.class);
    Mockito.when(request.handle()).thenReturn(handle);
    Mockito.when(request.callback()).thenReturn(callback);
    // Write should not succeed before negotiation completes
    Assert.assertFalse(channel.writeOutbound(request));
    Assert.assertFalse(channel.finish());
    // Synchronously waiting for channel to close
    channel.close().sync();
    Mockito.verify(request).handle();
    Mockito.verify(request).callback();
    Mockito.verify(handle).dispose();
    Mockito.verify(callback).onResponse(Mockito.any(TransportResponse.class));
}
Also used : RequestWithCallback(com.linkedin.r2.transport.common.bridge.common.RequestWithCallback) TimeoutTransportCallback(com.linkedin.r2.transport.http.client.TimeoutTransportCallback) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TransportResponse(com.linkedin.r2.transport.common.bridge.common.TransportResponse) SslContext(io.netty.handler.ssl.SslContext) TimeoutAsyncPoolHandle(com.linkedin.r2.transport.http.client.TimeoutAsyncPoolHandle) Test(org.testng.annotations.Test)

Example 2 with Http2AlpnHandler

use of com.linkedin.r2.netty.handler.http2.Http2AlpnHandler in project rest.li by linkedin.

the class TestHttp2AlpnHandler method testWriteBeforeNegotiation.

@Test
public void testWriteBeforeNegotiation() throws Exception {
    SslContext sslContext = Mockito.mock(SslContext.class);
    Http2StreamCodec http2StreamCodec = Mockito.mock(Http2StreamCodec.class);
    Http2AlpnHandler handler = new Http2AlpnHandler(sslContext, http2StreamCodec, true, Integer.MAX_VALUE);
    EmbeddedChannel channel = new EmbeddedChannel(handler);
    // Write should not succeed before negotiation completes
    RequestWithCallback request = Mockito.mock(RequestWithCallback.class);
    Assert.assertFalse(channel.writeOutbound(request));
    Assert.assertFalse(channel.finish());
}
Also used : RequestWithCallback(com.linkedin.r2.transport.common.bridge.common.RequestWithCallback) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SslContext(io.netty.handler.ssl.SslContext) Test(org.testng.annotations.Test)

Example 3 with Http2AlpnHandler

use of com.linkedin.r2.netty.handler.http2.Http2AlpnHandler in project rest.li by linkedin.

the class Http2ChannelInitializer method configureSsl.

/**
 * Configure the pipeline for TLS ALPN negotiation to HTTP/2.
 */
private void configureSsl(NioSocketChannel channel) throws SSLException {
    final SslContext sslCtx = createSslContext();
    final ChannelPromise alpnPromise = channel.newPromise();
    channel.attr(NettyChannelAttributes.INITIALIZATION_FUTURE).set(alpnPromise);
    channel.pipeline().addLast(SessionResumptionSslHandler.PIPELINE_SESSION_RESUMPTION_HANDLER, new SessionResumptionSslHandler(sslCtx, _enableSSLSessionResumption, _sslHandShakeTimeout));
    channel.pipeline().addLast(new Http2AlpnHandler(alpnPromise, createHttp2Settings()));
}
Also used : SessionResumptionSslHandler(com.linkedin.r2.netty.handler.common.SessionResumptionSslHandler) ChannelPromise(io.netty.channel.ChannelPromise) Http2AlpnHandler(com.linkedin.r2.netty.handler.http2.Http2AlpnHandler) JdkSslContext(io.netty.handler.ssl.JdkSslContext) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

SslContext (io.netty.handler.ssl.SslContext)3 RequestWithCallback (com.linkedin.r2.transport.common.bridge.common.RequestWithCallback)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 Test (org.testng.annotations.Test)2 SessionResumptionSslHandler (com.linkedin.r2.netty.handler.common.SessionResumptionSslHandler)1 Http2AlpnHandler (com.linkedin.r2.netty.handler.http2.Http2AlpnHandler)1 TransportResponse (com.linkedin.r2.transport.common.bridge.common.TransportResponse)1 TimeoutAsyncPoolHandle (com.linkedin.r2.transport.http.client.TimeoutAsyncPoolHandle)1 TimeoutTransportCallback (com.linkedin.r2.transport.http.client.TimeoutTransportCallback)1 ChannelPromise (io.netty.channel.ChannelPromise)1 JdkSslContext (io.netty.handler.ssl.JdkSslContext)1