title: Exception when printing the server certificate details
body: <p>i have set up a https connection between the server and the client, where the client is a java program and the server is a servlet. I have used the following code to print the certificate details from the server.<br></p>
  
  <pre><code>URL url = new URL("https://localhost:8443/cert");
  HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
  connection.setSSLSocketFactory(sslsocketfactory);
  
  connection.setDoOutput(true);
  if(connection!=null){
      Certificate[] certs = connection.getServerCertificates();// #1 
  
      System.out.println("Cert Type : " + certs[0].getType());
      System.out.println("Cert Hash Code : " + certs[0].hashCode());
      System.out.println("Cert Public Key Algorithm : " + certs[0].getPublicKey().getAlgorithm());
      System.out.println("Cert Public Key Format : " + certs[0].getPublicKey().getFormat());
      System.out.println("\n");
  }
  </code></pre>
  
  <p>But I am getting the following exception.</p>
  
  <pre><code>java.lang.IllegalStateException: connection not yet open
  </code></pre>
  
  <p>I thought handshake should take place as soon as theurl.openconnection() method in called.
  What is the problem here?<br>
  The Exception is thrown line number '#1'(see comments in the code above)</p>