HttpComponents Custom SSLSocketFactory

In the example at http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientCustomSSL.java

SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore); 

Should an instance of SSLSocketFactory use my own trust store, but when I try to create my project, I get an error

 javax.net.ssl.SSLSocketFactory is abstract; cannot be intantiated 

Is the example obsolete? Does it work for other people?

+4
source share
1 answer

This is org.apache.http.conn.ssl.SSLSocketFactory , which you should use, not javax.net.ssl.SSLSocketFactory (see the import directive in the example file that you use).

Note that the former has constructors that can use the latter if you already have code for this. However, you usually get a custom javax.net.ssl.SSLSocketFactory from SSLContext , so in this case you can use the SSLContext constructor.

+11
source

All Articles