Package org.springframework.web.servlet.resource

Examples of org.springframework.web.servlet.resource.ResourceHttpRequestHandler


    }

    Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
    for (ResourceHandlerRegistration registration : registrations) {
      for (String pathPattern : registration.getPathPatterns()) {
        ResourceHttpRequestHandler requestHandler = registration.getRequestHandler();
        requestHandler.setServletContext(servletContext);
        requestHandler.setApplicationContext(applicationContext);
        urlMap.put(pathPattern, requestHandler);
      }
    }

    SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
View Full Code Here


  /**
   * Returns a {@link ResourceHttpRequestHandler} instance.
   */
  protected ResourceHttpRequestHandler getRequestHandler() {
    Assert.isTrue(!CollectionUtils.isEmpty(locations), "At least one location is required for resource handling.");
    ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler();
    requestHandler.setLocations(locations);
    if (cachePeriod != null) {
      requestHandler.setCacheSeconds(cachePeriod);
    }
    return requestHandler;
  }
View Full Code Here

  /**
   * Returns a {@link ResourceHttpRequestHandler} instance.
   */
  protected ResourceHttpRequestHandler getRequestHandler() {
    ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
    if (this.resourceChainRegistration != null) {
      handler.setResourceResolvers(this.resourceChainRegistration.getResourceResolvers());
      handler.setResourceTransformers(this.resourceChainRegistration.getResourceTransformers());
    }
    handler.setLocations(this.locations);
    if (this.cachePeriod != null) {
      handler.setCacheSeconds(this.cachePeriod);
    }
    return handler;
  }
View Full Code Here

    }

    Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
    for (ResourceHandlerRegistration registration : this.registrations) {
      for (String pathPattern : registration.getPathPatterns()) {
        ResourceHttpRequestHandler handler = registration.getRequestHandler();
        handler.setServletContext(this.servletContext);
        handler.setApplicationContext(this.appContext);
        try {
          handler.afterPropertiesSet();
        }
        catch (Exception e) {
          throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", e);
        }
        urlMap.put(pathPattern, handler);
View Full Code Here

    loadBeanDefinitions("mvc-config-resources.xml", 9);

    HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
    assertNotNull(adapter);

    ResourceHttpRequestHandler handler = appContext.getBean(ResourceHttpRequestHandler.class);
    assertNotNull(handler);

    SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
    assertNotNull(mapping);
    assertEquals(Ordered.LOWEST_PRECEDENCE - 1, mapping.getOrder());
View Full Code Here

    SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
    assertNotNull(mapping);
    assertEquals(5, mapping.getOrder());
    assertNotNull(mapping.getUrlMap().get("/resources/**"));

    ResourceHttpRequestHandler handler = appContext.getBean((String)mapping.getUrlMap().get("/resources/**"),
        ResourceHttpRequestHandler.class);
    assertNotNull(handler);
    assertEquals(3600, handler.getCacheSeconds());
  }
View Full Code Here

    loadBeanDefinitions("mvc-config-resources-chain.xml", 10);

    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);

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

    CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
    assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
    assertEquals("test-resource-cache", cachingResolver.getCache().getName());

    VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(1);
    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(3));
    assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
    assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
    assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));

View Full Code Here

    loadBeanDefinitions("mvc-config-resources-chain-no-auto.xml", 11);

    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);

    List<ResourceResolver> resolvers = handler.getResourceResolvers();
    assertThat(resolvers, Matchers.hasSize(3));
    assertThat(resolvers.get(0), Matchers.instanceOf(VersionResourceResolver.class));
    assertThat(resolvers.get(1), Matchers.instanceOf(GzipResourceResolver.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));
  }
View Full Code Here

  public void mapPathToLocation() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/testStylesheet.css");

    ResourceHttpRequestHandler handler = getHandler("/resources/**");
    handler.handleRequest(request, this.response);

    assertEquals("test stylesheet content", this.response.getContentAsString());
  }
View Full Code Here

  public void resourceChain() throws Exception {
    ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
    ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
    this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

    ResourceHttpRequestHandler handler = getHandler("/resources/**");
    List<ResourceResolver> resolvers = handler.getResourceResolvers();
    assertThat(resolvers.toString(), resolvers, Matchers.hasSize(3));
    assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
    CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
    assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
    assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
    assertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.class));

    List<ResourceTransformer> transformers = handler.getResourceTransformers();
    assertThat(transformers, Matchers.hasSize(2));
    assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
    assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.resource.ResourceHttpRequestHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.