Class ResourceController

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.mvc.Controller

    public class ResourceController
    extends org.springframework.web.servlet.mvc.AbstractController
    Spring controller for retrieving and serving resources.

    This controller retrieves content by interrogating resource providers in the following order:

    1) Web application context resources (Jar files, followed by classpath) 2) Web application path
    3) Delegation to a default url handler

    The order allows resource assets to be overriden in jar file or classpath based extensions.

    The following URL format is supported: /res/

    Author:
    kevinr, muzquiano
    • Field Summary

      • Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator

        HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void applyHeaders​(java.lang.String path, javax.servlet.http.HttpServletResponse response, long contentLength, long lastModified)  
      void commitResponse​(java.lang.String path, java.net.URL resourceUrl, javax.servlet.http.HttpServletResponse response)
      Commit the resource to the response stream.
      void commitResponse​(java.lang.String path, org.springframework.core.io.Resource resource, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void copyStream​(java.io.InputStream in, java.io.OutputStream out)
      Fast stream copy method - uses ThreadLocal byte buffer to avoid reallocating byte arrays
      boolean dispatchResource​(java.lang.String path, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Dispatches to the resource with the given path
      java.lang.String getDefaultUrl()
      Gets the default url.
      org.springframework.web.servlet.ModelAndView handleRequestInternal​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      void setDefaultUrl​(java.lang.String defaultUrl)
      Sets the default url.
      • Methods inherited from class org.springframework.web.servlet.mvc.AbstractController

        handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
      • Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator

        applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
      • Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

        getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
      • Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

        getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceController

        public ResourceController()
    • Method Detail

      • setDefaultUrl

        public void setDefaultUrl​(java.lang.String defaultUrl)
        Sets the default url.
        Parameters:
        defaultUrl - the new default url
      • getDefaultUrl

        public java.lang.String getDefaultUrl()
        Gets the default url.
        Returns:
        the default url
      • handleRequestInternal

        public org.springframework.web.servlet.ModelAndView handleRequestInternal​(javax.servlet.http.HttpServletRequest request,
                                                                                  javax.servlet.http.HttpServletResponse response)
                                                                           throws java.lang.Exception
        Specified by:
        handleRequestInternal in class org.springframework.web.servlet.mvc.AbstractController
        Throws:
        java.lang.Exception
      • dispatchResource

        public boolean dispatchResource​(java.lang.String path,
                                        javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)
                                 throws javax.servlet.ServletException,
                                        java.io.IOException
        Dispatches to the resource with the given path
        Parameters:
        path - the path
        request - the request
        response - the response
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • commitResponse

        public void commitResponse​(java.lang.String path,
                                   java.net.URL resourceUrl,
                                   javax.servlet.http.HttpServletResponse response)
                            throws java.io.IOException
        Commit the resource to the response stream. Sets appropriate date, length and content type headers.
        Throws:
        java.io.IOException
      • commitResponse

        public void commitResponse​(java.lang.String path,
                                   org.springframework.core.io.Resource resource,
                                   javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response)
                            throws java.io.IOException,
                                   javax.servlet.ServletException
        Throws:
        java.io.IOException
        javax.servlet.ServletException
      • applyHeaders

        protected void applyHeaders​(java.lang.String path,
                                    javax.servlet.http.HttpServletResponse response,
                                    long contentLength,
                                    long lastModified)
      • copyStream

        protected void copyStream​(java.io.InputStream in,
                                  java.io.OutputStream out)
                           throws java.io.IOException
        Fast stream copy method - uses ThreadLocal byte buffer to avoid reallocating byte arrays
        Throws:
        java.io.IOException