users@jersey.java.net

Re: [Jersey] Strategy for handling 404 when URL does not match _at_Path

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 18 Aug 2009 09:14:40 +0200

Hi Ross,

You can use an ExceptionMapper and map WebApplicationException:

  @Provider
  public NotFoundExceptionMapper extends
ExceptionMapper<WebApplicationException> {
    public Response toResponse(WebApplicationException ex) {
      if (ex.getResponse().getStatus() == 404) {
        return
Response.fromResponse(ex.getResponse()).entity(...).build();
      } else {
        return ex.getResponse();
      }
    }
  }

Paul.


On Aug 17, 2009, at 10:42 PM, Ross McDonald wrote:

> Hi Guys.
>
> Just wondering if you can advise me on this. If I look at the
> helloworld sample, and instead of using the URL:
>
> http://localhost:9998/helloworld
>
> I use:
>
> http://localhost:9998/helloworlds
>
> I get a 404, with a blank page, as expected.
>
> What I want to be able to do is respond with a custom xml document,
> with an associated 404 header.
> I am familiar with creating custom xml responses.
>
> Is there a way I can code another method into my resource to map the
> previously mentioned response?
>
> Thanks in advance for your help,
>
> regards,
>
> -- Ross
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>