Archives for 

JAX-RS

REST Based Web Services

RESTFul Web Service Client Example

In the previous section  we have seen  a sample web service . In this section we can write a simple client for the service we developed

Restful Web Service Client example

RESTFul Service Client for a GET Service

Let us start with a client for a GET service.Once completion we can develop the same for a POST,PUT and DELETE  services

Before starting the  coding part of client , publish the web service we already developed  and start the server.

There are many libraries available for us to develop RESTful service clients. We can use the Apache Http Client libraries or the  JAX-RS implementation specific libraries.In our example we are using Apache Http Client components.We can download it from the Apache web site.We are using version 4.3 in our example. Extract and put the jar files in the lib folder to our project path.

The jars are :

commons-codec-1.6

commons-logging-1.1.3

fluent-hc-4.3.4

httpclient-4.3.4

httpclient-cache-4.3.4

httpcore-4.3.2

httpmime-4.3.4

RestClientSample.java

Now run the code , and the output would be the String message

RESTFul Service Client for a POST Service

Now add a simple POST  service also to the SampleService.java we already developed.So the SampleService.java would be

Compile and republish it to server.Now we need to develop a client for the new service also .Modify the Client class as shown below and run it.

It would display the output of both the services.

Related Discussions

Web Services – An Over view

JAX-WS Tutorial

JAX-RS Tutorial