Package io.dropwizard.servlets.assets
Class AssetServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- io.dropwizard.servlets.assets.AssetServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class AssetServlet extends javax.servlet.http.HttpServlet- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable String defaultMediaType, @Nullable Charset defaultCharset)Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL).AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable Charset defaultCharset)Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)@Nullable CharsetgetDefaultCharset()StringgetDefaultMediaType()@Nullable StringgetIndexFile()URLgetResourceURL()protected URLgetResourceURL(String absoluteRequestedResourcePath)StringgetUriPath()protected byte[]readResource(URL requestedResourceURL)-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
-
-
-
Constructor Detail
-
AssetServlet
public AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable Charset defaultCharset)
Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL). The assets are served at URIs rooted aturiPath. For example, given aresourceURLof"file:/data/assets"and auriPathof"/js", anAssetServletwould serve the contents of/data/assets/example.jsin response to a request for/js/example.js. If a directory is requested andindexFileis defined, thenAssetServletwill attempt to serve a file with that name in that directory. If a directory is requested andindexFileis null, it will serve a 404.- Parameters:
resourcePath- the base URL from which assets are loadeduriPath- the URI path fragment in which all requests are rootedindexFile- the filename to use when directories are requested, or null to serve no indexesdefaultCharset- the default character set
-
AssetServlet
public AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable String defaultMediaType, @Nullable Charset defaultCharset)
Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL). The assets are served at URIs rooted aturiPath. For example, given aresourceURLof"file:/data/assets"and auriPathof"/js", anAssetServletwould serve the contents of/data/assets/example.jsin response to a request for/js/example.js. If a directory is requested andindexFileis defined, thenAssetServletwill attempt to serve a file with that name in that directory. If a directory is requested andindexFileis null, it will serve a 404.- Parameters:
resourcePath- the base URL from which assets are loadeduriPath- the URI path fragment in which all requests are rootedindexFile- the filename to use when directories are requested, or null to serve no indexesdefaultMediaType- the default media typedefaultCharset- the default character set- Since:
- 2.0
-
-
Method Detail
-
getResourceURL
public URL getResourceURL()
-
getUriPath
public String getUriPath()
-
getIndexFile
public @Nullable String getIndexFile()
-
getDefaultMediaType
public String getDefaultMediaType()
- Since:
- 2.0
-
getDefaultCharset
public @Nullable Charset getDefaultCharset()
- Since:
- 2.0
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
readResource
protected byte[] readResource(URL requestedResourceURL) throws IOException
- Throws:
IOException
-
-