I am trying add some response headers to some of my webservice calls. I wrote my webservice using CXF 2.1.2 and JAX-RS. I need to return an object and I also want to add some headers to the Response. Without returning a javax.ws.rs.core.Response object, how do I add a header to the response and still return my javabean?
+2
A:
You can inject a reference to the actual HttpServletResponse via the @Context annotation in your webservice and use addHeader() etc. to add your header.
Heri
2009-09-29 20:24:17
@Heri - I tried this, HttpServletResponse comes back null. For Some background I am using Spring for my configuration. I also tried using @Resource for the response to no avail. Injecting the HttpServletRequest to the Context does work though...
jconlin
2009-09-29 21:07:29
This looks like a CXF issue, since it is a specified feature of JAX-RS and I tried it successfully in Jersey. It should be fixed in CXF long ago: https://issues.apache.org/jira/browse/CXF-1498
Heri
2009-09-30 07:27:56
@Heri - Unfortunately I was unable to upgrade the version of CXF in that particular environment, but my issue did appear to be tied to that. Either way you are correct.
jconlin
2009-10-15 20:51:35