Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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.

The REST server provides the following services:  

  • A RESTful customer service is provided on URL http://localhost:9000/customers. Users access this URI to operate on customer.  
  • A HTTP GET request to URL http://localhost:9000/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>
  • A HTTP GET request to URL http://localhost:9000/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"}}
  • A HTTP GET request to URL http://localhost:9000/customerservice/customers/123 without setting "accept header" explicitly, returns a customer instance in JSON  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 JSON document returns:

    {"Customer":{"id":"123","name":"John"}}

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.

  • No labels