class BasicServlet extends HttpServlet
Supports HEAD and GET only, for resources from the .war and local files. Supports files and resource only. Supports MIME types with local overrides and additions. Supports Last-Modified. Supports single request ranges.
Does not support directories or "welcome files". Does not support gzip. Does not support multiple request ranges. Does not cache.
POST returns 405. Directories return 403. Jar resources are sent with a long cache directive.
------------------------------------------------------------
The default servlet. This servlet, normally mapped to /, provides the handling for static content, OPTION and TRACE methods for the context. The following initParameters are supported, these can be set on the servlet itself:
resourceBase Set to replace the context resource base warBase Path allowed for resource in war
| Modifier and Type | Class and Description |
|---|---|
static interface |
BasicServlet.HttpContent
from Jetty HttpContent.java
|
| Modifier and Type | Field and Description |
|---|---|
protected I2PAppContext |
_context |
protected Log |
_log |
protected File |
_resourceBase |
| Constructor and Description |
|---|
BasicServlet() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addMimeMapping(String extension,
String type)
Add a MIME type mapping for an extension.
|
protected static String |
addPaths(String base,
String path)
Simple version of URIUtil.addPaths().
|
protected static String |
decodePath(String path)
Simple version of URIUtil.decodePath().
|
protected void |
doDelete(HttpServletRequest request,
HttpServletResponse response) |
protected void |
doGet(HttpServletRequest request,
HttpServletResponse response) |
protected void |
doOptions(HttpServletRequest request,
HttpServletResponse response) |
protected void |
doPost(HttpServletRequest request,
HttpServletResponse response) |
protected void |
doTrace(HttpServletRequest request,
HttpServletResponse response) |
protected static String |
encodePath(String path)
Simple version of URIUtil.encodePath().
|
BasicServlet.HttpContent |
getContent(String pathInContext,
long limit)
Get Resource to serve.
|
protected String |
getMimeType(String filename)
Get the MIME type by filename extension.
|
File |
getResource(String pathInContext)
Get Resource to serve.
|
void |
init(ServletConfig cfg) |
protected void |
loadMimeMap(String resourcePath)
Load MIME type mappings from a resource file.
|
protected boolean |
passConditionalHeaders(HttpServletRequest request,
HttpServletResponse response,
BasicServlet.HttpContent content)
Check modification date headers.
|
protected void |
sendData(HttpServletRequest request,
HttpServletResponse response,
BasicServlet.HttpContent content) |
protected void |
setResourceBase(File base)
Files are served from here.
|
protected void |
setWarBase(String base)
Only paths starting with this in the path are served.
|
protected void |
writeHeaders(HttpServletResponse response,
BasicServlet.HttpContent content,
long count)
Write response headers for the content.
|
doHead, doPut, getLastModified, service, servicedestroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, logprotected final transient I2PAppContext _context
protected final transient Log _log
protected File _resourceBase
protected void addMimeMapping(String extension, String type)
extension - the file extension (without the dot)type - the MIME type to associate with the extensionprotected static String addPaths(String base, String path)
base - the base pathpath - the path to add (may be null)protected static String decodePath(String path) throws MalformedURLException
path - the path to decodeMalformedURLException - if the path contains invalid escape sequencesprotected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doDelete in class HttpServletServletExceptionIOExceptionprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doGet in class HttpServletServletExceptionIOExceptionprotected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doOptions in class HttpServletServletExceptionIOExceptionprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doPost in class HttpServletServletExceptionIOExceptionprotected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doTrace in class HttpServletServletExceptionIOExceptionprotected static String encodePath(String path)
path - the path to encodepublic BasicServlet.HttpContent getContent(String pathInContext, long limit)
pathInContext - The path to find a resource for.limit - the maximum content length to serve, or 0 for unlimitedprotected String getMimeType(String filename)
filename - A file namepublic File getResource(String pathInContext)
pathInContext - The path to find a resource for.public void init(ServletConfig cfg) throws ServletException
init in interface Servletinit in class GenericServletServletExceptionprotected void loadMimeMap(String resourcePath)
resourcePath - the resource path in the classpath, without ".properties" extensionprotected boolean passConditionalHeaders(HttpServletRequest request, HttpServletResponse response, BasicServlet.HttpContent content) throws IOException
request - the HTTP requestresponse - the HTTP responsecontent - the content to checkIOException - if an I/O error occursprotected void sendData(HttpServletRequest request, HttpServletResponse response, BasicServlet.HttpContent content) throws IOException
IOExceptionprotected void setResourceBase(File base) throws UnavailableException
base - the directory to serve files fromUnavailableException - if the base directory doesn't existprotected void setWarBase(String base)
base - the base path that must be matchedprotected void writeHeaders(HttpServletResponse response, BasicServlet.HttpContent content, long count) throws IOException
response - the HTTP responsecontent - the content to write headers forcount - the content lengthIOException - if an I/O error occurs