users@jersey.java.net

Re: [Jersey] GET rest service throwing exceptions

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 24 Jun 2009 09:57:48 +0200

On Jun 23, 2009, at 6:45 PM, Saavedra, Gisella wrote:

> Paul ,
>
> thank you for the clarification. That explains why I did not get
> the UniformInterfaceException for NO_CONTENT (204)
> but I did get it for PRECONDITION_FAILED (412).
>
> I sent the first lines of code to avoid sending the whole piece.
> Sorry for the confusion. Trying to make the message shorter but I
> see I could not beat code behavior.
>
> Maybe the javadoc documentation should mention this boundary >=300
> for UniformInterfaceException.
>

It does:

https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/api/client/WebResource.html
#get(java.lang.Class)

https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/api/client/UniformInterface.html

Paul.

> So, either I have to send an empty object instead of NO_CONTENT, or
> change my service response to Response and at the client side use
> ClientResponse to catch any
> Response.Status.
>
> Thanks,
>
> Gisella
>
>
>
>
>
> On Jun 23, 2009, at 2:55 AM, Saavedra, Gisella wrote:
>
> >
> > I have the following resource method:
> >
> > @GET
> > @Produces({"application/xml"})
> > public Logs getAl() {
> >
> > // Verify parameters
> > NodeConfig nodeConfig = ClusterNodeUtils.getNodeInfo();
> >
> > // Verify that current node directory path exists
> > if (!
> > FileCompressionUtils.dirExists(nodeConfig.getNodecfgLogDirPath())) {
> > throw new
> > RestApplicationException(Response.Status.PRECONDITION_FAILED, "Log
> > directory does not exist");
> > }
> > …
> > }
> >
> > At the client side, it is invoked as:
> > try {
> > String xmlResponse =
> > res.accept(MediaType.APPLICATION_XML_TYPE).get(String.class);
> > } catch (UniformInterfaceException e) {
> > // log it
> > }
> >
> > /////////////////////////
> >
> > The RestApplicationException class code is:
> > public class RestApplicationException extends
> > WebApplicationException {
> > public RestApplicationException (Response.Status inStatus,
> > String inMessage) {
> >
> super(Response.status(inStatus).entity(inMessage).type("text/
> > plain").build());
> >
> > }
> >
> >
> > ////////////////////
> >
> > But at the client side, I do not get the exception thrown above. I
> > get the String xmlResponse = “"Log directory does not exist"
> >
>
> You should get UniformInterfaceException thrown on the client side
> because the response status code is >= 300.
>
> Could you add logging to your client so you can observer the responses
> being received from the server to verify that the precondition status
> code, 412, was being returned:
>
> res.addFilter(new LoggingFilter());
>
>
> > What do I need to do, either client or server side, to receive the
> > exception I threw as an exception?
> >
>
> The Jersey client API is not a RPC-type system where Java classes that
> are exceptions are propagated from server to client. The exception you
> threw on the server side will not be reproduced on the client side.
> Your RestApplicationException is defining an *HTTP response* that will
> be sent to the client and not an exception that will be propagated.
>
> Paul.
>
> > Thanks.
> >
> >
> >
> >
> > Gisella Saavedra
> > Sr. Software Engineer
> > gsaavedra_at_zebra.com
> > <image001.gif>
> > 1000 Broadway, Suite 150, Oakland, CA 94607 | T+1 510 267 5123 T
> > Main+1 510 267 5000 F+1 510 267 5100 | http://www.zebra.com/zes
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
> Gisella Saavedra
> Sr. Software Engineer
> gsaavedra_at_zebra.com
> <image001.gif>
> 1000 Broadway, Suite 150, Oakland, CA 94607 | T+1 510 267 5123 T
> Main+1 510 267 5000 F+1 510 267 5100 | http://www.zebra.com/zes
>
>
>