Why does my Spring service return any type of content requested by the client?

I have a Spring service service using Spring 3.1.0.RELEASE. Here is the appropriate code for the corresponding service call:

@RequestMapping(value="/{var1}", method=RequestMethod.GET, produces="application/json")
@ResponseBody
public String getSomeStuff(@PathVariable final String var1) {
    return myJsonString;
}

If I call it with the following curl command, it will gladly return me my json string with the application content type / xml, whereas I expect 406 based on Spring 3.1 docs:

curl -v -H "Accept: application/xml" http://localhost:8080/MyServiceSite/myvalue

In my application for this service there is no additional configuration (without serialization), I return raw json without further processing for the configured service. I'm sure I missed something, can someone point out something that I might have missed?

: , , . , 16.3.2.5. , , , , Spring . , Spring?

: . 415 , , 406 , , jive .

, , json, , , 406. , , , "" , .

+5
2

Spring MVC 3.1 RequestMappingHandlerMapping @MVC, new Spring 3.1. , 3.0 @MVC, . , , .

= "Accept = application/json" 3.1. .

+1

headers @RequestMapping. Accept . - :

@RequestMapping(value="/{var1}", method=RequestMethod.GET, produces="application/json", headers = "Accept=application/json")
@ResponseBody
public String getSomeStuff(@PathVariable final String var1) {
    return myJsonString;
}

, Spring . , , ResponseEntity - , , .

+1

All Articles