title: Java SSLHandshakeException with self-signed certificate
body: <p>I am trying to access local https site with self-signed certificate. I modified the hostfile and I assigned an Ip address to my localsite; the code I am using to get to the site:</p>
  
  <pre><code> String httpsURL = "https://test-ssl.com";
      URL myurl = new URL(httpsURL);
      HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
      InputStream ins = con.getInputStream();
      InputStreamReader isr = new InputStreamReader(ins);
      BufferedReader in = new BufferedReader(isr);
  
      String inputLine;
  
      while ((inputLine = in.readLine()) != null)
      {
        System.out.println(inputLine);
      }
  
      in.close();
    }
  </code></pre>
  
  <p>and I am getting this Error Message:</p>
  
  <pre><code>Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
      at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1904)
  </code></pre>
  
  <p>I have imported the self-signed certificate into the keystore using following this command:</p>
  
  <pre><code>keytool -import -alias site-ssl -keystore cacerts -file site-ssl.com.cer
  </code></pre>
  
  <p>Certificate was imported successfully </p>
  
  <p>what am I missing here? </p>