Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java HttpsURLConnection SSLSocketFactory timeout with trustAllCerts

  1. #1
    Junior Member
    Join Date
    Oct 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java HttpsURLConnection SSLSocketFactory timeout with trustAllCerts

    Using Method-1 to connect works, it trusts all certificates, even self signed certs, but the timeout does not work as well as Method-2

    But when I use Method-2, not all certs are trusted and it fails for self signed certs. I understand that this is because in Method-2 I did not use my sslSocfactory which incorporates my trustAllCerts. I can't figure out how to incorporate my sslSocfactory into Method-2. I've tried a few way but the compile fails.

    //=== my code ===========
    SSLSocket socket = null;
    SSLContext sc = null;
    sc = SSLContext.getInstance("TLS");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.g etSocketFactory());
    SSLSocketFactory sslSocfactory = HttpsURLConnection.getDefaultSSLSocketFactory();

    //--- Method-1 connection -----
    socket = (SSLSocket)sslSocfactory.createSocket(host, port);
    socket.setSoTimeout(timeout);

    //--- Method-2 connection -----
    socket = (SSLSocket)SSLSocketFactory.getDefault().createSoc ket();
    socket.connect(new InetSocketAddress(host, port), timeout); //- This is the timeout that works for my situation
    socket.setSoTimeout(timeout);

  2. #2
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    117
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: Java HttpsURLConnection SSLSocketFactory timeout with trustAllCerts

    I thought the connection was free. You have to buy the certificates? When hooking up the URL sockets connections. Who do you guys pay? What vendor or company? The router I have or use is Gateway. Hawai'i. I think it's certificates are from the University of Hawai'i. Because it is their network.

Similar Threads

  1. Session TimeOut
    By srautpyaa in forum Web Frameworks
    Replies: 0
    Last Post: December 21st, 2012, 04:41 AM
  2. Replies: 1
    Last Post: September 8th, 2011, 01:27 PM
  3. Timeout method
    By kafka82 in forum Loops & Control Statements
    Replies: 1
    Last Post: July 26th, 2011, 04:17 PM
  4. Replies: 1
    Last Post: May 1st, 2011, 10:13 AM
  5. Session Timeout in LDAP
    By retail_deepa in forum Java Servlet
    Replies: 0
    Last Post: August 4th, 2009, 03:26 AM