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:
parent
eefd1c4ca6
commit
8e4e0f3531
|
@ -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) {
|
||||
|
|
|
@ -45,7 +45,6 @@ import javax.servlet.descriptor.JspConfigDescriptor;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
@ -258,9 +257,17 @@ 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".
|
||||
*/
|
||||
@Override
|
||||
public String getMimeType(String filePath) {
|
||||
return MimeTypeResolver.getMimeType(filePath);
|
||||
String mimeType = MimeTypeResolver.getMimeType(filePath);
|
||||
return ("application/octet-stream".equals(mimeType)) ? null : mimeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -74,10 +74,12 @@ public class PathExtensionContentNegotiationStrategyTests {
|
|||
assertEquals(Arrays.asList(new MediaType("application", "vnd.ms-excel")), mediaTypes);
|
||||
}
|
||||
|
||||
// SPR-10334
|
||||
|
||||
@Test
|
||||
public void getMediaTypeFromFilenameNoJaf() {
|
||||
|
||||
this.servletRequest.setRequestURI("test.xls");
|
||||
this.servletRequest.setRequestURI("test.json");
|
||||
|
||||
ServletContext servletContext = this.servletRequest.getServletContext();
|
||||
PathExtensionContentNegotiationStrategy strategy =
|
||||
|
@ -86,7 +88,7 @@ public class PathExtensionContentNegotiationStrategyTests {
|
|||
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(this.webRequest);
|
||||
|
||||
assertEquals(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM), mediaTypes);
|
||||
assertEquals(Collections.emptyList(), mediaTypes);
|
||||
}
|
||||
|
||||
// SPR-8678
|
||||
|
|
Loading…
Reference in New Issue