views:

635

answers:

1

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
@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
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
@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