Relax ServletContext check for resource handling
This is a follow-up on commit 3b95e0b relaxing the expectation that a
ServletContext is present. Instead we check defensively and fall back
on PathExtensionContentNegotiationStrategy which can use JAF.
Issue: SPR-14577
This commit is contained in:
@@ -79,6 +79,8 @@ public class ResourceHandlerRegistryTests {
|
||||
request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/testStylesheet.css");
|
||||
|
||||
ResourceHttpRequestHandler handler = getHandler("/resources/**");
|
||||
handler.afterPropertiesSet();
|
||||
handler.afterSingletonsInstantiated();
|
||||
handler.handleRequest(request, this.response);
|
||||
|
||||
assertEquals("test stylesheet content", this.response.getContentAsString());
|
||||
|
||||
@@ -81,6 +81,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
this.handler.setCacheSeconds(3600);
|
||||
this.handler.setServletContext(new TestServletContext());
|
||||
this.handler.afterPropertiesSet();
|
||||
this.handler.afterSingletonsInstantiated();
|
||||
|
||||
this.request = new MockHttpServletRequest("GET", "");
|
||||
this.response = new MockHttpServletResponse();
|
||||
@@ -147,6 +148,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
.addFixedVersionStrategy("versionString", "/**");
|
||||
this.handler.setResourceResolvers(Arrays.asList(versionResolver, new PathResourceResolver()));
|
||||
this.handler.afterPropertiesSet();
|
||||
this.handler.afterSingletonsInstantiated();
|
||||
|
||||
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "versionString/foo.css");
|
||||
this.handler.handleRequest(this.request, this.response);
|
||||
@@ -253,6 +255,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
handler.setLocations(paths);
|
||||
handler.setContentNegotiationManager(manager);
|
||||
handler.afterPropertiesSet();
|
||||
handler.afterSingletonsInstantiated();
|
||||
|
||||
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");
|
||||
handler.handleRequest(this.request, this.response);
|
||||
@@ -274,6 +277,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
handler.setLocations(paths);
|
||||
handler.setContentNegotiationManager(manager);
|
||||
handler.afterPropertiesSet();
|
||||
handler.afterSingletonsInstantiated();
|
||||
|
||||
this.request.addHeader("Accept", "application/json,text/plain,*/*");
|
||||
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.html");
|
||||
@@ -302,6 +306,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
handler.setServletContext(servletContext);
|
||||
handler.setLocations(paths);
|
||||
handler.afterPropertiesSet();
|
||||
handler.afterSingletonsInstantiated();
|
||||
|
||||
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");
|
||||
handler.handleRequest(this.request, this.response);
|
||||
@@ -416,6 +421,7 @@ public class ResourceHttpRequestHandlerTests {
|
||||
handler.setServletContext(new MockServletContext());
|
||||
handler.setLocations(Arrays.asList(location1, location2));
|
||||
handler.afterPropertiesSet();
|
||||
handler.afterSingletonsInstantiated();
|
||||
|
||||
Resource[] locations = pathResolver.getAllowedLocations();
|
||||
assertEquals(1, locations.length);
|
||||
|
||||
Reference in New Issue
Block a user