You want your service to provide alternate views of the same resource.
Provide separate methods that respond to the HTTP protocol you’re
interested in (e.g., multiple methods with a
@GET annotation) and specify a different
@Produces for each one that indicates the MIME type it
A standard browser will pass the MIME types it can handle by
passing the HTTP
Accept header in its request. A typical
request header sent from Firefox looks like this:
The client is telling the server that it would prefer to get HTML
or XHTML, and its next preference is to accept XML. The preferences are
indicated not only by the order in which they appear, but with the
q parameter, used to specify a relative “quality factor” or
how strong the preference is for the given media type on a scale of 0 to
You can read more about the HTTP
Accept header at
So to test the client, you’ll need to indicate an alternative HTTP
Accept header. Building a client programmatically using
something like the HTTP Commons Client library will do this for you. To run
this example, you’ll also need Apache Commons Logging, Logging API, and Codec on your
classpath, as the Apache HTTP client requires them.
Apache Commons Codec and Logging are available at http://commons.apache.org/. This example uses version 3.1 of ...