Hi,
we make two methods. It seems to be very simple.
Thanx all,
Robert
2009/12/7 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>
> On Dec 4, 2009, at 6:23 PM, Marc Hadley wrote:
>
>> On Dec 4, 2009, at 11:02 AM, Robert Naczinski wrote:
>>>
>>> @GET
>>> @Produces(MediaType.TEXT_PLAIN + ", " + MediaType.TEXT_HTML)
>>> public Response read(@HeaderParam("Accept") String accept) {
>>> System.out.println("I was here");
>>> if (accept == MediaType.TEXT_PLAIN) {
>>> return
>>> Response.status(Status.OK).entity("text").type(MediaType.TEXT_PLAIN).build();
>>> } else {
>>> return
>>> Response.status(Status.OK).entity("<html><body>text</body></html>").type(MediaType.TEXT_HTML).build();
>>> }
>>> }
>>>
>>> My question was: is this accept implicit?
>>>
>> The above won't work, Accept isn't a single valued header and could look
>> something like: Accept: text/html; q=1.0, text/plain; q=0.8, */*; q=0.1.
>>
>> You do much better either splitting up the methods as suggested by Frank
>> or using Request.selectVariant[1] to have the framework do the content
>> negotiation for you.
>>
>
> See some code Marc previously sent to the list:
>
> http://markmail.org/message/aits7awvwxyk7xch?q=list:net.java.dev.jersey.users+selectVariant+order:date-backward
>
> This seems to be a popular question :-) so perhaps we should try and make it
> easy to get the content-type to be used or most acceptable media type (the
> latter might not be a concrete media type e.g. application/* so may not
> directly correspond to the content-type of the response) ?
>
> Paul.
>
>
>> Marc.
>>
>> [1]
>> https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/core/Request.html#selectVariant(java.util.List)
>>
>>> Thanx
>>> Robert
>>>
>>> 2009/12/4 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>>>>
>>>> On Dec 4, 2009, at 4:18 PM, Robert Naczinski wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I can annotate resource method with '_at_Produces'-Annotation
>>>>>
>>>>> (https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/Produces.html)
>>>>> In this annotation you can have one or several values.
>>>>>
>>>>> Can I automatically get this value of HTTP Header?
>>>>>
>>>>> With @HeaderParam can I get this value. But can I get this implicit?
>>>>>
>>>>
>>>> I do not understand what you mean. Can you provide a concrete example of
>>>> what to want to do?
>>>>
>>>> Paul.
>>>>
>>>>> Is there 'Best Practice'?
>>>>>
>>>>> Thanks
>>>>> Robert
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>