O'Reilly logo

RESTful Java with JAX-RS by Bill Burke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

RESTEasy Client Framework

RESTEasy[16] is the JBoss (Red Hat) JAX-RS implementation. As with java.net.HttpURLConnection 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("http://example.com/customers/{id}");
request.accept("application/xml")
       .pathParameter("id", 333);

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required