1

I have an application using Spring 3.2.2. I run it on Tomcat.

In the app I have a controller that returns JSON.

If controller request mapping contain strings ".com", ".org", ".talk", I get HTTP error 406

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

Example:

This works fine:

@RequestMapping(method = RequestMethod.GET, value = "/test.test")
    public @ResponseBody Map<String, String> test() {
        Map<String, String> stringMap = new HashMap<String, String>();
        stringMap.put("test", "test");
        return stringMap;
}

This causes http error 406:

@RequestMapping(method = RequestMethod.GET, value = "/test.talk")
        public @ResponseBody Map<String, String> test() {
            Map<String, String> stringMap = new HashMap<String, String>();
            stringMap.put("test", "test");
            return stringMap;
}

The issue is not reproduced with all domain names I tried. For example ".net" works fine.

Imane Fateh
  • 2,418
  • 3
  • 19
  • 23
Dmitry Klochkov
  • 2,484
  • 24
  • 31

1 Answers1

3

I have faced the same problem as described above. My application worked in Jetty but not in Tomcat. However, in my case the call never reached the Spring controller.

So, if that is the case for you as well this is likely a Tomcat-configuration problem. The Tomcat has mime-mappings in the file web.xml. Remove the mappings for com, org etc that are not required and the 406 should disappear.

Remove the following from the file apache-tomcat-7.x/conf/web.xml:

<mime-mapping>
    <extension>org</extension>
    <mime-type>application/vnd.lotus-organizer</mime-type>
</mime-mapping>

<mime-mapping>
    <extension>com</extension>
    <mime-type>application/x-msdownload</mime-type>
</mime-mapping>.
wassgren
  • 18,651
  • 6
  • 63
  • 77
  • Another simpler way to solve the problem is probably to use a trailing slash for the mapping as described [in this question](http://stackoverflow.com/questions/16332092/spring-mvc-pathvariable-with-dot-is-getting-truncated) A path like this can probably work /test.talk/ – wassgren May 12 '14 at 09:26