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 ?
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.