Java Reference
In-Depth Information
public String getEmployeeAddressText(String address) { ... }
@Produces("text/xml")
@GET
public String getEmployeeAddressXml(Address address) { ... }
}
The getEmployeeAddressText method is called for an HTTP request that looks as
follows:
GET /employee
Accept: text/plain
This will produce the following response:
500 Oracle Parkway, Redwood Shores, CA
The getEmployeeAddressXml method is called for an HTTP request that looks as
follows:
GET /employee
Accept: text/xml
This will produce the following response:
<address street="500 Oracle Parkway, Redwood Shores, CA" coun-
try="USA"/>
With static content negotiation, you can also define multiple content and media types for
the client and server.
@Produces("text/plain", "text/xml")
In addition to supporting static content negotiation, JAX-RS also supports runtime content
negotiation using the javax.ws.rs.core.Variant class and Request objects.
The Variant class specifies the resource representation of content negotiation. Each in-
stance of the Variant class may contain a media type, a language, and an encoding. The
Variant object defines the resource representation that is supported by the server. The
Variant.VariantListBuilder class is used to build a list of representation vari-
ants.
The following code snippet shows how to create a list of resource representation variants:
Search WWH ::




Custom Search