Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my Spring service returning any content type requested by client?
    primarykey
    data
    text
    <p>I have a Spring rest service using Spring 3.1.0.RELEASE. Here is the relevant code for the service call in question:</p> <pre><code>@RequestMapping(value="/{var1}", method=RequestMethod.GET, produces="application/json") @ResponseBody public String getSomeStuff(@PathVariable final String var1) { return myJsonString; } </code></pre> <p>If I call this using the following curl command, it happily returns me my json string with a content-type of application/xml whereas I would expect a 406 based on the Spring 3.1 docs:</p> <pre><code>curl -v -H "Accept: application/xml" http://localhost:8080/MyServiceSite/myvalue </code></pre> <p>There is no extra configuration in my app for this service (no serialization), I am returning raw json with no post-processing for the service configured. I'm certain I have missed something, can anyone point out anything I may have missed?</p> <p>Edit: Here is the <a href="http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-produces" rel="nofollow">documentation</a> I was looking at when attempting to get this working. Specifically section 16.3.2.5. My code is very similar except that their code looks like it assumes config setup to let Spring handle serialization. Perhaps the produces does not work when bypassing the Spring serialization?</p> <p>Edit: I changed my expectation for the response code. A 415 would indicate I was sending improper content in my request body whereas 406 is proper for having an accept header that doesn't jive with the content type of the server.</p> <p>Anyway, I have changed this method do return a Map and added config for it to serialize to json and now if I send an invalid content type from the client I get the proper 406 response. It seems that maybe the "produces" setting is ignored when the output of the method is not being serialized.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload