Hi
Hi
I am new to CXF and I am trying to write a CXF Service using JAX RS
Annotations. The problem is, that in this case the type of Servers's
response (XML/JSON), is defined in Request Header like:
X-UI-FORMAT=JSON|XML.
So, if I understand it right, the expected type is defined in the custom header
? Like this :
X-UI-FORMAT=application/json
X-UI-FORMAT=application/xml
while HTTP Accept header may contains some arbitrary values, possibly */* ?
If it's the case then yes, one option is to inject @Context HttpHeaders and do
if/else coding, the way you did it.
Similar option is to do add a @HeaderParam("X-UI-FORMAT") parameter in the
signature.
CXF specific extension, RequestHandler filter will let you do it in a better way. In this RequestHandler you can update the value of
HTTP Accept header by preprocessing X-UI-FORMAT, eg :
public class XUiFormatHandler implements RequestHandler {
public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
m.put(Message.ACCEPT_CONTENT_TYPE, getXUiFormatValue(m));
}
}
and then register this filter from Spring like any other provider.
Finally you can do
@ProduceMime("application/xml", "application/json")
public Customer getCustomer()
Did I understand your problem correctly ?
Cheers, Sergey
Here is what I have to do:
@GET
@Path("getCustomer")
public Customer getCustomer() {
if request.header.equals("application/json") return Customer in JSON
format
else return Customer in XML format
}
I couldn't find the solution neither in Forum nor in CXF samples. And
ProduceMime annotation doesn't seem to work in this case, as only one is
allowed.
Is there any solution to this problem ?
Thanks,
Leszek Mysliwiec
--
View this message in context:
http://www.nabble.com/CXF-how-to-definie-Response-Type-in-Request-Header---tp20127708p20127708.html
Sent from the cxf-user mailing list archive at Nabble.com.