users@jersey.java.net

[Jersey] Using WebApplicationExceptions

From: Steven Van Impe <steven.vanimpe_at_hogent.be>
Date: Mon, 9 Sep 2013 12:32:21 +0000

I often use WebApplicationExceptions to return 4xx status codes in my JAX-RS resource classes. For example:

throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(“Some error message").build());

But this only seems to work for BAD_REQUEST. The following do not work:

throw new WebApplicationException(Status.NOT_FOUND);
or
throw new WebApplicationException(Status.FORBIDDEN);

Throwing either of these results in a 500 Internal Server Error caused by a RollBackException. Then how can I return a 404 or 403 status code ?

I am using GlassFish 4, as bundled with NetBeans 7.4 beta.

---
Steven Van Impe
Lecturer @ University College Ghent, Belgium
[Follow @svanimpe]<https://twitter.com/intent/follow?screen_name=svanimpe>
http://asipofjava.blogspot.com/