users@jersey.java.net

Re: [Jersey] Representation addressability and the _at_Path annotation

From: Casper Bang <casper_at_jbr.dk>
Date: Mon, 23 Mar 2009 22:03:27 +0100

That sounds like a fine idea, one that would suit my needs fine and cater
well to the notion of addressability and the world of mashups (it's a little
hard to specify accept-types in an URI).

/Casper

2009/3/23 Jaka Jančar <jaka_at_kubje.org>

> What I would like the most is the ability to define a global map of
> extensions to mime types (e.g. png=>image/png, ...), and whenever an
> extension was provided by the client (/images/15.png instead of just
> /images/15), the client-provided accept-types would be overridden.
>
> Perhaps this is already doable somehow using filters.
>
> Regards,
> Jaka
>
>
> On 23. Mar 2009, at 21:37, Casper Bang wrote:
>
> For addressability and debugging reasons, I'd like to supply an
>> alternative representation resolution than simply relying on MIME header
>> data and @Produces annotations. The handy @Path annotations opens up for
>> some nice reuse at method level:
>>
>> @Path("/meters/{meterId: " + meterId + "}")
>> public class{
>> @GET
>> @Path("png")
>> @Produces("image/png")
>> public byte[] getAsImage{ ... }
>> }
>>
>> This would give me the resource as a PNG image if I issue a GET
>> /meters/755841/png
>>
>> Now, what I would really like is to modify the adressability aspect a bit
>> to mimic people's common understanding of the web, such that I can issue a
>> GET /meters/755841.png (and ...755841.json etc.) but that does not seem
>> possible given how the trailing / is mandatory and needed for Jersey to be
>> able to parse/tokenize. The obvious workaround I can see is to include the
>> variable (meterId) in each and every method level @Path annotation:
>>
>> @Path("/meters/)
>> public class{
>>
>> @GET
>> @Path("{meterId: "+ meterId +"}.png")
>> @Produces("image/png")
>> public byte[] getAsImage{ ... }
>>
>> @GET
>> @Path("{meterId: "+ meterId +"}.json")
>> @Produces("application/json")
>> public byte[] getAsJson{ ... }
>>
>> // ...etc.
>> }
>>
>> However this does not seem very DRY and potentially not the best use of
>> Jersey. So is this the only way? Or can I somehow tell Jersey to tokenize on
>> dot as well as slash?
>>
>> Thanks in advance,
>> Casper
>>
>>
>> PS: By the way, the above @Path expression won't actually compile. I get
>> the error "attribute value must be constant" when using "{meterId: "+
>> meterId +"}.png". The way around that seems to be to concatanate into a
>> public static final String member of the resource and use it instead. Not
>> sure I understand why concatanation in a @Path value is allowed at class
>> level but not at method level?
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>