Java Application using Https Connection:“Connection refused error”

时间秒杀一切 提交于 2019-12-12 10:06:58

问题


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

I am passing data over SSL connection(Https). It is working fine in my system.But when I tried to run jar in another system I am getting “Connection refused error”.

Note:Running jar in another system which passes data over http connection is working fine.

I have gone through this link which suggested me to create a “jssecacerts” file and paste it in $JAVA_HOME/jre/lib/security folder of the “another system”. But I am still getting same error. Why is this not working??


回答1:


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

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

it will ask for keystore password default keystore password is "changeit"

You can obtain the public cert by opening your URL in a web browser (e.g chrome) click on the icon at the start of URL -> click certificate information -> details tab -> click export button.


A better approach will be:

  • create a keystore using "keytool" available in JAVA_HOME/bin
  • Import your server's public cert in this keystore.
  • bundle the keystore with your app.
  • make a bat / sh file to run your jar providing a parameter to java command -Djavax.net.ssl.trustStore=/path-to-your-keystore

So every time your app will start it will use this custom keystore. so you don't have to copy jssecacerts file on each system your run your app on.



来源:https://stackoverflow.com/questions/9989340/java-application-using-https-connectionconnection-refused-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!