Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:55:09+00:00 2026-05-30T22:55:09+00:00

i have set up a https connection between the server and the client, where

  • 0

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.

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");
}

But I am getting the following exception.

java.lang.IllegalStateException: connection not yet open

I thought handshake should take place as soon as theurl.openconnection() method in called.
What is the problem here?
The Exception is thrown line number ‘#1′(see comments in the code above)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:55:10+00:00Added an answer on May 30, 2026 at 10:55 pm

    you’re trying to connect to a self signed certificate host. Follow the instructions for Option 2 of the answer from this answer, which should allow you connect.

    I replaced the connection.setDoOutput() with a connection.connect() and the code worked correctly for me.

    Do not use this mechanism for anything other than testing – you should be using a validly signed certificate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Rest API that requires client certificate authentication. The API is used
I have set up transactional replication between two SQL Servers on different ends of
I have a web-based application and a client, both written in Java. For what
I have a ubuntu server which I've locked down to only HTTP, HTTPS and
I have set up Jenkins with the Github plugin on my test server. I
Https Connection subdomain Im Looking to set up my wickets 1.5 application with HTTPS.
I have Charles Proxy set up to look at outgoing https requests, and I
I have a XIB set up like in this screenshot: alt text http://emberapp.com/jxpx777/images/interface-builder/sizes/m.png File's
For example I have site http://localhost/site In IIS I set that 404 error causes
We have set up a system where notifications get sent to a user with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.