The following example shows the issue.
There are 3 methods for accept header matching for application/xml, application/json, */*.
. @Produces(MediaType.WILDCARD) public Obj getObj(........); @Produces(MediaType.APPLICATION_XML) public Obj getObjAsXml(........); @Produces(MediaType.APPLICATION_JSON) public Obj getObjAsJson(........);
- Given accept header: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
- Expected:
- It should match to getObjAsXml() based on HTTP spec.
- "application/xml" has higer priority than "*/*" for given accept header.
- Actual:
- It matches to getObj() instead.
- line 180 of org.jboss.resteasy.core.registry.Segment.java
. for (WeightedMediaType accept : accepts) { for (WeightedMediaType produce : produces) { if (accept.isCompatible(produce)) return producesMap.get(produce); } }
- It binds to "*/*" instead of "application/xml" because of following situation.
- the first "accept" object is "text/html"
- the first "produce" object is "*/*".
- "text/html".isCompatible("*/*) return true. As a result, it binds to wrong method.
- It matches to getObj() instead.
- Expected: