Apache Commons Http Client - 注册客户端特定协议

发布于 2024-09-25 13:28:35 字数 1006 浏览 1 评论 0原文

我正在开发一个旨在集成到其他应用程序中的库。我必须与 https 服务器通信,并且我正在使用 apache commons HttpClient 3.1。我有自己的密钥库,需要注册 协议通过:Protocol.registerProtocol。我想知道是否有一种方法可以为我的特定客户端实例而不是静态地注册它 - 这样我就不会弄乱任何其他实例,也没有人会弄乱我。

我看到一些可以获取客户端 HostConfiguration 并调用 setHost,带有协议,但它似乎无法正常工作。我像这样注册它:

HostConfiguration config = client.getHostConfiguration();
config.setHost(remoteUrl.getHost(), remoteUrl.getPort(), new Protocol("https", new MyProtocolSocketFactory(), 443));

但是当尝试建立连接时,SSL 握手失败,而在使用具有相同参数的 Protocol.registerProtocol 时它可以工作。失败是标准的:

由以下原因引起:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径

I'm working on a library that is meant to be integrated in other applications. I have to communicate with a https server, and I'm using apache commons HttpClient 3.1. I have my own keystore and need to register a Protocol via: Protocol.registerProtocol. I was wondering if there was a way to register this for my specific instance of the client rather than statically - this way I don't mess up any other instances and nobody messes me up.

I saw something where I can get the clients HostConfiguration and call setHost, with a protocol, but it doesn't appear to work properly. I'm registering it like:

HostConfiguration config = client.getHostConfiguration();
config.setHost(remoteUrl.getHost(), remoteUrl.getPort(), new Protocol("https", new MyProtocolSocketFactory(), 443));

but when trying to make a connection, the SSL handshake fails, while it works when using Protocol.registerProtocol with the same parameters. The failure is the standard:

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花桑 2024-10-02 13:28:35

升级到 HttpComponents 4 并保留客户端 3.x。

Upgrade to HttpComponents 4 and leave client 3.x alone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文