Spring MVC 3 throwing Not Acceptable error on post request
In my web app users can upload an epub file. The server extracts some data
from the file and returns this to the client in xml or json. Files are
uploaded using the jquery.form plugin from malsup.
I get a 406 (not acceptable) status from spring. Why does this happen?
The response is:
The resource identified by this request is only capable of generating
responses with characteristics not acceptable according to the request
"accept" headers.
My controller looks like:
@Controller
public class FileUploadController {
// handles file form submit
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ResponseBody
public SerializedClass save(@RequestParam("posted_file") MultipartFile
file) throws IOException, JAXBException {
return new SerializedClass();
}
The serializedclass:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="body")
public class SerializedClass {
@XmlElement(name="p")
private String p = "a paragraph";
@XmlElement(name="title")
private String title = "the title";
public String getP() {
return p;
}
public void setP(String p) {
this.p = p;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
The request:
Request URL:http://localhost:8080/save.html
Request Method:POST
Status Code:406 Not Acceptable
Request Headersview source
Accept:application/xml, text/xml, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,nl;q=0.6
Connection:keep-alive
Content-Length:1160288
Content-Type:multipart/form-data;
boundary=----WebKitFormBoundarytbhYBrnCSDu5T0UB
Cookie:JSESSIONID=BA1C6A44828C145A3F6CD56FD195ACAA
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
------WebKitFormBoundarytbhYBrnCSDu5T0UB
Content-Disposition: form-data; name="MAX_FILE_SIZE"
100000
------WebKitFormBoundarytbhYBrnCSDu5T0UB
Content-Disposition: form-data; name="posted_file"; filename="Sprookjes -
Wilhelm en Jacob Grimm.epub"
Content-Type: application/epub+zip
------WebKitFormBoundarytbhYBrnCSDu5T0UB
Content-Disposition: form-data; name="uploadSubmitter1"
Submit 1
------WebKitFormBoundarytbhYBrnCSDu5T0UB--
Response Headersview source
Content-Length:1067
Content-Type:text/html;charset=utf-8
Date:Sat, 14 Sep 2013 08:58:39 GMT
Server:Apache-Coyote/1.1
I use Maven and JAXB is in my dependency list:
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
What am I missing?
Thank you
No comments:
Post a Comment