Does Restlet 415 Unsupported Media Type return when it should return 400 Bad Request?

I am using Restlet 2.1 with jackson to create json REST api.

When I make a request with the expected content type, but with a distorted body, I return the status code 415 "Unsuppored Media Type". I think the correct error code should be 400 "Bad Request".

Mixing seems to occur when Jackson tries and cannot decode the garbage.

I will try to make the code more understandable with some code:

// java method mapping
@Post("json")
public Project create(Project project) {

Service call with curl

$ curl -i -XPOST -H 'content-type: application/json' -d '{xgarbage}' http://localhost:8080/projects HTTP/1.1 415 Unsupported Media Type

And fragmentation of the os recorde stack trace in the logs:

Nov 29, 2010 9:51:56 PM org.restlet.ext.jackson.JacksonRepresentation getObject
WARNING: Unable to parse the object with Jackson.
org.codehaus.jackson.JsonParseException: Unexpected character ('x' (code 120)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.ByteArrayInputStream@693e4a5a; line: 1, column: 2]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:929)

The actual implementation of the service is never hit, so somewhere a decision was made to map the distorted content to number 415.

, : ? "RESTful Web Services", , .

[400 Bad Request] , PUT POST, , .

.

[415 Unsupported Media Type] , , (, XML, ), 400 ( " " ")

, 400.

, , Jackson?

, !

+5
1

415 , , . , JSON XML. Malformed JSON XML JSON XML , , , , , JSON, , " t JSON, .

.

10.4.16 415

, , .

, JSON, , , , , JSON .

+3

All Articles