users@jersey.java.net

Re: [Jersey] understanding content types and resource methods

From: Felipe Gaúcho <fgaucho_at_gmail.com>
Date: Tue, 29 Dec 2009 13:14:53 +0100

ops..

Content-Type has precedence over Accept ?

strange....... but ok, very good to know.......

On Tue, Dec 29, 2009 at 10:20 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>
> On Dec 21, 2009, at 3:26 PM, Marc Hadley wrote:
>
>> Dispatching of HTTP requests to Java methods is based on 4 things:
>>
>> (i) The URI path
>> (ii) The HTTP method
>> (iii) The media type of the request (Content-Type header)
>> (iv) The media type requested for the response (Accept header)
>>
>> The dispatch algorithm is described in all its gory details here:
>>
>> https://jsr311.dev.java.net/nonav/releases/1.1/spec/spec3.html#x3-340003.7
>>
>> Dispatch based on the deserialized Java type isn't supported.
>>
>> As suggested earlier in the thread you can use different paths (via @Path)
>> for each type of message or different media types (via @Consumes). Having
>> one service consume multiple different media types is fine BTW.
>>
>> An alternative is to use a single wrapper element for all types of event
>> that can contain each of your different event messages. e.g.:
>>
>> <wrapper>
>>  <event1>...</event1>
>> </wrapper>
>>
>> You can then switch in the method code to determine the type of event
>> received.
>>
>> Another alternative is to use Object as your method parameter type and
>> then use instanceof to determine the message received.
>>
>
> Note that to use Object you need to also define a
> ContextResolver<JAXBContext> implementation that returns a JAXBContext for
> the Class of Object.
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>



-- 
------------------------------------------
   Felipe Gaúcho
   10+ Java Programmer
   CEJUG Senior Advisor