{"id":4157,"date":"2016-05-18T00:00:22","date_gmt":"2016-05-18T00:00:22","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4157"},"modified":"2016-05-18T00:00:22","modified_gmt":"2016-05-18T00:00:22","slug":"jersey-container-request-getlanguage-returns-null","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/jersey-container-request-getlanguage-returns-null\/","title":{"rendered":"Jersey Container Request: why getLanguage returns null"},"content":{"rendered":"<p>In Jersey, ContainerRequestContext and ContainerRequest will return null for &#8220;getLanguage&#8221; when you might expect them to work. For instance, you may see that &#8220;getLocale&#8221; on ServletRequest gives you a valid value. <\/p>\n<p>This problem happens because Jersey is pulling &#8220;Content-Language&#8221;, when what you want is &#8220;Accept-Language&#8221;. To get the correct value, you need to use &#8220;request.getAcceptableLanguages().get(0)&#8221;. Note that you could get multiple values (one per language requested). <\/p>\n<p>The Jersey documentation helpfully describes this method as &#8220;the language of the entity or null if not specified&#8221;, which is correct, but a little unexpected, since this is actually the language of the response, and not the request.<\/p>\n<pre>\norg.glassfish.jersey.server.ContainerRequest\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Understanding an unexpected Jersey behavior<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[300,308,465],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4157"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4157"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4157\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}