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.

Apache CXF

Apache CXF[23] is a popular open source web services framework. It was originally just a SOAP stack, but they recently added support for JAX-RS. The CXF philosophy is that different web service styles can coexist. You’ll see a lot of this when you use the framework to write your RESTful web services.

Apache CXF has a few nice extensions to JAX-RS that I’d like to point out.

Aggregating Request Parameters into Beans

RESTful services can often depend on a large number of request parameters. Listing multiple parameters in resource method signatures may end up not very readable and quite brittle, for example:

public class BookStores {
    @GET @Path("books/{publication}")
    public Books getBooks(
                     @PathParam("storeid") int storeid,
                     @PathParam("publication") Date publicationDate,
                     @MatrixParam("sortKey1") String sortKey1,
                     @MatrixParam("sortKey2") String sortKey2,
                     @MatrixParam("publication") Date publicationDate,
                     @QueryParam("author") String name,
                     @QueryParam("count") int responseListSize) {}

If you need access to a lot of injectable data, your JAX-RS resource methods can get quite large and cumbersome. Apache CXF allows you to aggregate this information into specific injectable bean classes instead. For example:

public class BookStores {
    @GET @Path("books/{publication}")
    public Books getBooks(@PathParam("") PathBean pathParams,
                          @MatrixParam("") MatrixBean matrixParams,
                          @QueryParam("") QueryBean queryParams) {}

PathBean is a plain Java ...

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