Hi,
As Roland had previously suggested I took latest HTTPClient Version (3.1)
and used it in our desktop app which connects to server with https
(StrictSSLProtocolSocketFactory impl.) through Proxy server... To use proxy
i had to create my own socketfactory which will override createSocket()
method and it will set new Socket with Proxy.NO_PROXY.
heres my socetfactory implementation.
public class AsiteSocketFactory extends StrictSSLProtocolSocketFactory
implements ProtocolSocketFactory {
public AsiteSocketFactory() throws
java.security.GeneralSecurityException, java.io.IOException{
super(true);
}
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException {
return new Socket(host,port);
}
public Socket createSocket(String host, int port, InetAddress
localAddress, int localPort) throws IOException, UnknownHostException {
return new Socket(host,port,localAddress,localPort);
}
public Socket createSocket(String host, int port, InetAddress
localAddress, int localPort, HttpConnectionParams params)
throws IOException, UnknownHostException, ConnectException {
Socket rval;
if (params == null) {
throw new IllegalArgumentException("Parameters may not be
null");
}
rval = new Socket(Proxy.NO_PROXY);
SocketAddress localaddr = new
InetSocketAddress(localAddress, localPort);
SocketAddress remoteaddr = new InetSocketAddress(host, port);
rval.bind(localaddr);
rval.connect(remoteaddr);
return rval;
}
}
I also need StrictSSLProtocol impl so i extended that class in factory and
called Super(true) ....
I create HTTPClient object like this... httpClient is a static object...
MultiThreadedHttpConnectionManager connectionManager = new
MultiThreadedHttpConnectionManager();
httpClient = new HttpClient(connectionManager);
Protocol stricthttps = new Protocol("https", new AsiteSocketFactory(), 443);
Protocol.registerProtocol("http", stricthttps);
httpClient.getHostConfiguration().setHost(SystemConstants.connectionHostName,
443, stricthttps);
httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
Now when i run this same code on Production Box (https configured) even if i
pass URL in Method (PostMethod postMethod = new PostMethod(requestUrl);)
like "http://bim.xyz.com" it works fine... I got an http request on server
log with this....
But if i run same thing on another server which is run on http only(internal
testing purpose), i get
sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target
does this mean that server is sending the certificate even if i connect by
URL "http" in PostMethod obect???
Do i need to create httpclient object differently for http requests??? then
I will also have to remove my sockectfactory from the Protocol constructor
because it is extending StrictSSLProtSockFactory.....
Please Help..
Thanks
Nitya