Class ErrorHandler
- All Implemented Interfaces:
Handler, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
- Direct Known Subclasses:
ErrorPageErrorHandler
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractHandler
AbstractHandler.ErrorDispatchHandlerNested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbadMessageError(int status, String reason, HttpFields.Mutable fields) Bad Message Error bodybooleanerrorPageForMethod(String method) protected voidgenerateAcceptableResponse(Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int code, String message) Generate an acceptable error response.protected voidgenerateAcceptableResponse(Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int code, String message, String contentType) Generate an acceptable error response for a mime type.protected WritergetAcceptableWriter(Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Deprecated.Get the cacheControl.static ErrorHandlergetErrorHandler(Server server, ContextHandler context) booleanDeprecated.voidhandle(String target, Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Handle a request.protected voidhandleErrorPage(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message) booleanbooleanbooleanvoidsetCacheControl(String cacheControl) Set the cacheControl.voidsetShowMessageInTitle(boolean showMessageInTitle) Set if true, the error message appears in page title.voidsetShowServlet(boolean showServlet) voidsetShowStacks(boolean showStacks) protected voidprotected voidwriteErrorJson(jakarta.servlet.http.HttpServletRequest request, PrintWriter writer, int code, String message) protected voidwriteErrorPage(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) protected voidwriteErrorPageBody(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) protected voidwriteErrorPageHead(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message) protected voidwriteErrorPageMessage(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message, String uri) protected voidwriteErrorPageStacks(jakarta.servlet.http.HttpServletRequest request, Writer writer) protected voidwriteErrorPlain(jakarta.servlet.http.HttpServletRequest request, PrintWriter writer, int code, String message) Methods inherited from class AbstractHandler
destroy, doError, doStart, doStop, getServer, setServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Field Details
-
ERROR_PAGE
- See Also:
-
ERROR_CONTEXT
- See Also:
-
ERROR_CHARSET
- See Also:
-
-
Constructor Details
-
ErrorHandler
public ErrorHandler()
-
-
Method Details
-
errorPageForMethod
-
handle
public void handle(String target, Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException, jakarta.servlet.ServletException Description copied from interface:HandlerHandle a request.- Specified by:
handlein interfaceHandler- Specified by:
handlein classAbstractHandler- Parameters:
target- The target of the request - either a URI or a name.baseRequest- The original unwrapped request object.request- The request either as theRequestobject or a wrapper of that request.response- The response as theResponseobject or a wrapper of that request.- Throws:
IOException- if unable to handle the request or response processingjakarta.servlet.ServletException- if unable to handle the request or response due to underlying servlet issue
-
generateAcceptableResponse
protected void generateAcceptableResponse(Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int code, String message) throws IOException Generate an acceptable error response.This method is called to generate an Error page of a mime type that is acceptable to the user-agent. The Accept header is evaluated in quality order and the method
generateAcceptableResponse(Request, HttpServletRequest, HttpServletResponse, int, String, String)is called for each mimetype until the response is written to or committed.- Parameters:
baseRequest- The base requestrequest- The servlet request (may be wrapped)response- The response (may be wrapped)code- the http error codemessage- the http error message- Throws:
IOException- if the response cannot be generated
-
getAcceptableWriter
@Deprecated protected Writer getAcceptableWriter(Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException Deprecated.Returns an acceptable writer for an error page.Uses the user-agent's
Accept-Charsetto get responseWriter. The acceptable charsets are tested in quality order if they are known to the JVM and the first known is set onServletResponse.setCharacterEncoding(String)and theServletResponse.getWriter()method used to return a writer. If there is noAccept-Charsetheader thenISO-8859-1is used. If '*' is the highest quality known charset, thenutf-8is used.- Parameters:
baseRequest- The base requestrequest- The servlet request (may be wrapped)response- The response (may be wrapped)- Returns:
- A
Writerif there is a known acceptable charset or null - Throws:
IOException- if a Writer cannot be returned
-
generateAcceptableResponse
protected void generateAcceptableResponse(Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int code, String message, String contentType) throws IOException Generate an acceptable error response for a mime type.This method is called for each mime type in the users agent's
Acceptheader, untilRequest.isHandled()is true and a response of the appropriate type is generated.The default implementation handles "text/html", "text/*" and "*/*". The method can be overridden to handle other types. Implementations must immediate produce a response and may not be async.
- Parameters:
baseRequest- The base requestrequest- The servlet request (may be wrapped)response- The response (may be wrapped)code- the http error codemessage- the http error messagecontentType- The mimetype to generate (may be */*or other wildcard)- Throws:
IOException- if a response cannot be generated
-
handleErrorPage
protected void handleErrorPage(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message) throws IOException - Throws:
IOException
-
writeErrorPage
protected void writeErrorPage(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException - Throws:
IOException
-
writeErrorPageHead
protected void writeErrorPageHead(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message) throws IOException - Throws:
IOException
-
writeErrorPageBody
protected void writeErrorPageBody(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException - Throws:
IOException
-
writeErrorPageMessage
protected void writeErrorPageMessage(jakarta.servlet.http.HttpServletRequest request, Writer writer, int code, String message, String uri) throws IOException - Throws:
IOException
-
writeErrorPlain
protected void writeErrorPlain(jakarta.servlet.http.HttpServletRequest request, PrintWriter writer, int code, String message) -
writeErrorJson
protected void writeErrorJson(jakarta.servlet.http.HttpServletRequest request, PrintWriter writer, int code, String message) -
writeErrorPageStacks
protected void writeErrorPageStacks(jakarta.servlet.http.HttpServletRequest request, Writer writer) throws IOException - Throws:
IOException
-
badMessageError
Bad Message Error bodyGenerate an error response body to be sent for a bad message. In this case there is something wrong with the request, so either a request cannot be built, or it is not safe to build a request. This method allows for a simple error page body to be returned and some response headers to be set.
- Parameters:
status- The error code that will be sentreason- The reason for the error code (may be null)fields- The header fields that will be sent with the response.- Returns:
- The content as a ByteBuffer, or null for no body.
-
getCacheControl
Get the cacheControl.- Returns:
- the cacheControl header to set on error responses.
-
setCacheControl
Set the cacheControl.- Parameters:
cacheControl- the cacheControl header to set on error responses.
-
isShowServlet
public boolean isShowServlet()- Returns:
- True if the error page will show the Servlet that generated the error
-
setShowServlet
public void setShowServlet(boolean showServlet) - Parameters:
showServlet- True if the error page will show the Servlet that generated the error
-
isShowStacks
public boolean isShowStacks()- Returns:
- True if stack traces are shown in the error pages
-
setShowStacks
public void setShowStacks(boolean showStacks) - Parameters:
showStacks- True if stack traces are shown in the error pages
-
setShowMessageInTitle
public void setShowMessageInTitle(boolean showMessageInTitle) Set if true, the error message appears in page title.- Parameters:
showMessageInTitle- if true, the error message appears in page title
-
getShowMessageInTitle
Deprecated.useisShowMessageInTitle()instead -
isShowMessageInTitle
public boolean isShowMessageInTitle() -
write
- Throws:
IOException
-
getErrorHandler
-
isShowMessageInTitle()instead