How to add custom HTTP Header to JAX-RS response?

apache, cxf, jax-rs

Solution

Try to add `Response Object` as your return value where you can set Headers..

Response.ok(/* some entity */).header("CustomHeader", "CustomValue").build();

You don't need to use interceptors

Problem

I'm trying to add custom HTTP header to response in Apache CXF. I need to count MD5 from content and add it as a HTTP header. I tried to use ResponseHandler or Interceptor. My last try was ``` @Component public class ResponseBPAuthFilter extends AbstractOutDatabindingInterceptor { public ResponseBPAuthFilter() { super(Phase.MARSHAL_ENDING); } @Override public void handleMessage(Message t) throws Fault { Map headers = CastUtils.cast((Map)t.get(Message.PROTOCOL_HEADERS)); headers.put("Some-Header", Arrays.asList("test")); } } ``` but it does nothing.

Original source