users@jersey.java.net

User defined exceptions

From: Ricardo Borillo <Ricardo.Borillo_at_si.uji.es>
Date: Thu, 16 Jul 2009 21:23:35 +0200

Hi all,

I'm implementing my first REST API and i'm facing some design problems ...

In my server REST service i issue, through jaxb binding, an instance
of a class in application/xml format.
If an user defined exception arises, i issue an error message (i'm
using an exception mapper) with an HTTP 200 error code:

<error code="1" />

This error message is built with JAXB too.

The question is how to manage this situation in the client. If i have:

        ClientResponse response = webResource.path("test/x").accept(
                MediaType.APPLICATION_XML).get(ClientResponse.class);

        if (response.getStatus() == 200)
        {
            return response.getEntity(MyJAXBEntity.class);
        }
        else
        {
            throw new Exception(response.getStatus());
        }

How can i know that i'm getting an error xml or other message using
JAXB binding?
How can i design this type of interaction?

Thanks a lot and sorry if this is an obvious question :)

---
Salut,
====================================
Ricardo Borillo Domenech
http://xml-utils.com