JAX-RS Sample on Content Negotiation
This sample demonstrates how to implement content negotiation in the Application Server. Content negotiation is a mechanism which allows to maintain multiple representations of the same resource, and serve the particular representation relevant to a given request and what the requesting server needs.
 A RESTful customer service is provided on URL http://localhost:9763/jaxrs_content_negotiation/services/. Users access this URL to operate on a customer.  The REST server provides the following services:
An HTTP GET request to URL http://localhost:9763/jaxrs_content_negotiation/services/customers/customerservice/customers/123Â with "accept header" set to "application/xml" returns a customer instance in XML format. The XML document returns:
<Customer> <id>123</id> <name>John</name> </Customer>
An HTTP GET request to URL http://localhost:9763/jaxrs_content_negotiation/services/customers/customerservice/customers/123Â with "accept header" set to "application/json" returns a customer instance in JSON format. The JSON document returns:
{"Customer":{"id":"123","name":"John"}}
An HTTP GET request to URL http://localhost:9763/jaxrs_content_negotiation/services/customers/customerservice/customers/123Â without setting "accept header" explicitly, returns a customer instance in XMLÂ format. This is because the accept header will be absent from the request when using HTTP Client. In that case, the CXF will treat the "Accept" content type as "*/*". The XML document returns:
<Customer> <id>123</id> <name>John</name> </Customer>
Building and running the sample
This sample can be found at <AS_HOME>\samples\Jaxws-Jaxrs\
jaxrs_content_negotiation
For information on building and running the sample, see Building and Running JAX-RS Samples.