I am creating a RESTful service using Play. I want Play to reject any request where the media type is not specified as JSON in the request header.
There tutorial has a good example of this. http://www.playframework.com/documentation/2.0/JavaJsonRequests
Read where it says ...
@BodyParser.Of(Json.class)
public static index sayHello() {
String name = json.findPath("name").getTextValue();
if(name == null) {
return badRequest("Missing parameter [name]");
} else {
return ok("Hello " + name);
}
}
Note: This way, a 400 HTTP response will be automatically returned for non JSON requests.
Why is it returning HTTP error 400, bad request, instead of HTTP error 415, unsupported media type?
Is there a way to change this behavior?