HttpsURLConnection

Somshekar C Kadam somkadam76 at gmail.com
Wed Aug 21 13:10:15 UTC 2019


I am newbie to Java.
we have on our environment
Linux kernel 4.9, java 1.8 version using tls 1.2 default


   1. using curl when we give any https link , it returns within 2 seconds
   2. using java program using httpurlconnection class we get 10 seconds or
   more delay.
   3. Even removed some ciphers thought it may take sometime but that is
   not the case.
   4. Trying an alternative to httpurlconnection class apache httpclient,
   having issues compiling and running it, any pointers will help.
   5. Also any pointers or suggestion why we have 10 seconds delay on https
   connection ?
   6. I have tested using oracle java 8 also, same result, also tried
   zulu11 version of java same delay.
   7. Any suggestions would help here thanks in advance
   8. This is being tested on Armv7 board, we see the delay.
   But when I run this in intel machine its just takes max 1 to 2 seconds
   using sam java program.
   So stuck on this.
   9. I am seeing  on ARM lot many seconds wasted on this as shown below
   logs. Where as in Intel I did not see a single reference, seems that is
   something to do with it, need to  look further into it.

   ============
   15033 08:10:27.254816 clock_gettime(CLOCK_MONOTONIC, {4286, 606936331})
   = 0
   15033 08:10:27.255070 clock_gettime(CLOCK_MONOTONIC, {4286, 607189947})
   = 0
   15033 08:10:27.255504 clock_gettime(CLOCK_MONOTONIC, {4286, 607662716})
   = 0
   15033 08:10:27.255924 clock_gettime(CLOCK_MONOTONIC, {4286, 608074100})
   = 0
   ==================================
   10. Even if I try this simple httpsurlconnection java program to print
   content it takes more than 10 seconds on ARM not in intel. Not sure why
   please help

   HttpsClient.java
   ========================
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.security.cert.Certificate;
   import java.io.*;

   import javax.net.ssl.HttpsURLConnection;
   import javax.net.ssl.SSLPeerUnverifiedException;

   public class HttpsClient {

      public static void main(String[] args)
      {
           new HttpsClient().testIt();
      }

      private void testIt(){

         //String https_url = "https://www.google.com/";
         String https_url = "
   https://transparencyreport.google.com/https/overview?hl=en";
         URL url;
         try {

       url = new URL(https_url);
       HttpsURLConnection con = (HttpsURLConnection)url.openConnection();

       //dumpl all cert info
       print_https_cert(con);

       //dump all the content
       print_content(con);

         } catch (MalformedURLException e) {
       e.printStackTrace();
         } catch (IOException e) {
       e.printStackTrace();
         }

      }

      private void print_https_cert(HttpsURLConnection con){

       if(con!=null){

         try {

   System.out.println("Response Code : " + con.getResponseCode());
   System.out.println("Cipher Suite : " + con.getCipherSuite());
   System.out.println("\n");

   Certificate[] certs = con.getServerCertificates();
   for(Certificate cert : certs){
     System.out.println("Cert Type : " + cert.getType());
     System.out.println("Cert Hash Code : " + cert.hashCode());
     System.out.println("Cert Public Key Algorithm : "
                                       +
   cert.getPublicKey().getAlgorithm());
     System.out.println("Cert Public Key Format : "
                                       + cert.getPublicKey().getFormat());
     System.out.println("\n");
   }

   } catch (SSLPeerUnverifiedException e) {
   e.printStackTrace();
   } catch (IOException e){
   e.printStackTrace();
   }

        }

      }

      private void print_content(HttpsURLConnection con){
   if(con!=null){

   try {

     System.out.println("****** Content of the URL ********");
     BufferedReader br =
   new BufferedReader(
   new InputStreamReader(con.getInputStream()));

     String input;

     while ((input = br.readLine()) != null){
        System.out.println(input);
     }
     br.close();

   } catch (IOException e) {
     e.printStackTrace();
   }

          }

      }

   }



   ======================


Regards
Somshekar C Kadam
9036660538
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20190821/f36f0322/attachment.html>


More information about the net-dev mailing list