use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class PathResourceResolverTests method checkResource.
@Test
public void checkResource() throws IOException {
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
testCheckResource(location, "../testsecret/secret.txt");
testCheckResource(location, "test/../../testsecret/secret.txt");
location = new UrlResource(getClass().getResource("./test/"));
String secretPath = new UrlResource(getClass().getResource("testsecret/secret.txt")).getURL().getPath();
testCheckResource(location, "file:" + secretPath);
testCheckResource(location, "/file:" + secretPath);
testCheckResource(location, "/" + secretPath);
testCheckResource(location, "////../.." + secretPath);
testCheckResource(location, "/%2E%2E/testsecret/secret.txt");
testCheckResource(location, "/%2e%2e/testsecret/secret.txt");
testCheckResource(location, " " + secretPath);
testCheckResource(location, "/ " + secretPath);
testCheckResource(location, "url:" + secretPath);
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class PathResourceResolverTests method testCheckResource.
private void testCheckResource(Resource location, String requestPath) throws IOException {
Resource actual = this.resolver.resolveResource(null, requestPath, Arrays.asList(location), null);
if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) {
fail(requestPath + " doesn't actually exist as a relative path");
}
assertNull(actual);
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class PathResourceResolverTests method checkFileLocation.
// SPR-12747
@Test
public void checkFileLocation() throws Exception {
Resource resource = new ClassPathResource("test/main.css", PathResourceResolver.class);
assertTrue(this.resolver.checkResource(resource, resource));
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class ResourceHttpRequestHandlerTests method getMediaTypeWithFavorPathExtensionOff.
// SPR-14577
@Test
public void getMediaTypeWithFavorPathExtensionOff() throws Exception {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.setFavorPathExtension(false);
factory.afterPropertiesSet();
ContentNegotiationManager manager = factory.getObject();
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setServletContext(new MockServletContext());
handler.setLocations(paths);
handler.setContentNegotiationManager(manager);
handler.afterPropertiesSet();
this.request.addHeader("Accept", "application/json,text/plain,*/*");
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.html");
handler.handleRequest(this.request, this.response);
assertEquals("text/html", this.response.getContentType());
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class ResourceHttpRequestHandlerTests method setUp.
@Before
public void setUp() throws Exception {
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
List<Resource> paths = new ArrayList<>(2);
paths.add(new ClassPathResource("test/", getClass()));
paths.add(new ClassPathResource("testalternatepath/", getClass()));
paths.add(new ClassPathResource("META-INF/resources/webjars/"));
this.handler = new ResourceHttpRequestHandler();
this.handler.setLocations(paths);
this.handler.setCacheSeconds(3600);
this.handler.setServletContext(new TestServletContext());
this.handler.afterPropertiesSet();
this.request = new MockHttpServletRequest("GET", "");
this.response = new MockHttpServletResponse();
}
Aggregations