Search in sources :

Example 1 with HttpClientChannelHandler

use of org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler 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

ChannelHandlerFactory (org.apache.camel.component.netty.ChannelHandlerFactory)1 HttpClientChannelHandler (org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler)1 ChannelHandler (org.jboss.netty.channel.ChannelHandler)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 HttpClientCodec (org.jboss.netty.handler.codec.http.HttpClientCodec)1 SslHandler (org.jboss.netty.handler.ssl.SslHandler)1 ReadTimeoutHandler (org.jboss.netty.handler.timeout.ReadTimeoutHandler)1