It doesn't sound like a bug to me, but I agree that the ServerResource
documentation should be clearer about this.

I think of getResponse().setEntity(new SomeRepresentation()) as an appeal to
a lower-level API. Is there some reason you don't want to return "new
SomeRepresentation()" directly from the annotated method?

--tim

On Tue, May 11, 2010 at 4:31 PM, David Fogel <carrotsa...@gmail.com> wrote:

> Hi all-
>
> Our resources tend to subclass ServerResource and then use @Get,
> @Post, etc annotated methods for their functionality.  Since there
> isn't very much documentation on the ServerResource class, we don't
> really know whether this is a bug, or if it reflects us violating some
> contract to do with the annotation processing, but we've noticed the
> following undesirable behavior:
>
> If we
> 1) annotate a method which has a return-type of "void", and
> 2) within that method call getResponse().setEntity(new
> SomeRepresentation()),
>
> then, ServerResource.handl() will, after calling some form of
> doHandle(), replace this existing entity with "null" in the response.
>
> Here is the relevant excerpt in ServerResource.handle():
>
> ....
> if (isConditional()) {
>    result = doConditionalHandle();
>  } else if (isNegotiated()) {
>    result = doNegotiatedHandle();
>  } else {
>    result = doHandle();
>  }
>
>  if (getResponse() != null) {
>    getResponse().setEntity(result);
>  }
> ....
>
> In the above code, "result" is the (possibly converted) value returned
> from the annotated method.  For "void" methods, this value is null.
> In our case, sometimes the method has set the entity separately using
> getResponse().setEntity(..)
>
> Is it possible that this line is meant to be something like:
> if (getResponse() != null && result != null)
>  getResponse().setEntity(result);
>
> I think it's fine for the method return value to override what's
> already in the response, unless the result is null and the response
> already has an entity set.
>
> (Incdentally, our reason for using methods that have a "void" return
> type is that these methods will usually be doing redirects or
> "Success-No-Content" type response, but occasionally need to return
> something with an entity, for instance during an error.)
>
> Is this a bug?
>
> thanks,
>  -Dave Fogel
>
> ------------------------------------------------------
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2607795
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2607808

Reply via email to