Java Reference
In-Depth Information
Accept-Encoding: gzip;q=1.0, compress;0.5; deflate;q=0.1
Here, gzip is desired first, then compress , followed by deflate . In practice, clients use the
Accept-Encoding header to tell the server which encoding formats they support, and they
really don't care which one the server uses.
When a client or server encodes a message body, it must set the Content-Encoding header.
This tells the receiver which encoding was used.
JAX-RS and Conneg
The JAX-RS specification has a few facilities that help you manage conneg. It does method
dispatching based on Accept header values. It allows you to view this content information
directly. It also has complex negotiation APIs that allow you to deal with multiple decision
points. Let's look into each of these.
Method Dispatching
In previous chapters, we saw how the @Produces annotation denotes which media type a
JAX-RS method should respond with. JAX-RS also uses this information to dispatch re-
quests to the appropriate Java method. It matches the preferred media types listed in the Ac-
cept header of the incoming request to the metadata specified in @Produces annotations.
Let's look at a simple example:
@Path ( "/customers" )
public class
class CustomerResource
CustomerResource {
@Path ( "{id}" )
@Produces ( "application/xml" )
public Customer getCustomerXml ( @PathParam ( "id" ) int
int id ) {...}
@Path ( "{id}" )
@Produces ( "text/plain" )
public String getCustomerText ( @PathParam ( "id" ) int
int id ) {...}
@Path ( "{id}" )
@Produces ( "application/json" )
public Customer getCustomerJson ( @PathParam ( "id" ) int
int id ) {...}
Search WWH ::

Custom Search