The security context cannot be set in the request as it is already in the response processing phase.
Hello guys,
today i’ll show how to resolve the “security context cannot be set in the request as it is already in the response processing phase.” problem in a Jersey implementation, the stack trace is intuitive, but you have no choices to resolve that if you don’t read the documentation, I spent a lot time on the stackoverflow searching about, unfortunately not in the Jersey documentation, then i resolved!
Take a look:
/**
* @author Jhonatan S. Souza
*/
@Provider
@PreMatching
public class RequestFilter implements javax.ws.rs.container.ContainerResponseFilter, javax.ws.rs.container.ContainerRequestFilter {
The problem is that you r using the response implementation javax.ws.rs.container.ContainerResponseFilter instead the javax.ws.rs.container.ContainerRequestFilterdo the change and the request will gonna work.
Indeed, very simple, but gave me a headache. Enjoy!!!
See ya!