Class ResourceController

java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.support.WebContentGenerator
org.springframework.web.servlet.mvc.AbstractController
org.springframework.extensions.webscripts.servlet.mvc.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
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    applyHeaders(String path, jakarta.servlet.http.HttpServletResponse response, long contentLength, long lastModified)
     
    void
    commitResponse(String path, URL resourceUrl, jakarta.servlet.http.HttpServletResponse response)
    Commit the resource to the response stream.
    void
    commitResponse(String path, org.springframework.core.io.Resource resource, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     
    protected void
    Fast stream copy method - uses ThreadLocal byte buffer to avoid reallocating byte arrays
    boolean
    dispatchResource(String path, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Dispatches to the resource with the given path
    Gets the default url.
    org.springframework.web.servlet.ModelAndView
    handleRequestInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     
    void
    setDefaultUrl(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, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isRequireSession, prepareResponse, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, 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 Details

    • ResourceController

      public ResourceController()
  • Method Details

    • setDefaultUrl

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

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

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

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

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

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

      protected void applyHeaders(String path, jakarta.servlet.http.HttpServletResponse response, long contentLength, long lastModified)
    • copyStream

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