users@jersey.java.net

Re: _at_RolesAllowed - Customizing error pages

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 29 Nov 2010 15:22:09 +0100

On Nov 29, 2010, at 3:05 PM, tmp wrote:

>
> thank you very much!
>
> i had some problems to insert a 404 page btw.
> first i tried it like this:
>
> if (r.getStatus() == 403 && r.getEntity() == null) {
> return Response.fromResponse(r).entity(new
> Viewable("/error-pages/403", null)).build();
> }
> else if (r.getStatus() == 403 && r.getEntity() == null) {

The above is checking for a 403 twice in the two if statements.

> return Response.fromResponse(r).entity(new
> Viewable("/error-pages/404", null)).build();
> }
>
>
> it worked for the 403 exception but not for the 404. so i had to
> change the
> code a bit:
>
> if (r.getStatus() == 403 && r.getEntity() == null) {
> return Response.fromResponse(r).entity(new
> Viewable("/error-pages/403", null)).build();
> }
> else if (r.getStatus() == 404 && r.getEntity() == null) {
> return Response.ok(new Viewable("/error-pages/404",
> null)).build();
> }
>
> can you explain that? it works fine, but i don't know why :)

How else are you going to check for two different status codes?

Paul.