dev@jsr311.java.net

RE: JSR311: Determining the media type of responses

From: Liu, Jervis <jliu_at_iona.com>
Date: Mon, 10 Dec 2007 04:14:43 -0500

> -----Original Message-----
> From: Marc.Hadley_at_Sun.COM [mailto:Marc.Hadley_at_Sun.COM]
> Sent: 2007Äê12ÔÂ8ÈÕ 0:30
> To: dev_at_jsr311.dev.java.net
> Subject: Re: JSR311: Determining the media type of responses
>
> See below for an expanded algorithm. As suggested, if there's no
> concrete type but */* is acceptable and producible then we default to
> application/octet-stream. The final question is what to do if you end
> up with something like text/* as the only acceptable and producible
> type. Currently this results in a 406 response which is sort of odd
> given that the type is producible, we just can't work out what type to
> use. Here are the options I see:
>
> (a) return a 406 - the status quo
> (b) return some other status code - which one ?
> (c) default to application/octet-stream - is this really a good idea
> if, e.g., the intersection is text/* ? Would seem odd to default to a
> type that isn't acceptable.
> (d) define default concrete types for all the major types, e.g. text/
> plain for text/*, application/octet-stream for application/*, image/
> (what ?) any others we need to worry about ?
> (e) something else ?
>
[Liu, Jervis]
Option (a) and (b) should be ruled out as it is wrong to return 406 or other statues when "text/*" actually means sth valid can be produced. Having a default content type for each major types sounds a reasonable approach, e.g., application/octet-stream for */*, text/plain for text/*, application/octet-stream for application/* etc. The problem with this approach is that it would be impossible for the spec to come out with a complete list. But it is acceptable before any better ideas emerged. Types not defined by this list can be decided by JSR-311 implementation.
 
> Any input much appreciated.
>
> Thanks,
> Marc.
>
> 1. Gather the producible media types P
>
> - If @ProduceMime on method: P = values of @ProduceMime for the
> method.
> - Else if @ProduceMime on class: P = values of @ProduceMime for the
> class.
> - Else P = union(values of @ProduceMime for the MessageBodyWriter
> providers that support the class of the returned entity).
>
> 2. If P is empty, P = {"*/*"}
>
> 3. Obtain the acceptable media types A. If A is empty A = {"*/*"}
>
> 4. Sort A and P in decending order, each with a primary key of q-value
> and secondary key of specificity n/m > n/* > */*
>
> 5. M={}, for each entry a in A
> - For each entry p in P
> - If a is compatible with p
> - Add MostSpecific(a,p) to M
>
> 6. If M is empty then 406 Not Acceptable.
>
> 7. M_selected = null, for each entry m in M
> - if m is a concrete type, M_selected = m, finish
>
> 8. If M contains */*, M_selected = application/octet-stream else "406
> Not Acceptable"
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland