I want to add some headers to http response from my server. I need to headers to be added regardless of the code(2xx, 4xx, 5xx) that returns the app. I tried to implement javax.servlet.Filter with @WebFilter annotation and javax.ws.rs.container.ContainerResponseFilter with @Provider annotation, but methods doFilter and filter called only when application returns 200 http status code. Is it possible to use filters for non 2xx responses?
I'm using Wildfly 8.2.0 as app server, but I think it's not important
EDIT
I think I should give more information about my problem. My application is REST-service implemented by Resteasy. Also I have configured security policy for authorization by using Wildlfy security subsystem. I need to response from REST-service always contains CORS headers for every request from frontend, even client doesn't pass authorization check. But when response code is 401, filter methods don't called, even if I use DispatcherType.ERROR, how suggest @Steve C.
So, I don't return any status codes, all codes returns server (as say @ACV). Maybe this is cause, that filters don't work for my case.
EDIT II
I found partial answer in this question. It's possible to add headers to all non-error (non 5xx) responses by configuring undertow subsystem at Wildfly standalone.xml
You need to include the DispatcherType in your @WebFilter declaration:
@WebFilter(urlPatterns={...}, dispatcherTypes={ERROR, REQUEST, ...})
public class ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With