Jersey Container Request: why getLanguage returns null

In Jersey, ContainerRequestContext and ContainerRequest will return null for “getLanguage” when you might expect them to work. For instance, you may see that “getLocale” on ServletRequest gives you a valid value.

This problem happens because Jersey is pulling “Content-Language”, when what you want is “Accept-Language”. To get the correct value, you need to use “request.getAcceptableLanguages().get(0)”. Note that you could get multiple values (one per language requested).

The Jersey documentation helpfully describes this method as “the language of the entity or null if not specified”, which is correct, but a little unexpected, since this is actually the language of the response, and not the request.

org.glassfish.jersey.server.ContainerRequest

Leave a Reply

Your email address will not be published. Required fields are marked *