views:

32

answers:

1

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

A: 

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

SB