@Override
public MediaType getNormalisedRequestMediaType(HttpServletRequest request) {
String contentType = request.getContentType();
if (request.getMethod().equals("POST")) {
if (contentType == null) {
throw new CougarValidationException(ServerFaultCode.ContentTypeNotValid, "Input content type was not specified for deserialisable response");
}
MediaType requestMT;
try {
requestMT = MediaType.valueOf(contentType);
} catch (Exception e) {
throw new CougarValidationException(ServerFaultCode.MediaTypeParseFailure, "Input content type cannot be parsed: " + contentType,e);
}
if (requestMT.isWildcardType() || requestMT.isWildcardSubtype()) {
throw new CougarValidationException(ServerFaultCode.InvalidInputMediaType, "Input content type may not be wildcard: " + requestMT);
}
if (!MediaTypeUtils.isValid(allContentTypes, requestMT)) {
throw new CougarValidationException(ServerFaultCode.ContentTypeNotValid, "Input content type is not valid: " + requestMT);
}
String candidateContentType = requestMT.getType() + "/" + requestMT.getSubtype();
MediaType normalizedMediaType = validContentTypes.get(candidateContentType);
if (normalizedMediaType == null) {
throw new CougarValidationException(ServerFaultCode.FrameworkError, "Input content type " + contentType + " failed to find a normalized type using key " + candidateContentType);
}
return normalizedMediaType;
}
return null;
}