java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
net.i2p.servlet.ErrorServlet
- All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Common servlet for errors This is intended for webapps and local plugins. It is not appropriate for eepsites or remotely-accessible plugins, as it uses local console resources. See http://www.eclipse.org/jetty/documentation/current/custom-error-pages.html for how to add to web.xml or see examples in bundled webapps. Init parameters:
- CSSPath - absolute URL of CSS to reference, starting with /, defaults to console theme
- name - webapp or plugin name, will be translated with bundle, e.g. SusiMail
- bundle - package of translation bundle, e.g. net.i2p.susimail.web.messages
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe bundle nameprivate final I2PAppContextThe contextprivate StringThe CSS pathprivate StringThe default bundleprivate final Stringto be added to headprivate Stringfor webapp translationprivate static final StringBase theme pathprivate static final StringConsole bundle nameprivate static final StringDefault CSSprivate static final StringDefault iconprivate static final StringDefault themeprivate static final StringTheme property nameprivate static final StringProxy CSSprivate static final longFixed id, the servlet is never serialized across versions.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprotected StringTranslate a string using the console bundle.protected StringTranslate a string using the console bundle.protected StringTranslate a string using the console bundle.protected StringTranslate a string using the webapp bundle.protected voiddoGet(HttpServletRequest req, HttpServletResponse resp) Handle GET request and render error page HTML.protected voiddoPost(HttpServletRequest req, HttpServletResponse resp) Needed if the errored page was a POSTprivate StringgetSanitizedStackTrace(Throwable errorCause) Formats a stack trace with the paths stripped.voidinit()Load CSS path, webapp name, and bundle from init parameters.protected voidoutputMessage(PrintWriter out, int errorCode, String errorMsg, String errorURI, Throwable errorCause) Override for specific cases.private voidprint404Error(PrintWriter out, String errorURI) Writes the not-found error page.private voidprintInternalError(PrintWriter out, int errorCode, String errorMsg, String errorURI, Throwable errorCause) Writes the internal error page.private voidprintStylesheet(PrintWriter out, String themePath) Links the theme's stylesheet into the error page.private voidWrites the router version block of the error page.private voidprintUnsupportedError(PrintWriter out, int errorCode) Writes the method-not-supported page.Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, serviceMethods inherited from class GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
Field Details
serialVersionUID
private static final long serialVersionUIDFixed id, the servlet is never serialized across versions.- See Also:
_context
The contextCONSOLE_BUNDLE_NAME
PROP_THEME_NAME
DEFAULT_THEME
BASE_THEME_PATH
DEFAULT_ICO
DEFAULT_CSS
PROXY_CSS
_icoPath
_cssPath
The CSS path_webappName
for webapp translation_bundleName
The bundle name_defaultBundle
The default bundle
Constructor Details
ErrorServlet
public ErrorServlet()Servlet for rendering error pages in webapps and plugins.
Method Details
init
Load CSS path, webapp name, and bundle from init parameters.- Overrides:
initin classGenericServlet- Throws:
ServletException
doGet
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException Handle GET request and render error page HTML.- Overrides:
doGetin classHttpServlet- Throws:
ServletExceptionIOException
doPost
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException Needed if the errored page was a POST- Overrides:
doPostin classHttpServlet- Throws:
ServletExceptionIOException
outputMessage
protected void outputMessage(PrintWriter out, int errorCode, String errorMsg, String errorURI, Throwable errorCause) Override for specific cases. This supports 403, 404, and 500+. Output HTML that goes inside the div.- Parameters:
out- where the HTML is writtenerrorCode- e.g. 404errorMsg- non-null, may be empty, already HTML-escapederrorURI- non-null, may be empty, already HTML-escapederrorCause- may be null
printStylesheet
Links the theme's stylesheet into the error page.- Parameters:
out- where the page is writtenthemePath- path of the active theme
print404Error
Writes the not-found error page.- Parameters:
out- where the page is writtenerrorURI- the address that was not found
printInternalError
private void printInternalError(PrintWriter out, int errorCode, String errorMsg, String errorURI, Throwable errorCause) Writes the internal error page.- Parameters:
out- where the page is writtenerrorCode- the HTTP status to showerrorMsg- the message to showerrorURI- the address that failederrorCause- the exception, may be null
printUnsupportedError
Writes the method-not-supported page.- Parameters:
out- where the page is writtenerrorCode- the HTTP status to show
getSanitizedStackTrace
printSystemInfo
Writes the router version block of the error page.- Parameters:
out- where the page is written
_w
_t
_t
_t