write two methods, one that produces MediaType.TEXT_PLAIN and one that
produces MediaType.TEXT_HTML:
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response createPlain() {
return
Response.status(Status.OK).entity("text").type(MediaType.TEXT_PLAIN).build();
}
and
@GET
@Produces(MediaType.TEXT_HTML)
public Response createPlain() {
return
Response.status(Status.OK).entity("<html><body>text</body></html>").type(MediaType.TEXT_HTML).build();
}
Frank
Robert Naczinski <robertnac_at_googlemail.com>
Sent by: robert.naczinski_at_googlemail.com
12/04/2009 10:03 AM
Please respond to
users_at_jersey.dev.java.net
To
users_at_jersey.dev.java.net
cc
Subject
Re: [Jersey] Getting Accept Header in Requests
Hi,
I can write:
@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?
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
<HTML><BODY><P><hr size=1></P>
<P>
<font color="#006000">Please consider the environment before printing this email and any attachments.</font><P><STRONG>
This e-mail and any attachments are intended only for the individual or company to which it is addressed and may contain information which is privileged, confidential and prohibited from disclosure or unauthorized use under applicable law. If you are not the intended recipient of this e-mail, you are hereby notified that any use, dissemination, or copying of this e-mail or the information contained in this e-mail is strictly prohibited by the sender. If you have received this transmission in error, please return the material received to the sender and delete all copies from your system.
</STRONG></P></BODY></HTML>