Use null in MockServletContext for unknown mime types

MockServletContext.getMimeTypes now returns null if the Java Activation
Framework returns "application/octet-stream", which is the default
media type it returns if the mime type is unknown. This enforces the
contract for ServletContext.getMimeTypes (return null for uknown mime
types) but does mean "application/octet-stream" cannot be returned.

Issue: SPR-10334
This commit is contained in:
Rossen Stoyanchev
2013-03-07 12:33:44 -05:00
parent eefd1c4ca6
commit 8e4e0f3531
3 changed files with 22 additions and 5 deletions

View File

@@ -242,8 +242,16 @@ public class MockServletContext implements ServletContext {
return this.effectiveMinorVersion;
}
/**
* This method uses the Java Activation framework, which returns
* "application/octet-stream" when the mime type is unknown (i.e. it never returns
* {@code null}). In order to maintain the {@link ServletContext#getMimeType(String)
* contract, as of version 3.2.2, this method returns null if the mimeType is
* "application/octet-stream".
*/
public String getMimeType(String filePath) {
return MimeTypeResolver.getMimeType(filePath);
String mimeType = MimeTypeResolver.getMimeType(filePath);
return ("application/octet-stream".equals(mimeType)) ? null : mimeType;
}
public Set<String> getResourcePaths(String path) {