/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */

package org.wso2.carbon.transport.http.netty.sender;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpContentCompressor;
import io.netty.handler.codec.http.HttpRequestEncoder;
import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.carbon.transport.http.netty.common.ssl.SSLHandlerFactory;
import org.wso2.carbon.transport.http.netty.config.SenderConfiguration;
import org.wso2.carbon.transport.http.netty.sender.channel.BootstrapConfiguration;

import java.util.concurrent.TimeUnit;

/**
 * A class that responsible for initialize target server pipeline.
 */
public class HTTPClientInitializer extends ChannelInitializer<SocketChannel> {

    private static final Logger log = LoggerFactory.getLogger(HTTPClientInitializer.class);

    private SenderConfiguration senderConfiguration;

    protected static final String HANDLER = "handler";
    private TargetHandler handler;
    private int soTimeOut;

    public HTTPClientInitializer(SenderConfiguration senderConfiguration) {
        this.senderConfiguration = senderConfiguration;
        soTimeOut = BootstrapConfiguration.getInstance().getSocketTimeout();
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // Add the generic handlers to the pipeline
        // e.g. SSL handler
        if (senderConfiguration.getSslConfig() != null) {
            log.debug("adding ssl handler");
            SslHandler sslHandler = new SSLHandlerFactory(senderConfiguration.getSslConfig()).create();
            sslHandler.engine().setUseClientMode(true);
            ch.pipeline().addLast("ssl", sslHandler);
        }
        ch.pipeline().addLast("compressor", new HttpContentCompressor());
        ch.pipeline().addLast("decoder", new HttpResponseDecoder());
        ch.pipeline().addLast("encoder", new HttpRequestEncoder());
        ch.pipeline().addLast("chunkWriter", new ChunkedWriteHandler());
        // TODO: Enable this once timeout is configured in client connector
//        int socketIdleTimeout = senderConfiguration.getSocketIdleTimeout(60000);
//        ch.pipeline().addLast("idleStateHandler",
//                new IdleStateHandler(socketIdleTimeout, socketIdleTimeout, 0, TimeUnit.MILLISECONDS));
        handler = new TargetHandler();
        ch.pipeline().addLast(HANDLER, handler);
    }

    public TargetHandler getTargetHandler() {
        return handler;
    }
}

@@ -1037,58 +1037,8 @@
 er;%0A
-import io.netty.handler.timeout.IdleStateHandler;%0A
 impo
@@ -1324,47 +1324,8 @@
 n;%0A%0A
-import java.util.concurrent.TimeUnit;%0A%0A
 /**%0A

Remove unwanted imports