users@jersey.java.net

[Jersey] Re: Media Type and Accept

From: Kevin Hale Boyes <kcboyes_at_gmail.com>
Date: Wed, 24 Sep 2014 13:15:15 -0600

Thanks for your answer!

That tracing support looks very useful but it isn't quite what I'm after
because it's more of a logging/debugging tool.
I want something that I can use inside my method that implements the
endpoint (getit in my example).

I want to get access to the response format selected because I want to make
some decisions and do certain validations.
More specificly, I'm working on supporting the new Prefer header (RFC 7240)
for minimal and representation.
But I want to limit the support for now so that if minimal is requested
then the response must be in JSON.
If representation is requested then the response must be in XML.
Later the support will be expanded.

So, my getit() method looks at the request header for Prefer but I also
need to know what Accept was requested.

I forgot to mention that I'm still using jersey 1.17 though I'm interested
in hearing if the support that I'm after is provided in later versions as
we're thinking of moving to the latest release soon.

I hope that helps to understand my question better.
Thanks,
Kevin

On 24 September 2014 09:37, Michael Pratt <prattm_at_gmail.com> wrote:

> Have you tried tracing?
>
> https://jersey.java.net/documentation/latest/user-guide.html#tracing
>
> The MBW events should shed some light on the MessageBodyWriter selection.
>
> Mike
>
> On Wed, Sep 24, 2014 at 9:31 AM, Kevin Hale Boyes <kcboyes_at_gmail.com>
> wrote:
>
>> I have an endpoint method that produces two output formats - XML and JSON.
>> i.e.,
>> @GET
>> @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
>> public MyModel getit() { ... }
>>
>> When the request comes in Jersey decides what output to generate based on
>> the Accept request header. It processes the (possibly) complex list of
>> acceptable types with the quality factors.
>>
>> Is there any way to get access to the decision it's made as to which
>> output format it will generate?
>>
>> Thanks,
>> Kevin.
>>
>
>