简体   繁体   English

使用Https连接的Java应用程序:“连接被拒绝错误”

[英]Java Application using Https Connection:“Connection refused error”

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). 我为JavaAppliaction创建了一个jar。从这个应用程序我连接到WebApplicaton中的servlet(我将名称和密码从swing传递到servlet)(这里我只是在servlet中显示名称和密码)。

I am passing data over SSL connection(Https). 我正在通过SSL连接(Https)传递数据。 It is working fine in my system.But when I tried to run jar in another system I am getting “Connection refused error”. 它在我的系统中运行正常。但是,当我尝试在另一个系统中运行jar时,出现“连接被拒绝错误”。

Note:Running jar in another system which passes data over http connection is working fine. 注意:在另一个通过http连接传递数据的系统中运行jar可以正常工作。

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”. 我浏览了此链接 ,该链接建议我创建一个“ jssecacerts”文件并将其粘贴到“另一个系统”的$ JAVA_HOME / jre / lib / security文件夹中。 But I am still getting same error. 但是我仍然遇到同样的错误。 Why is this not working?? 为什么这不起作用?

One possible solution: Try importing the public certificate into java default keystore using. 一种可能的解决方案:尝试使用将公共证书导入到Java默认密钥库中。

keytool -importcert -trustcacerts -file "path-to-public-cert" -keystore JAVA_HOME/jre/lib/security/cacerts keytool -importcert -trustcacerts-文件“公共证书路径” -keystore JAVA_HOME / jre / lib / security / cacerts

it will ask for keystore password default keystore password is "changeit" 它将要求输入密钥库密码,默认密钥库密码为“ changeit”

You can obtain the public cert by opening your URL in a web browser (eg chrome) click on the icon at the start of URL -> click certificate information -> details tab -> click export button. 您可以通过在Web浏览器(例如chrome)中打开URL来获取公共证书,单击URL开头的图标->单击证书信息->详细信息选项卡->单击导出按钮。


A better approach will be: 更好的方法是:

  • create a keystore using "keytool" available in JAVA_HOME/bin 使用JAVA_HOME / bin中可用的“ keytool”创建密钥库
  • 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 制作一个bat / sh文件来运行jar,为java命令-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. 因此您不必在运行应用程序的每个系统上都复制jssecacerts文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM