users@jersey.java.net

[Jersey] Re: Using WebApplicationExceptions

From: Martynas Jusevi?ius <martynas_at_graphity.org>
Date: Mon, 9 Sep 2013 16:22:52 +0100

Check out ExceptionMapper:
http://docs.oracle.com/javaee/6/api/javax/ws/rs/ext/ExceptionMapper.html

Implement a mapper for each of the exception types and add them to your
Application as providers.

Martynas
graphityhq.com


On Mon, Sep 9, 2013 at 1:32 PM, Steven Van Impe <steven.vanimpe_at_hogent.be>wrote:

> 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
> [image: Follow @svanimpe]<https://twitter.com/intent/follow?screen_name=svanimpe>
> http://asipofjava.blogspot.com/
>
>