org.springframework.web.servlet.resource.EncodedResourceResolver Java Examples

The following examples show how to use org.springframework.web.servlet.resource.EncodedResourceResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MvcConfig.java    From tutorials with MIT License 6 votes vote down vote up
@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 EncodedResourceResolver()).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 EncodedResourceResolver());
    }
    // For examples using Spring 4.0.7
    else 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/");

    }
}
 
Example #2
Source File: MvcNamespaceTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testResourcesWithResolversTransformersCustom() throws Exception {
	loadBeanDefinitions("mvc-config-resources-chain-no-auto.xml");

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertNotNull(mapping.getUrlMap().get("/resources/**"));
	ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"),
			ResourceHttpRequestHandler.class);
	assertNotNull(handler);

	assertThat(handler.getCacheControl().getHeaderValue(),
			Matchers.equalTo(CacheControl.maxAge(1, TimeUnit.HOURS)
					.sMaxAge(30, TimeUnit.MINUTES).cachePublic().getHeaderValue()));

	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers, Matchers.hasSize(3));
	assertThat(resolvers.get(0), Matchers.instanceOf(VersionResourceResolver.class));
	assertThat(resolvers.get(1), Matchers.instanceOf(EncodedResourceResolver.class));
	assertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.class));

	VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(0);
	assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
			Matchers.instanceOf(FixedVersionStrategy.class));
	assertThat(versionResolver.getStrategyMap().get("/**"),
			Matchers.instanceOf(ContentVersionStrategy.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.instanceOf(AppCacheManifestTransformer.class));
}
 
Example #3
Source File: MvcNamespaceTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testResourcesWithResolversTransformersCustom() throws Exception {
	loadBeanDefinitions("mvc-config-resources-chain-no-auto.xml");

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertNotNull(mapping.getUrlMap().get("/resources/**"));
	ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"),
			ResourceHttpRequestHandler.class);
	assertNotNull(handler);

	assertThat(handler.getCacheControl().getHeaderValue(),
			Matchers.equalTo(CacheControl.maxAge(1, TimeUnit.HOURS)
					.sMaxAge(30, TimeUnit.MINUTES).cachePublic().getHeaderValue()));

	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers, Matchers.hasSize(3));
	assertThat(resolvers.get(0), Matchers.instanceOf(VersionResourceResolver.class));
	assertThat(resolvers.get(1), Matchers.instanceOf(EncodedResourceResolver.class));
	assertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.class));

	VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(0);
	assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
			Matchers.instanceOf(FixedVersionStrategy.class));
	assertThat(versionResolver.getStrategyMap().get("/**"),
			Matchers.instanceOf(ContentVersionStrategy.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.instanceOf(AppCacheManifestTransformer.class));
}
 
Example #4
Source File: ResourceConfig.java    From springsecuritytotp with MIT License 5 votes vote down vote up
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
	registry.addResourceHandler("/", "/index.html")
			.addResourceLocations("classpath:/static/")
			.setCacheControl(CacheControl.noCache()).resourceChain(false)
			.addResolver(new EncodedResourceResolver());

	registry.addResourceHandler("/**").addResourceLocations("classpath:/static/")
			.setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS).cachePublic())
			.resourceChain(false).addResolver(new EncodedResourceResolver());
}