15

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?

jconlin
  • 3,806
  • 6
  • 31
  • 32

1 Answers1

12

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
  • 2,114
  • 14
  • 13
  • @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 Sep 29 '09 at 21:07
  • 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 Sep 30 '09 at 07:27
  • @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 Oct 15 '09 at 20:51