public class ErrorHandler extends AbstractHandler
ContextHandler.setErrorHandler(ErrorHandler)
or
ContainerLifeCycle.addBean(Object)
.
It is called by the HttpResponse.sendError method to write a error page via handle(String, Request, HttpServletRequest, HttpServletResponse)
or via badMessageError(int, String, HttpFields)
for bad requests for which a dispatch cannot be done.Modifier and Type | Class and Description |
---|---|
static interface |
ErrorHandler.ErrorPageMapper |
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
static String |
ERROR_PAGE |
Constructor and Description |
---|
ErrorHandler() |
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
badMessageError(int status,
String reason,
HttpFields fields)
Bad Message Error body
|
String |
getCacheControl()
Get the cacheControl.
|
static ErrorHandler |
getErrorHandler(Server server,
ContextHandler context) |
boolean |
getShowMessageInTitle() |
void |
handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
Handle a request.
|
protected void |
handleErrorPage(HttpServletRequest request,
Writer writer,
int code,
String message) |
boolean |
isShowStacks() |
void |
setCacheControl(String cacheControl)
Set the cacheControl.
|
void |
setShowMessageInTitle(boolean showMessageInTitle) |
void |
setShowStacks(boolean showStacks) |
protected void |
write(Writer writer,
String string) |
protected void |
writeErrorPage(HttpServletRequest request,
Writer writer,
int code,
String message,
boolean showStacks) |
protected void |
writeErrorPageBody(HttpServletRequest request,
Writer writer,
int code,
String message,
boolean showStacks) |
protected void |
writeErrorPageHead(HttpServletRequest request,
Writer writer,
int code,
String message) |
protected void |
writeErrorPageMessage(HttpServletRequest request,
Writer writer,
int code,
String message,
String uri) |
protected void |
writeErrorPageStacks(HttpServletRequest request,
Writer writer) |
destroy, doStart, doStop, dumpThis, getServer, setServer
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public static final String ERROR_PAGE
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
Handler
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as the Request
object or a wrapper of that request. The HttpChannel.getCurrentHttpChannel()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The HttpChannel.getCurrentHttpChannel()
method can be used access the Response object if required.IOException
protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message) throws IOException
IOException
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException
IOException
protected void writeErrorPageHead(HttpServletRequest request, Writer writer, int code, String message) throws IOException
IOException
protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException
IOException
protected void writeErrorPageMessage(HttpServletRequest request, Writer writer, int code, String message, String uri) throws IOException
IOException
protected void writeErrorPageStacks(HttpServletRequest request, Writer writer) throws IOException
IOException
public ByteBuffer badMessageError(int status, String reason, HttpFields fields)
Generate a 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.
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.public String getCacheControl()
public void setCacheControl(String cacheControl)
cacheControl
- the cacheControl header to set on error responses.public boolean isShowStacks()
public void setShowStacks(boolean showStacks)
showStacks
- True if stack traces are shown in the error pagespublic void setShowMessageInTitle(boolean showMessageInTitle)
showMessageInTitle
- if true, the error message appears in page titlepublic boolean getShowMessageInTitle()
protected void write(Writer writer, String string) throws IOException
IOException
public static ErrorHandler getErrorHandler(Server server, ContextHandler context)
Copyright © 1995-2015 Webtide. All Rights Reserved.