users@jersey.java.net

Re: [Jersey] null return values versus Content-Type header

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 04 Jun 2008 14:55:43 +0200

This is fixed in the trunk.

Paul.

Marc Hadley wrote:
> On May 28, 2008, at 4:57 AM, Paul Sandoz wrote:
>>
>> I am now wondering whether this exception is way to restrictive and
>> the returning of a null value should be equivalent to returning no
>> content.
>>
> Here what the spec says about null:
>
> 3.3.3 Return Type
>
> Resource methods MAY return void, Response or another Java type, these
> return types are mapped to a response entity body as follows:
>
> - void: Results in an empty entity body with a 204 status code.
> - Response: Results in an entity body mapped from the Entity property of
> the Response with the status code specified by the status property of
> the Response. A null return value results in a 204 status code.
> - Other: Results in an entity body mapped from the return type. If the
> return value is not null a 200 status code is used, a null return value
> results in a 204 status code.
>
> The only slight edge case is that if a method returns a non-null
> Response with a null entity then it has to set the status code
> appropriately since it shouldn't be overridden by the runtime.
>
> Marc.
>
>> You can work around this by:
>>
>> return Response.noContent().build();
>>
>> What should we do for this case:
>>
>> return Response.ok(null, "text/plain").build();
>>
>> ?
>>
>> Should the rule be: if the entity is null and there is a Content-Type
>> header present then that header should be ignored and a warning should
>> be logged?
>>
>> Paul.
>>
>>> Thanks,
>>> Frank Sauer
>>> The "Content-Type" header is set to application/xml, but the response
>>> has no entity:
>>> javax.ws.rs.WebApplicationException
>>> at
>>> com.sun.ws.rest.impl.uri.rules.HttpMethodRule.verifyResponse(HttpMeth
>>> odRule.java:209)
>>> at
>>> com.sun.ws.rest.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.j
>>> ava:113)
>>> at
>>> com.sun.ws.rest.impl.uri.rules.RightHandPathRule.accept(RightHandPath
>>> Rule.java:88)
>>> at
>>> com.sun.ws.rest.impl.uri.rules.ResourceClassRule.accept(ResourceClass
>>> Rule.java:55)
>>> at
>>> com.sun.ws.rest.impl.uri.rules.RightHandPathRule.accept(RightHandPath
>>> Rule.java:88)
>>> at
>>> com.sun.ws.rest.impl.uri.rules.RootResourceClassesRule.accept(RootRes
>>> ourceClassesRule.java:49)
>>> at
>>> com.sun.ws.rest.impl.application.WebApplicationImpl.handleRequest(Web
>>> ApplicationImpl.java:369)
>>> at
>>> com.sun.ws.rest.spi.container.servlet.ServletContainer.service(Servle
>>> tContainer.java:130)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>>> ------------------------------------------------------------------------
>>> * This e-mail and any attachments are intended only for the
>>> individual or company to which it is addressed and may contain
>>> information which is privileged, confidential and prohibited from
>>> disclosure or unauthorized use under applicable law. If you are not
>>> the intended recipient of this e-mail, you are hereby notified that
>>> any use, dissemination, or copying of this e-mail or the information
>>> contained in this e-mail is strictly prohibited by the sender. If you
>>> have received this transmission in error, please return the material
>>> received to the sender and delete all copies from your system. *
>>
>> --
>> | ? + ? = To question
>> ----------------\
>> Paul Sandoz
>> x38109
>> +33-4-76188109
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109