Ok, I think I may have found the answers to some of my questions. I'm
a little panicked, and I could have spent another hour looking at list
archives to get some of the basic answers. My apologies.
Here's what I believe:
1) I happen to need a maven dependency on the jersey-apache-client:
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client</artifactId>
<version>1.0.3.1</version>
</dependency>
2) next install a Protocol socket factory that all HttpClient
instances will use when the protocol is https. Do this before you
create the first HttpClient:
Protocol easyhttps = new Protocol("https", new
EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyhttps);
where, per the link below, I'm using what I believe is sorta well-
known EasySSLProtocolSocketFactory code
3) next, create the client for Jersey use:
Client client;
client = new ApacheHttpClient();
WebResource.Builder reqBuilder =
client.resource(uri).accept("text/plain");
...
And away we go.
Question: will this actually work? That is, will Jersey actually get
an https client that draws from this Protocol factory? That question
is not loaded; this code will work with plain vanilla HttpClient
code. I'm just not sure it will work with how Jersey gets that
underlying client.
Question: I'd sorta like to not install an https protocol factory for
all of HttpClient use. One can create clients on a per instance basis
that use this specific protocol factory. See
http://juliusdavies.ca/commons-ssl/javadocs/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.html
. Can I actually do this with the client ApacheHttpClient? I
can't see any way to get at the underlying HttpClient to do the
equivalent of
client.getHostConfiguration().setHost("localhost", 443, easyhttps);
per the javadoc in the link above.
Whew. Thanks for reading this far.
Mark
On Sep 17, 2009, at 6:41 PM, Mark Petrovic wrote:
> Hi.
>
> I have a need to create a Jersey client that is based on the Apache
> HttpClient. Furthermore, I need to be able to provide a custom SSL
> protocol factory so that this http client can pass client SSL
> authentication.
>
> I know I've seen sample code that shows how to use HttpClient in a
> Jersey client app, but I can't seem to find it at the moment. Once
> I have that client, I'm hoping I can wedge something like this SSL
> protocol factory onto it:
>
> http://www.jdocs.com/httpclient/3.0.1/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.html
>
> Thanks much.
>
>
> --
> Mark Petrovic
> mark_at_petrovic.org
> http://www.petrovic.org
>
>
>
>
>
--
Mark Petrovic
mark_at_petrovic.org
http://www.petrovic.org