users@jersey.java.net

error handling

From: Jean Aurambault <aurambaj_at_yahoo-inc.com>
Date: Mon, 31 Mar 2008 20:05:55 +0200

Hi,

I have few questions regarding error handling in jersey.

The main objective is to be able to return, in addition of code status,
a description of the error. Basically I don't want to get standard
errors from the container (eg. tomcat).
Moreover according to the resource representation (XML or JSON)
requested by the user, the error has to be encoded either XML or JSON.

1) The first issue I have is about the selection of the type: XML or
JSON that will be used. Let's say I have a resource like that
(comment/question are in the code):

    @GET
    @ProduceMime({"application/xml", "application/json"})
    public Response get() {

        if (!isValid) {
            // Is it possible here to have the ProduceMime apply to the
entity ErrorConverter (which is jaxb bean)?
            throw new
WebApplicationException(Response.status(400).entity(new
ErrorConverter(400, "name", "description")).build());
        }

        // here the ProduceMime is applied and I would like to have the
same behaviour when the error is thrown
        return Response.status(200).entity(new ProductConverter("name",
"description")).build();
    }

2) The second question is about the part of the framework which
generates exceptions (eg. jaxb unmarshalling doesn't work and throws
exception) . I would like to have the control to return my specific
errors and not the basic ones of the container.
Is there a solution to do that ? If not, is it plan to have such a
mechanism in the future ?

Thanks in advance,

Jean.