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 ?
Jersey is an open source framework for developing RESTFul Web Services. It also has great inbuilt client capabilities.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With