java - How to add custom response and abort request in jersey 1.11 filters - Stack Overflow
In case of error, if you want to send a custom response then you need to throw WebApplicationException. Create a Response object and send it back using the following exception constructor:
WebApplicationException(Response response) Construct a new instance using the supplied response
Try this:
@Override public ContainerRequest filter(ContainerRequest request) { User user = Helper.getCurrentUser(); if(user == null){ ResponseBuilder builder = null; String response = "Custom message"; builder = Response.status(Response.Status.UNAUTHORIZED).entity(response); throw new WebApplicationException(builder.build()); } return request; }
Read full article from java - How to add custom response and abort request in jersey 1.11 filters - Stack Overflow
No comments:
Post a Comment