Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change RESTEasy service return type

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!

like image 1000
Andrew Avatar asked Sep 24 '10 11:09

Andrew


1 Answers

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.

like image 99
Qwerky Avatar answered Sep 16 '22 23:09

Qwerky