Am I able to change the value of @Produces annotation parameter in my RESTEasy services??
The task I'm given is to integrate multiple format reporting to an existing reporting system.
So changing the @Produces annotation parameter dynamically would help me a lot.
Thanks in advance!
views:
53answers:
2
+1
A:
You can specify several entries in @Produces. Your request should mention which format (as mime type) do you want as the result.
Example:
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
nanda
2010-09-24 12:08:14
Thanks Nanda! Seems to be a nice solution... how about PDF here??
Andrew
2010-09-24 13:05:08
I can't get it to work with PDF... any ideas?
Andrew
2010-09-24 13:48:37
A:
Make your method return a Response
object and try something like this;
int status = 200;
String type = MediaType.APPLICATION_XML;
String response = "<hello>world</hello>";
return Response.status(status).type(type).entity(response).build();
I think the type in the response will override what you annotated, but I haven't tested it.
Qwerky
2010-09-24 12:09:36