use of org.springframework.web.servlet.resource.PathResourceResolver in project spring-framework by spring-projects.
the class ResourceHandlerRegistryTests method urlResourceWithCharset.
@Test
public void urlResourceWithCharset() {
this.registration.addResourceLocations("[charset=ISO-8859-1]file:///tmp");
this.registration.resourceChain(true);
ResourceHttpRequestHandler handler = getHandler("/resources/**");
assertThat(handler.getUrlPathHelper()).isNotNull();
List<ResourceResolver> resolvers = handler.getResourceResolvers();
PathResourceResolver resolver = (PathResourceResolver) resolvers.get(resolvers.size() - 1);
Map<Resource, Charset> locationCharsets = resolver.getLocationCharsets();
assertThat(locationCharsets.size()).isEqualTo(1);
assertThat(locationCharsets.values().iterator().next()).isEqualTo(StandardCharsets.ISO_8859_1);
}
use of org.springframework.web.servlet.resource.PathResourceResolver in project spring-framework by spring-projects.
the class ResourceChainRegistration method getResourceResolvers.
protected List<ResourceResolver> getResourceResolvers() {
if (!this.hasPathResolver) {
List<ResourceResolver> result = new ArrayList<>(this.resolvers);
if (isWebJarsAssetLocatorPresent && !this.hasWebjarsResolver) {
result.add(new WebJarsResourceResolver());
}
result.add(new PathResourceResolver());
return result;
}
return this.resolvers;
}
use of org.springframework.web.servlet.resource.PathResourceResolver in project jphp by jphp-compiler.
the class PWebServer method _makeHandlers.
protected WebServerConfig.Handlers _makeHandlers() {
return new WebServerConfig.Handlers() {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
for (ArrayMemory handler : staticHandlers) {
Memory path = handler.valueOfIndex("path");
ResourceHandlerRegistration registration;
if (path.isArray()) {
registration = registry.addResourceHandler(path.toValue(ArrayMemory.class).toStringArray());
} else {
registration = registry.addResourceHandler(path.toString());
}
Memory cachePeriod = handler.valueOfIndex("cachePeriod");
registration.setCachePeriod(cachePeriod.isNull() ? null : cachePeriod.toInteger());
Memory location = handler.valueOfIndex("location");
if (location.isArray()) {
registration.addResourceLocations(location.toValue(ArrayMemory.class).toStringArray());
} else {
registration.addResourceLocations(location.toString());
}
ResourceChainRegistration chain = registration.resourceChain(handler.valueOfIndex("cache").toBoolean());
if (handler.valueOfIndex("gzip").toBoolean()) {
chain.addResolver(new GzipResourceResolver());
}
chain.addResolver(new PathResourceResolver());
}
}
};
}
use of org.springframework.web.servlet.resource.PathResourceResolver in project tutorials by eugenp.
the class MvcConfig method addResourceHandlers.
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// For examples using Spring 4.1.0
if ((env.getProperty("resource.handler.conf")).equals("4.1.0")) {
registry.addResourceHandler("/js/**").addResourceLocations("/js/").setCachePeriod(3600).resourceChain(true).addResolver(new GzipResourceResolver()).addResolver(new PathResourceResolver());
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/", "classpath:/other-resources/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());
registry.addResourceHandler("/files/**").addResourceLocations("file:/Users/Elena/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());
registry.addResourceHandler("/other-files/**").addResourceLocations("file:/Users/Elena/").setCachePeriod(3600).resourceChain(true).addResolver(new GzipResourceResolver());
} else // For examples using Spring 4.0.7
if ((env.getProperty("resource.handler.conf")).equals("4.0.7")) {
registry.addResourceHandler("/resources/**").addResourceLocations("/", "/resources/", "classpath:/other-resources/");
registry.addResourceHandler("/files/**").addResourceLocations("file:/Users/Elena/");
}
}
use of org.springframework.web.servlet.resource.PathResourceResolver in project spring-framework by spring-projects.
the class ResourceHandlerRegistryTests method resourceChainWithOverrides.
@Test
public void resourceChainWithOverrides() {
CachingResourceResolver cachingResolver = Mockito.mock(CachingResourceResolver.class);
VersionResourceResolver versionResolver = Mockito.mock(VersionResourceResolver.class);
WebJarsResourceResolver webjarsResolver = Mockito.mock(WebJarsResourceResolver.class);
PathResourceResolver pathResourceResolver = new PathResourceResolver();
CachingResourceTransformer cachingTransformer = Mockito.mock(CachingResourceTransformer.class);
CssLinkResourceTransformer cssLinkTransformer = new CssLinkResourceTransformer();
this.registration.setCachePeriod(3600).resourceChain(false).addResolver(cachingResolver).addResolver(versionResolver).addResolver(webjarsResolver).addResolver(pathResourceResolver).addTransformer(cachingTransformer).addTransformer(cssLinkTransformer);
ResourceHttpRequestHandler handler = getHandler("/resources/**");
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers).hasSize(4);
assertThat(resolvers.get(0)).isSameAs(cachingResolver);
assertThat(resolvers.get(1)).isSameAs(versionResolver);
assertThat(resolvers.get(2)).isSameAs(webjarsResolver);
assertThat(resolvers.get(3)).isSameAs(pathResourceResolver);
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers).hasSize(2);
assertThat(transformers.get(0)).isSameAs(cachingTransformer);
assertThat(transformers.get(1)).isSameAs(cssLinkTransformer);
}
Aggregations