users@jersey.java.net

_at_Consumes based on additional headers (versioning)

From: Cybernd <cybernd_at_cybernd.at>
Date: Thu, 08 Jul 2010 17:38:21 +0200

Hi,

As far as i understand, jersey finds the suitable resource method based
on @Path and @Consumes.
Jersey is also able to do content negotiation based on @Consumes quality
header properties.

Is there a way to use an additional artificial version header?

The basic idea would be (pseudocode):

     @POST
@Path("/dummy")@Consumes(MediaType.APPLICATION_XML)@ConsumeHeader("X-API-Version",
"1")
     public MyResponseV1 myDummy(MyRequestV1 request) {}

     @POST
@Path("/dummy")@Consumes(MediaType.APPLICATION_XML)@ConsumeHeader("X-API-Version",
"2")
     public MyResponseV2 myDummy(MyRequestV2 request) {}

Rational: This would allow me to support both versions running at the
same time.
I am aware that it is possible to reach the same behavior with custom
mediaTypes but my current rest API spec wants to use the custom version
header.

The easiest workaround would be to use String for request and response,
but this would mean that i lose the ability to use jerseys integrated
jaxb/json support.

Spring MVC rest support seems to be able to do something like that out
of the box.
It is possible to configure an array of consuming headers using this syntax:
      headers={"headername=headervalue"}

Is it possible to reach my goal?
Or is it a feature that is missing intentional because it is against
some REST rules?

URI versioning (path and/or query) is in my usecase unfavored.

thanks,
Bernhard Neuhauser