Change MediaTypeFactory to return Optional

This commit changes the `MediaTypeFactory` to return
`Optional<MediaType>` (instead of a plain `MediaType`) for the
`getMediaType` methods.

Issue: SPR-14908
This commit is contained in:
Arjen Poutsma
2017-03-23 10:14:43 +01:00
parent 3d68c496f1
commit fd1db57e05
9 changed files with 38 additions and 36 deletions

View File

@@ -263,14 +263,12 @@ public class MockServletContext implements ServletContext {
@Override
public String getMimeType(String filePath) {
String extension = StringUtils.getFilenameExtension(filePath);
MediaType result;
if (this.mimeTypes.containsKey(extension)) {
result = this.mimeTypes.get(extension);
return this.mimeTypes.get(extension).toString();
}
else {
result = MediaTypeFactory.getMediaType(filePath);
return MediaTypeFactory.getMediaType(filePath).orElse(MediaType.APPLICATION_OCTET_STREAM).toString();
}
return result != null ? result.toString() : null;
}
/**