使用Https连接的Java应用程序:“连接被拒绝错误” [英] Java Application using Https Connection:"Connection refused error"

查看:569
本文介绍了使用Https连接的Java应用程序:“连接被拒绝错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的JavaAppliaction创建了一个jar.From这个应用程序我在WebApplicat中连接到servlet(我将名称和密码从swing传递给servlet)(这里我只是在servlet中显示名称和密码)。 / p>

我通过SSL连接(Https)传递数据。它在我的系统中工作正常。但是当我尝试在另一个系统中运行jar时,我收到Connection refused error。



注意:在另一个系统中运行jar通过http连接传递数据工作正常。



我已经完成了这个链接,建议我创建一个jssecacerts文件并将其粘贴到$ JAVA_HOME / jre中/ lib /安全文件夹中的另一个系统。但我仍然得到同样的错误。为什么这不起作用?

解决方案

一种可能的解决方案:尝试使用公共证书导入java默认密钥库。



keytool -importcert -trustcacerts -filepath-to-public-cert-keystore JAVA_HOME / jre / lib / security / cacerts



它将要求密钥库密码默认密钥库密码为changeit



您可以通过在Web浏览器中打开URL来获取公共证书(例如chrome)单击URL开头的图标 - >单击证书信息 - >详细信息选项卡 - >单击导出
按钮。






更好的方法是:




  • 使用JAVA_HOME / bin中提供的keytool创建密钥库

  • 在此密钥库中导入服务器的公共证书。

  • 将密钥库与您的应用捆绑在一起。

  • 制作一个bat / sh文件来运行你的jar,为java命令提供参数-Djavax.net.ssl.trustStore = / path-to-your-keystore



因此,每当您的应用启动时,它都将使用此自定义密钥库。因此,您无需在运行应用程序的每个系统上复制jssecacerts文件。


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??

解决方案

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连接的Java应用程序:“连接被拒绝错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