Apache Commons Http Client - 注册客户端特定协议
我正在开发一个旨在集成到其他应用程序中的库。我必须与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
升级到 HttpComponents 4 并保留客户端 3.x。
Upgrade to HttpComponents 4 and leave client 3.x alone.