HTTP content negotiation conflicts in JAX-RS/Jersey?

可紊 提交于 2019-11-29 00:13:11

As the Jersey User Guide states:

If both are equally acceptable then the former will be chosen because it occurs first.

From what I know, this leaves you with two possibilities/hacks:

  1. Append the file extension to your URIs to override the Accept header

  2. Write a servlet filter that overwrites the Accept header for those User Agents

There is a mechanism in Jersey to override the relative degree of preference from the HTTP Accept header. Just add a parameter "qs" to the @Produces annotation that you want to take precedence. In your case: @Produces("text/html;qs=2") Note that the http "q" values range from 0-1 and the Jersey "qs" values should be >= 1 (1 is default).

(I learned about this from this source, and I wrote a little note for myself here)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!