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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyHeaders(String path, jakarta.servlet.http.HttpServletResponse response, long contentLength, long lastModified) voidcommitResponse(String path, URL resourceUrl, jakarta.servlet.http.HttpServletResponse response) Commit the resource to the response stream.voidcommitResponse(String path, org.springframework.core.io.Resource resource, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected voidcopyStream(InputStream in, OutputStream out) Fast stream copy method - uses ThreadLocal byte buffer to avoid reallocating byte arraysbooleandispatchResource(String path, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Dispatches to the resource with the given pathGets the default url.org.springframework.web.servlet.ModelAndViewhandleRequestInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) voidsetDefaultUrl(String defaultUrl) Sets the default url.Methods inherited from class org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSessionMethods inherited from class org.springframework.web.servlet.support.WebContentGenerator
applyCacheControl, applyCacheSeconds, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isRequireSession, prepareResponse, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setVaryByRequestHeadersMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
-
Constructor Details
-
ResourceController
public ResourceController()
-
-
Method Details
-
setDefaultUrl
Sets the default url.- Parameters:
defaultUrl- the new default url
-
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:
handleRequestInternalin classorg.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 pathrequest- the requestresponse- the response- Throws:
jakarta.servlet.ServletExceptionIOException
-
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:
IOExceptionjakarta.servlet.ServletException
-
applyHeaders
protected void applyHeaders(String path, jakarta.servlet.http.HttpServletResponse response, long contentLength, long lastModified) -
copyStream
Fast stream copy method - uses ThreadLocal byte buffer to avoid reallocating byte arrays- Throws:
IOException
-