Search in sources :

Example 1 with HttpClientCodec

use of org.jboss.netty.handler.codec.http.HttpClientCodec in project databus by linkedin.

the class DummyHttpRequestHandler method setupClient.

private void setupClient() {
    _clientBootstrap = new ClientBootstrap(new DefaultLocalClientChannelFactory());
    _clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline clientPipeline = pipeline();
            clientPipeline.addLast("client logger 1", new LoggingHandler("client logger 1", InternalLogLevel.DEBUG, true));
            clientPipeline.addLast("codec", new HttpClientCodec());
            clientPipeline.addLast("aggregator", new FooterAwareHttpChunkAggregator(1000000));
            _responseHandler = new SimpleHttpResponseHandler();
            clientPipeline.addLast("handler", _responseHandler);
            clientPipeline.addLast("client logger 5", new LoggingHandler("client logger 5", InternalLogLevel.DEBUG, true));
            return clientPipeline;
        }
    });
}
Also used : LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) FooterAwareHttpChunkAggregator(com.linkedin.databus.core.test.netty.FooterAwareHttpChunkAggregator) DefaultLocalClientChannelFactory(org.jboss.netty.channel.local.DefaultLocalClientChannelFactory) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 2 with HttpClientCodec

use of org.jboss.netty.handler.codec.http.HttpClientCodec in project databus by linkedin.

the class SimpleTestHttpClient method createPipeline.

private ChannelPipeline createPipeline() throws Exception {
    ChannelPipeline clientPipeline = pipeline();
    clientPipeline.addLast("client logger 1", new LoggingHandler("client logger 1", InternalLogLevel.DEBUG, true));
    clientPipeline.addLast("codec", new HttpClientCodec());
    clientPipeline.addLast("aggregator", new FooterAwareHttpChunkAggregator(1000000));
    _responseHandler = new SimpleHttpResponseHandler();
    clientPipeline.addLast("handler", _responseHandler);
    clientPipeline.addLast("client logger 5", new LoggingHandler("client logger 5", InternalLogLevel.DEBUG, true));
    return clientPipeline;
}
Also used : LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 3 with HttpClientCodec

use of org.jboss.netty.handler.codec.http.HttpClientCodec in project databus by linkedin.

the class GenericHttpClientPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    if (_channelGroup != null)
        pipeline.addLast("auto group register ", new ConnectionChannelRegistrationHandler(_channelGroup));
    if (Logger.getRootLogger().isTraceEnabled()) {
        LOG.debug("Adding Netty tracing");
        pipeline.addLast("netty client traffic", new LoggingHandler("netty client traffic", InternalLogLevel.DEBUG, true));
    }
    if (null != _containerStatsCollector) {
        pipeline.addLast("inbound statistics collector", new InboundContainerStatisticsCollectingHandler(_containerStatsCollector));
    }
    ExtendedReadTimeoutHandler readTimeoutHandler = new ExtendedReadTimeoutHandler("client call ", _timeoutTimer, _readTimeoutMs, true);
    pipeline.addLast(READ_TIMEOUT_HANDLER_NAME, readTimeoutHandler);
    pipeline.addLast("codec", new HttpClientCodec());
    pipeline.addLast("http logger", new HttpRequestLoggingHandler());
    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());
    //pipeline.addLast("handler", new GenericHttpResponseHandler(_responseProcessor, _keepAlive));
    pipeline.addLast("handler", _handler);
    //add a handler to deal with write timeouts
    pipeline.addLast("client request write timeout handler", new ExtendedWriteTimeoutHandler("netty client traffic", _timeoutTimer, _writeTimeoutMs, true));
    return pipeline;
}
Also used : ConnectionChannelRegistrationHandler(com.linkedin.databus2.core.container.netty.ConnectionChannelRegistrationHandler) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ExtendedReadTimeoutHandler(com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler) ExtendedWriteTimeoutHandler(com.linkedin.databus2.core.container.ExtendedWriteTimeoutHandler) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) InboundContainerStatisticsCollectingHandler(com.linkedin.databus2.core.container.netty.InboundContainerStatisticsCollectingHandler) HttpContentDecompressor(org.jboss.netty.handler.codec.http.HttpContentDecompressor)

