users@jersey.java.net

Re: [Jersey] Override Bad HTTP ACCEPT Header

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 16 Apr 2009 11:36:48 +0200

Hi Paul,

What version of Jersey are you using?

Versions 1.0.2 and 1.0.3 will parse the accept header you have given
as an example.

Although "*/*" is not strictly allowed it is so pervasive we have to
support it.


On Apr 15, 2009, at 10:35 PM, Paul Hassinger wrote:

> I have web services that I only produce xml with.
>
> I've noticed some browsers may possibly send HEADERS with a bad http
> accept such as the following:
>
> [failed to localize] bad.accept.field(HTTP ACCEPT=text/
> html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8)
>
>
>
> How do I go about either:
>
> - Since I have specified that the methods of the services produce
> xml, why does it still need to check the header?

Because if the client declares it accepts something else the runtime
can return an error. Additionally you may choose later on to add
another method that produces another a representation in another media
type.

> How can I ignore parsing this header for the method? Can I ignore
> it globally?
>
>
> - Alternatively, can I, or how would I go about defaulting every
> request to use my own specified Header, such as cleaning up the
> browser input removing any HTTP ACCEPTs, anduse that instead of the
> header from the browser?

You can use a filter:

   https://jersey.dev.java.net/nonav/apidocs/1.0.3/jersey/com/sun/jersey/api/container/filter/package-summary.html

But first i would check the version of Jersey and upgrade if necessary
to see if that solves things for you.

Paul.