dev@jsr311.java.net

Re: Proposal for rework of spi package (was Re: "Dual dispatch")

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 26 Apr 2007 11:30:05 +0200

Marc Hadley wrote:
> On Apr 25, 2007, at 4:30 PM, Stefan Tilkov wrote:
>
>>>
>>> @UriTemplate("/things/{thing_id}")
>>> public class ThingResource {
>>>
>>> public Thing(@UriParam("thing_id") String id) {...}
>>>
>>> @HttpMethod
>>> Thing get() {...}
>>
>> I think this should still be
>>
>> @HttpMethod @ProduceMime("application/thing")
>> Thing get() {...}
>>
>> because in this class, I may want to return application/thing content,
>> and in another class (or even another method) I might want to use a
>> different content type.
>>
> I think that would make sense for something generic like a String return
> type where the method itself is essentially doing the serialization but
> suppose Thing is a simple Java bean, in that case there's no need to
> have two different methods that return an instance of Thing for
> different media types since one method will do.
>
> I still think it makes sense to support @ProduceMime on the method but
> in some cases I think it could be left out and the runtime can still do
> conneg based on the TypeStreamingProviders.
>

The main quandary i have with deferring conneg to the type provider is
that this can defer a 406 response until after the HTTP method has been
invoked, processed the request, and returned a response.

This is similar to the case of:

     @HttpMethod @ProduceMime("*/*")
     Response get() {
        Thing thing = ...
        return Response.entity(thing).type("application/thing");
     }


In this case the application could call some pre-condition helper
(provided by the runtime e.g. from the PreconditionEvaluator class) to
check that "application/thing" is not acceptable and return a 406
response, for example:

     @HttpMethod @ProduceMime("*/*")
     Thing get(@HttpContext PreconditionEvaluator e) {
        // throws exception if not acceptable
        MimeType a = e.acceptable("application/thing+xml",
            "application/thing+json");
        Thing thing = ...
        return Response.entity(thing).type(a);
     }



In the the case of the type provider it is less clear if the application
should do accept checking and what the mime types should be if it wants
to check. It may lead to cases where success is expected but results in
415 responses where roll back is not possible, for example when using
conneg for POST/PUT that returns something.

Thus although i think it a good thing that a type provider can serialize
to more than one format and i am so sure about using it as a substitute
for @ProduceMime.

Paul.

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