Java Application Using Https Connection: "Connection Failure Error"

I created a jar for my JavaAppliaction. From this application, I connect to the servlet (I am passing the name and password from swing to servlet) to the WebApplicaton (here I am just showing the name and password in the servlet).

I am transferring data over SSL connection (Https). It works fine on my system. But when I tried to run jar on another system, I get a "Connection refused error" message.

Note. Running the jar on another system that transmits data over an http connection works fine.

I went through a link that suggested that I create a jssecacerts file and paste it into $ JAVA_HOME / jre / lib / security in the "other system" folder. But I still get the same error. Why doesn't it work?

+2


source to share


1 answer


One possible solution: try importing the public certificate into the default java keystore.

keytool -importcert -trustcacerts -file "path-to-public-cert" -keystore JAVA_HOME / jre / lib / security / cacerts

it will ask for the default keystore password. Keystore password "changeit"

You can get the public certificate by opening your url in a web browser (like chrome) by clicking the icon at the beginning of the url -> click the certificate information -> details tab -> click the Export button.




The best approach would be:

  • create a keystore using "keytool" available in JAVA_HOME / bin
  • Import your server certificate into this keystore.
  • associate the keystore with your application.
  • create a bat / sh file to run your jar by giving the parameter to java command -Djavax.net.ssl.trustStore = / path-to-your-keystore

This way, every time your app starts, it will use this custom key store. so you don't have to copy the jssecacerts file to every system your application runs on.

+1


source







All Articles