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

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:

@Path("stores/{storeid}")
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:

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

PathBean is a plain Java ...

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