Aaron Johnson Now with 50% less caffeine!

Posted
2 October 2007 @ 9am

Tagged
J2EE, Open Source, Systems Administration

Using a custom socket factory with HttpClient

The documentation on how to use a custom socket factory in HttpClient is actually pretty good, but there’s one thing they don’t make very clear. If you want to specify a per-host socket factory like this:

Protocol p = new Protocol("https", new MySSLSocketFactory(), 443);
HttpClient httpclient = new HttpClient();
httpclient.getHostConfiguration().setHost("example.com", 443, p);
GetMethod httpget = new GetMethod("/mypath");

you must specify a path and not the full URL in the GetMethod constructor. If you don’t, in other words, if you use a constructor like this:

GetMethod httpget = new GetMethod("https://example.com/mypath");

the custom socket factory you specified in the host configuration will not be used.


No Comments Yet


There are no comments yet. You could be the first!

Leave a Comment

Links: 9-26-2007 Creating a Firefox Sidebar for Clearspace: Part I