Handler
, org.eclipse.jetty.util.component.Destroyable
, org.eclipse.jetty.util.component.LifeCycle
public class ErrorHandler extends AbstractHandler
ContextHandler.setErrorHandler(ErrorHandler)
or
Server.setErrorHandler(ErrorHandler)
.
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 | Description |
---|---|---|
static interface |
ErrorHandler.ErrorPageMapper |
AbstractHandler.ErrorDispatchHandler
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
ERROR_PAGE |
Constructor | Description |
---|---|
ErrorHandler() |
Modifier and Type | Method | Description |
---|---|---|
java.nio.ByteBuffer |
badMessageError(int status,
java.lang.String reason,
org.eclipse.jetty.http.HttpFields fields) |
Bad Message Error body
|
void |
doError(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
Convenience method to generate error page.
|
protected void |
generateAcceptableResponse(Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
int code,
java.lang.String message) |
Generate an acceptable error response.
|
protected void |
generateAcceptableResponse(Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
int code,
java.lang.String message,
java.lang.String mimeType) |
Generate an acceptable error response for a mime type.
|
protected java.io.Writer |
getAcceptableWriter(Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
Returns an acceptable writer for an error page.
|
java.lang.String |
getCacheControl() |
Get the cacheControl.
|
static ErrorHandler |
getErrorHandler(Server server,
ContextHandler context) |
|
boolean |
getShowMessageInTitle() |
|
void |
handle(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
Handle a request.
|
protected void |
handleErrorPage(javax.servlet.http.HttpServletRequest request,
java.io.Writer writer,
int code,
java.lang.String message) |
|
boolean |
isShowStacks() |
|
void |
setCacheControl(java.lang.String cacheControl) |
Set the cacheControl.
|
void |
setShowMessageInTitle(boolean showMessageInTitle) |
|
void |
setShowStacks(boolean showStacks) |
|
protected void |
write(java.io.Writer writer,
java.lang.String string) |
|
protected void |
writeErrorPage(javax.servlet.http.HttpServletRequest request,
java.io.Writer writer,
int code,
java.lang.String message,
boolean showStacks) |
|
protected void |
writeErrorPageBody(javax.servlet.http.HttpServletRequest request,
java.io.Writer writer,
int code,
java.lang.String message,
boolean showStacks) |
|
protected void |
writeErrorPageHead(javax.servlet.http.HttpServletRequest request,
java.io.Writer writer,
int code,
java.lang.String message) |
|
protected void |
writeErrorPageMessage(javax.servlet.http.HttpServletRequest request,
java.io.Writer writer,
int code,
java.lang.String message,
java.lang.String uri) |
|
protected void |
writeErrorPageStacks(javax.servlet.http.HttpServletRequest request,
java.io.Writer writer) |
destroy, doStart, doStop, dumpThis, getServer, setServer
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
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, updateBean, updateBeans
public static final java.lang.String ERROR_PAGE
public void handle(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
Handler
handle
in interface Handler
handle
in class AbstractHandler
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
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.java.io.IOException
- if unable to handle the request or response processingpublic void doError(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
AbstractHandler
This method can be called from AbstractHandler.handle(String, Request, HttpServletRequest, HttpServletResponse)
when an DispatcherType.ERROR
dispatch
is detected and an error page needs to be generated by calling HttpServletResponse.sendError(int, String)
with the appropriate code and reason,
which are taken from ServletRequest.getAttribute(String)
for RequestDispatcher.ERROR_STATUS_CODE
and RequestDispatcher.ERROR_MESSAGE
doError
in class AbstractHandler
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
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.java.io.IOException
- if unable to handle the request or response processingfor a conveniance class that calls this method.
protected void generateAcceptableResponse(Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, int code, java.lang.String message) throws java.io.IOException
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 Request.isHandled()
is true.
baseRequest
- The base requestrequest
- The servlet request (may be wrapped)response
- The response (may be wrapped)java.io.IOException
- if the response cannot be generatedprotected java.io.Writer getAcceptableWriter(Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
Uses the user-agent's Accept-Charset
to get response
Writer
. The acceptable charsets are tested in quality order
if they are known to the JVM and the first known is set on
ServletResponse.setCharacterEncoding(String)
and the
ServletResponse.getWriter()
method used to return a writer.
If there is no Accept-Charset
header then
ISO-8859-1
is used. If '*' is the highest quality known
charset, then utf-8
is used.
baseRequest
- The base requestrequest
- The servlet request (may be wrapped)response
- The response (may be wrapped)Writer
if there is a known acceptable charset or nulljava.io.IOException
- if a Writer cannot be returnedprotected void generateAcceptableResponse(Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, int code, java.lang.String message, java.lang.String mimeType) throws java.io.IOException
This method is called for each mime type in the users agent's
Accept
header, until Request.isHandled()
is true and a
response of the appropriate type is generated.
baseRequest
- The base requestrequest
- The servlet request (may be wrapped)response
- The response (may be wrapped)mimeType
- The mimetype to generate (may be */*or other wildcard)java.io.IOException
- if a response cannot be generatedprotected void handleErrorPage(javax.servlet.http.HttpServletRequest request, java.io.Writer writer, int code, java.lang.String message) throws java.io.IOException
java.io.IOException
protected void writeErrorPage(javax.servlet.http.HttpServletRequest request, java.io.Writer writer, int code, java.lang.String message, boolean showStacks) throws java.io.IOException
java.io.IOException
protected void writeErrorPageHead(javax.servlet.http.HttpServletRequest request, java.io.Writer writer, int code, java.lang.String message) throws java.io.IOException
java.io.IOException
protected void writeErrorPageBody(javax.servlet.http.HttpServletRequest request, java.io.Writer writer, int code, java.lang.String message, boolean showStacks) throws java.io.IOException
java.io.IOException
protected void writeErrorPageMessage(javax.servlet.http.HttpServletRequest request, java.io.Writer writer, int code, java.lang.String message, java.lang.String uri) throws java.io.IOException
java.io.IOException
protected void writeErrorPageStacks(javax.servlet.http.HttpServletRequest request, java.io.Writer writer) throws java.io.IOException
java.io.IOException
public java.nio.ByteBuffer badMessageError(int status, java.lang.String reason, org.eclipse.jetty.http.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 java.lang.String getCacheControl()
public void setCacheControl(java.lang.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(java.io.Writer writer, java.lang.String string) throws java.io.IOException
java.io.IOException
public static ErrorHandler getErrorHandler(Server server, ContextHandler context)
Copyright © 1995–2018 Webtide. All rights reserved.