You are previewing RESTful Java with JAX-RS.

RESTful Java with JAX-RS

Cover of RESTful Java with JAX-RS by Bill Burke Published by O'Reilly Media, Inc.
O'Reilly logo

RESTEasy Client Framework

RESTEasy[16] is the JBoss (Red Hat) JAX-RS implementation. As with and Apache HTTP Client, it provides a programmatic API to submit HTTP requests with the additional feature of it being JAX-RS-aware. To use the API, you create org.jboss.resteasy.client.ClientRequest objects. You build up the request using the following constructor and methods:

public class ClientRequest {
   public ClientRequest(String uriTemplate) {}

   public ClientRequest followRedirects(boolean follow) {}
   public ClientRequest accept(String accept) {}
   public ClientRequest formParameter(String parameterName,
                                        Object value) {}
   public ClientRequest queryParameter(String parameterName,
                                         Object value) {}
   public ClientRequest matrixParameter(String parameterName,
                                           Object value) {}
   public ClientRequest header(String headerName, Object value) {}
   public ClientRequest cookie(String cookieName, Object value) {}
   public ClientRequest cookie(Cookie cookie) {}
   public ClientRequest pathParameter(String parameterName,
                                         Object value)
   public ClientRequest body(String contentType, Object data) {}

The ClientRequest constructor can take any expression you put in an @Path annotation, but it must also have scheme, host, and port information. Here’s an example of building up a GET request:

ClientRequest request =
                 new ClientRequest("{id}");
       .pathParameter("id", 333);

We allocate the ClientRequest instance, passing in a URL template. ...

The best content for your career. Discover unlimited learning on demand for around $1/day.