Jersey provides a client API to invoke a JAX-RS web service. In this section we shall create a REST client to test the JAX-RS web service. Create a Java class, TestClient.java
. Select File | New | Other. Select Java | Class in the New wizard. In the
New Java Class window specify a source folder (EclipseJAX-RS/src
is the default) in the Source folder field, specify a package name (jaxrs
) in the Package field, and specify a class name (TestClient
) in the Name field. Click on Next, as shown in the following screenshot:
In TestClient.java
we invoke the resource methods using the Jersey client API. The com.sun.jersey.api.client.Client
class is the main class for creating resource instances. First, create a ClientConfig
object, which represents the client configuration such as property names and features that may be used by the Client
object, using the constructor
for DefaultClientConfig
. Create a Client
instance from ClientConfig
using the static method create...