java - Apache Wink 连接到 https 资源

标签 java web-services rest ssl apache-wink

我从 Apache Wink Web 服务向位于云中的外部资源(我无法将证书放入 JVM)发送请求,我知道当我尝试从浏览器发出请求时,我得到正确答案。

String serviceURL = "https://someurl&ciUser=user&ciPassword=password";

ClientConfig clientConfig = new ClientConfig();
clientConfig.setBypassHostnameVerification(true);

RestClient client = new RestClient(clientConfig);

Resource resource = client.resource(serviceURL); 

但我得到以下异常:

[err] org.apache.wink.client.ClientRuntimeException: java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
[err]   at org.apache.wink.client.internal.ResourceImpl.invoke(ResourceImpl.java:240)
[err]   at org.apache.wink.client.internal.ResourceImpl.invoke(ResourceImpl.java:189)
[err]   at org.apache.wink.client.internal.ResourceImpl.get(ResourceImpl.java:302)

更新

我也试过这个但是得到了同样的错误

String serviceURL = "https://url&ciUser=user&ciPassword=password";

//Perform basic http auth
ClientConfig clientConfig = new ClientConfig();
BasicAuthSecurityHandler basicAuthSecurityHandler = new BasicAuthSecurityHandler("user", "password");
clientConfig.handlers(basicAuthSecurityHandler);

RestClient client = new RestClient(clientConfig);

有没有可能解决这个问题?

最佳答案

尝试以下步骤

  1. 使用我导出的 jks 文件通过 https 运行应用程序。

  2. 使用浏览器查看证书。

  3. 导出并保存到.cer文件

  4. 使用 java keytool 导入它。

这是命令:

keytool -import -trustcacerts -alias localhost -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -file "D:/apache tomcat 6/bin/example.cer"

关于java - Apache Wink 连接到 https 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20611426/

相关文章:

java - 使用 jnetpcap 库提取数据包详细信息

java - 可以动态使用@XmlSeeAlso 吗?

javascript - 使用 Javascript 从 SOAP 中提取数据

java - Tomcat 上的 Jersey REST 服务出现 404 错误

java - Spring Data Rest - 自定义 Json 模式/阿尔卑斯山?

java - Repaint() 方法不会重新绘制

java - AsyncTask 一段时间后停止

c# - 沟通 Java 和 C#

java - 使用所需网络适配器的 Web 服务调用

python - Django rest framework permission_classes of ViewSet 方法