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, String indexFile, Charset defaultCharset)
Creates a newAssetServlet
that 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 void
doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
String
getIndexFile()
protected URL
getResourceUrl(String absoluteRequestedResourcePath)
URL
getResourceURL()
String
getUriPath()
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 newAssetServlet
that serves static assets loaded fromresourceURL
(typically a file: or jar: URL). The assets are served at URIs rooted aturiPath
. For example, given aresourceURL
of"file:/data/assets"
and auriPath
of"/js"
, anAssetServlet
would serve the contents of/data/assets/example.js
in response to a request for/js/example.js
. If a directory is requested andindexFile
is defined, thenAssetServlet
will attempt to serve a file with that name in that directory. If a directory is requested andindexFile
is 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
-
-
Method Detail
-
getResourceURL
public URL getResourceURL()
-
getUriPath
public String getUriPath()
-
getIndexFile
@Nullable public String getIndexFile()
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
readResource
protected byte[] readResource(URL requestedResourceURL) throws IOException
- Throws:
IOException
-
-