Example 4 with HttpClientCodec

use of org.jboss.netty.handler.codec.http.HttpClientCodec in project databus by linkedin.

the class TestHttpResponseProcessor method createChannelFuture.

static ChannelFuture createChannelFuture(final GenericHttpResponseHandler responseHandler, int port) {
    ClientBootstrap client = new ClientBootstrap(new NioClientSocketChannelFactory(BOSS_POOL, IO_POOL));
    client.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new LoggingHandler(InternalLogLevel.DEBUG), new HttpClientCodec(), new LoggingHandler(InternalLogLevel.DEBUG), responseHandler);
        }
    });
    final ChannelFuture connectFuture = client.connect(new InetSocketAddress("localhost", port));
    return connectFuture;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) InetSocketAddress(java.net.InetSocketAddress) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) DatabusException(com.linkedin.databus2.core.DatabusException) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 5 with HttpClientCodec

use of org.jboss.netty.handler.codec.http.HttpClientCodec in project camel by apache.

the class HttpClientPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    SslHandler sslHandler = configureClientSSLOnDemand();
    if (sslHandler != null) {
        // must close on SSL exception
        sslHandler.setCloseOnSSLException(true);
        LOG.debug("Client SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }
    pipeline.addLast("http", new HttpClientCodec());
    List<ChannelHandler> decoders = producer.getConfiguration().getDecoders();
    for (int x = 0; x < decoders.size(); x++) {
        ChannelHandler decoder = decoders.get(x);
        if (decoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
        }
        pipeline.addLast("decoder-" + x, decoder);
    }
    List<ChannelHandler> encoders = producer.getConfiguration().getEncoders();
    for (int x = 0; x < encoders.size(); x++) {
        ChannelHandler encoder = encoders.get(x);
        if (encoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
        }
        pipeline.addLast("encoder-" + x, encoder);
    }
    if (producer.getConfiguration().getRequestTimeout() > 0) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout());
        }
        ChannelHandler timeout = new ReadTimeoutHandler(producer.getEndpoint().getTimer(), producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS);
        pipeline.addLast("timeout", timeout);
    }
    // handler to route Camel messages
    pipeline.addLast("handler", new HttpClientChannelHandler(producer));
    return pipeline;
}
Also used : HttpClientChannelHandler(org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler) ChannelHandlerFactory(org.apache.camel.component.netty.ChannelHandlerFactory) ReadTimeoutHandler(org.jboss.netty.handler.timeout.ReadTimeoutHandler) HttpClientChannelHandler(org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Aggregations

ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)5 HttpClientCodec (org.jboss.netty.handler.codec.http.HttpClientCodec)5 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)4 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)2 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)2 FooterAwareHttpChunkAggregator (com.linkedin.databus.core.test.netty.FooterAwareHttpChunkAggregator)1 SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 ExtendedReadTimeoutHandler (com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler)1 ExtendedWriteTimeoutHandler (com.linkedin.databus2.core.container.ExtendedWriteTimeoutHandler)1 HttpRequestLoggingHandler (com.linkedin.databus2.core.container.HttpRequestLoggingHandler)1 ConnectionChannelRegistrationHandler (com.linkedin.databus2.core.container.netty.ConnectionChannelRegistrationHandler)1 InboundContainerStatisticsCollectingHandler (com.linkedin.databus2.core.container.netty.InboundContainerStatisticsCollectingHandler)1 InetSocketAddress (java.net.InetSocketAddress)1 ChannelHandlerFactory (org.apache.camel.component.netty.ChannelHandlerFactory)1 HttpClientChannelHandler (org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 ChannelHandler (org.jboss.netty.channel.ChannelHandler)1 DefaultLocalClientChannelFactory (org.jboss.netty.channel.local.DefaultLocalClientChannelFactory)1 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)1