def start(request_params)
      # close the previous if exists
      finish
      # create new connection
      @server         = request_params[:server]
      @port           = request_params[:port]
      @protocol       = request_params[:protocol]
      @proxy_host     = request_params[:proxy_host]
      @proxy_port     = request_params[:proxy_port]
      @proxy_username = request_params[:proxy_username]
      @proxy_password = request_params[:proxy_password]
      
      SECURITY_PARAMS.each do |param_name|
        @params[param_name] = request_params[param_name]
      end

      @logger.info("Opening new #{@protocol.upcase} connection to #@server:#@port")

      @logger.info("Connecting to proxy #{@proxy_host}:#{@proxy_port} with username" +
                   " #{@proxy_username.inspect}") unless @proxy_host.nil?

      @http = Net::HTTP.new(@server, @port, @proxy_host, @proxy_port, @proxy_username,
                            @proxy_password)
      @http.open_timeout = get_param(:http_connection_open_timeout, request_params)
      @http.read_timeout = get_param(:http_connection_read_timeout, request_params)

      if @protocol == 'https'
        verifyCallbackProc = Proc.new{ |ok, x509_store_ctx|
          # List of error codes: http://www.openssl.org/docs/apps/verify.html
          code = x509_store_ctx.error
          msg = x509_store_ctx.error_string
          if request_params[:fail_if_ca_mismatch] && code != 0
            false
          else
            true
          end
        }
        @http.use_ssl = true

        ca_file = get_param(:ca_file)
        if ca_file && File.exists?(ca_file)
          # Documentation for 'http.rb':
          # : verify_mode, verify_mode=((|mode|))
          #    Sets the flags for server the certification verification at
          #    beginning of SSL/TLS session.
          #    OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER is acceptable.
          #
          # KHRVI: looks like the constant VERIFY_FAIL_IF_NO_PEER_CERT is not acceptable
          @http.verify_callback = verifyCallbackProc
          @http.ca_file= ca_file
          @http.verify_mode = get_param(:use_server_auth) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
          # The depth count is 'level 0:peer certificate', 'level 1: CA certificate', 'level 2: higher level CA certificate', and so on.
          # Setting the maximum depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9, allowing for the peer certificate and additional 9 CA certificates.
          @http.verify_depth    = 9
        else
          @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        end
        
        # CERT
        cert_file = get_param(:cert_file, request_params)
        cert      = File.read(cert_file) if cert_file && File.exists?(cert_file)
        cert    ||= get_param(:cert, request_params)
        # KEY
        key_file  = get_param(:key_file,  request_params)
        key       = File.read(key_file) if key_file && File.exists?(key_file)
        key     ||= get_param(:key,  request_params)
        if cert && key
          begin
            @http.verify_callback = verifyCallbackProc
            @http.cert = OpenSSL::X509::Certificate.new(cert)
            @http.key  = OpenSSL::PKey::RSA.new(key)
          rescue OpenSSL::PKey::RSAError, OpenSSL::X509::CertificateError => e
            @logger.error "##### Error loading SSL client cert or key: #{e.message} :: backtrace #{e.backtrace}"
            raise e
          end
        end
      end
      # open connection
      @http.start
    end
def start(request_params)
      # close the previous if exists
      finish
      # create new connection
      @server         = request_params[:server]
      @port           = request_params[:port]
      @protocol       = request_params[:protocol]
      @proxy_host     = request_params[:proxy_host]
      @proxy_port     = request_params[:proxy_port]
      @proxy_username = request_params[:proxy_username]
      @proxy_password = request_params[:proxy_password]
      
      SECURITY_PARAMS.each do |param_name|
        @params[param_name] = request_params[param_name]
      end

      @logger.info("Opening new #{@protocol.upcase} connection to #@server:#@port")

      @logger.info("Connecting to proxy #{@proxy_host}:#{@proxy_port} with username" +
                   " #{@proxy_username.inspect}") unless @proxy_host.nil?

      @http = Net::HTTP.new(@server, @port, @proxy_host, @proxy_port, @proxy_username,
                            @proxy_password)
      @http.open_timeout = get_param(:http_connection_open_timeout, request_params)
      @http.read_timeout = get_param(:http_connection_read_timeout, request_params)

      if @protocol == 'https'
        verifyCallbackProc = Proc.new{ |ok, x509_store_ctx|
          # List of error codes: http://www.openssl.org/docs/apps/verify.html
          code = x509_store_ctx.error
          msg = x509_store_ctx.error_string
          if request_params[:fail_if_ca_mismatch] && code != 0
            false
          else
            true
          end
        }
        @http.use_ssl = true

        ca_file = get_param(:ca_file)
        if ca_file && File.exists?(ca_file)
          # Documentation for 'http.rb':
          # : verify_mode, verify_mode=((|mode|))
          #    Sets the flags for server the certification verification at
          #    beginning of SSL/TLS session.
          #    OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER is acceptable.
          #
          # KHRVI: looks like the constant VERIFY_FAIL_IF_NO_PEER_CERT is not acceptable
          @http.verify_callback = verifyCallbackProc
          @http.ca_file= ca_file
          @http.verify_mode = get_param(:use_server_auth) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
          # The depth count is 'level 0:peer certificate', 'level 1: CA certificate', 'level 2: higher level CA certificate', and so on.
          # Setting the maximum depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9, allowing for the peer certificate and additional 9 CA certificates.
          @http.verify_depth    = 9
        else
          @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        end
        
        # CERT
        cert_file = get_param(:cert_file, request_params)
        cert      = File.read(cert_file) if cert_file && File.exists?(cert_file)
        cert    ||= get_param(:cert, request_params)
        # KEY
        key_file  = get_param(:key_file,  request_params)
        key       = File.read(key_file) if key_file && File.exists?(key_file)
        key     ||= get_param(:key,  request_params)
        if cert && key
          begin
            @http.verify_callback = verifyCallbackProc
            @http.cert = OpenSSL::X509::Certificate.new(cert)
            @http.key  = OpenSSL::PKey::RSA.new(key)
          rescue OpenSSL::PKey::RSAError, OpenSSL::X509::CertificateError => e
            @logger.error "##### Error loading SSL client cert or key: #{e.message} :: backtrace #{e.backtrace}"
            raise e
          end
        end
      end
      # open connection
      @http.start
    end
Start a fresh connection. The object closes any existing connection and
 opens a new one.