Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPS using Jersey Client

Tags:

java

jersey

How do I send GET requests using the Jersey Client API to a server which runs on the HTTPS protocol. Is there any sample code that I can use ?

like image 418
Stormshadow Avatar asked Jan 27 '10 08:01

Stormshadow


People also ask

What is jersey client used for?

Jersey is an open source framework for developing RESTFul Web Services. It also has great inbuilt client capabilities.

Is Jersey client thread safe?

Yes, the Jersey 2.1 client is thread safe and it should be thread safe even in the future Jersey version. You can create many WebTarget from one Client instance and invoke many requests on these WebTargets and even more requests on one WebTarget instance in the same time.

What is Jersey client API?

Jersey ClientBuilder. JAX-RS Client API is a designed to allow fluent programming model. To create jersey client follow these steps – Use ClientBuilder. newClient() static method.


1 Answers

Construct your client as such

HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); ClientConfig config = new DefaultClientConfig(); SSLContext ctx = SSLContext.getInstance("SSL"); ctx.init(null, myTrustManager, null); config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx)); Client client = Client.create(config); 

Ripped from this blog post with more details: http://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with

For information on setting up your certs, see this nicely answered SO question: Using HTTPS with REST in Java

like image 108
gmoore Avatar answered Sep 30 '22 04:09

gmoore