public static ProxyRouteState create( ApplicationState state, ProxyRouteConfig config, ProxyHandler handler) { List<ClientConfig> configs = config.clientConfigs(); List<ClientState> clientStates = configs .stream() .map(clientConfig -> new ClientState(clientConfig, state.workerGroup())) .collect(Collectors.toList()); return new ProxyRouteState(config, handler, clientStates); }
public ClientState( ClientChannelConfiguration channelConfig, ClientConfig config, InetSocketAddress remote, boolean enableTls) { this(channelConfig, config, remote, sslContext(enableTls, config)); }
@Override public Client createClient(ChannelHandlerContext ctx, ClientConfig config) { ClientState clientState = new ClientState(channelConfig(ctx), config); ClientChannelInitializer clientChannelInit = new ClientChannelInitializer(clientState, () -> new ProxyBackendHandler(ctx), getTracing()); ClientConnectionManager connManager = new ClientConnectionManager(clientState, clientChannelInit); Client client = new Client(clientState, connManager); ctx.channel().closeFuture().addListener(f -> clientPool.release(client)); log.debug("creating client"); return client; }
public ClientState(ClientChannelConfiguration channelConfig, ClientConfig config) { this(channelConfig, config, config.remote(), sslContext(config.isTlsEnabled(), config)); }
private Client newClient(XioTracing tracing) { val channelConfig = ChannelConfiguration.clientConfig(1, "client-tracing-test-worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.baseClient")); val clientState = new ClientState(channelConfig, clientConfig); ClientChannelInitializer clientChannelInit = new ClientChannelInitializer(clientState, ApplicationHandler::new, tracing); ClientConnectionManager connManager = new ClientConnectionManager(clientState, clientChannelInit); return new Client(clientState, connManager); }
@Test public void testDisableSsl() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.basicClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(SslHandler.class); assertNull(result); }
@Test public void testDisabledTracing() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.basicClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have disabled Tracing the tracing returns null for newClientHandler when(tracing.newClientHandler()).thenReturn(null); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(HttpClientTracingHandler.class); assertEquals(result, null); }
private ClientConnectionManager subjectFactory(boolean shouldSucceed) { ClientChannelConfiguration channelConfiguration = new ClientChannelConfiguration(new NioEventLoopGroup(), NioSocketChannel.class); File configFile; if (shouldSucceed) { configFile = new File("src/test/resources/ClientConnectionManagerTestSucceed.conf"); } else { configFile = new File("src/test/resources/ClientConnectionManagerTestFail.conf"); } Config config = ConfigFactory.parseFile(configFile); ClientConfig clientConfig = ClientConfig.from(config); ClientState clientState = new ClientState(channelConfiguration, clientConfig); ClientChannelInitializer clientChannelInit = new ClientChannelInitializer(clientState, () -> new HollowChannelHandler(), null); return new ClientConnectionManager(clientState, clientChannelInit); }
@Test public void testEnableIdleTimeout() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.idleEnabledClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(XioIdleDisconnectHandler.class); assertNotNull(result); } }
@Test public void testEnableSsl() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.sslClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(SslHandler.class); assertNotNull(result); }
@Test public void testDisableIdleTimeout() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.idleDisabledClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(XioIdleDisconnectHandler.class); assertNull(result); }
@Test public void testEnabledTracing() throws Exception { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.basicClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(HttpClientTracingHandler.class); assertEquals(result, tracingHandler); }
@Override public Client createClient(ChannelHandlerContext ctx, ClientConfig config) { ClientState clientState = new ClientState(channelConfig(ctx), config); ClientChannelInitializer clientChannelInit = new ClientChannelInitializer( clientState, () -> new ProxyBackendHandler(ctx), getTracing()); ClientConnectionManager connManager = new ClientConnectionManager(clientState, clientChannelInit); return new Client(clientState, connManager); } };