Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Response Header to JAX-RS Webservice

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?

like image 754
jconlin Avatar asked Sep 29 '09 15:09

jconlin


People also ask

How do you set a response header?

Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.

How do you get the HTTP request header in Jax Rs 2 ways?

In this tutorial, we show you two ways to get HTTP request header in JAX-RS : Inject directly with @HeaderParam. Pragmatically via @Context.

What is @HeaderParam?

Annotation Type HeaderParamBinds the value(s) of a HTTP header to a resource method parameter, resource class field, or resource class bean property. A default value can be specified using the DefaultValue annotation. The type T of the annotated parameter, field or property must either: Be a primitive type.


1 Answers

You can inject a reference to the actual HttpServletResponse via the @Context annotation in your webservice and use addHeader() etc. to add your header.

like image 185
Heri Avatar answered Sep 21 '22 15:09

Heri