users@jersey.java.net

Re: [Jersey] User defined exceptions

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Thu, 16 Jul 2009 12:33:43 -0700

Ricardo Borillo wrote:
> 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 :)
>
>
Would something like this work?

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

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


where the MyErrorMessage class has a "code" property containing a string
representation of the "code" value.

Craig
 
> ---
> Salut,
> ====================================
> Ricardo Borillo Domenech
> http://xml-utils.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>