users@jersey.java.net

[Jersey] _at_Produces/provider media type matching

From: <iconnj_at_gmail.com>
Date: Tue, 18 Sep 2012 21:02:25 +0000 (GMT)

I am experimenting with api verioning and have a very peculiar
requirement to work against. We are going to use content-negotiation
i.e @Produces annotation for this and I want to a custom media type in
a format like @Produces({"myapplication/v1-v10+xml"}), where v1-v10
tells that this api will serve any request with Accept header of
"myapplication/v1+xml", "myapplication/v2+xml" all the way to
"myapplication/v10+xml".

I know this is a bit strange, but the idea is that each drop we make in
production will be a new version for the client, but not every service
will be modified. So I want to annotate the service with a range so
that I don’t have to duplicate it for every drop even if it’s not
changed.

Is there any way I can intercept the login in Jersey while it matched
the @Path and @Produces annotations? I know I can’t use regex to match
media types.

A bit more research tells me that the Jersey calls the
MediaType.isCompatible(MediaType other) method to determine the
compatibility between the requests accept header and the services
provider media type.

Is may be able to leverage this a bit if I can create a custom
MediaType and override the isCompatible method. Does Jersey allows such
extension??

I'd be happy to know if I should try any other approch.

-Nik