users@jersey.java.net

Re: [Jersey] Best practices - Web service and website

From: Gary Moore <gary.moore_at_gmail.com>
Date: Fri, 20 Aug 2010 10:02:17 -0400

Stephen,

Our custom exceptions implement ExceptionMapper. see:
http://github.com/fracturedatlas/parakeet/blob/master/src/main/java/org/fracturedatlas/athena/tix/exception/ParakeetException.java

If you follow this pattern, perhaps you could pass the accept headers
when you instantiate the Exception. Or, the resource layer could
catch the Exception, inject the headers, and re-throw it. Then, the
toResponse method could inspect the header and format a response
accordingly.

It's a little crude, and I don't much like inspecting the request
heders like that because it takes away from the magic that Jersey is
providing with PRoduces, Consumes, etc...

This discussion from last year might help:
http://jersey.576304.n2.nabble.com/Viewable-in-ExceptionMapper-td2356696.html

On Fri, Aug 20, 2010 at 9:42 AM, Stephen Colebourne
<scolebourne_at_joda.org> wrote:
> I'm building a system where there are two distinct types of output -
> web service and website.
>
> For the web service, I want exceptions to map to status codes. For the
> website, I want to map to error pages. Are there any strategies for
> doing this? The exception mappers seem to be global.
>
> To make this work neatly, I have one class for the web service and one
> class for the website for the same resource. In order to get this to
> work, I ended up adjusting the URI, so the web service one has /data
> in the middle. Is it possible to have the same URI implemented in two
> different classes (so long as the media type annotations are
> different)?
>
> Stephen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>



-- 
Gary Moore
http://www.gmoore.net