Skip to content

Commit

Permalink
fixed ee11
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed Nov 27, 2024
1 parent 585aeed commit db3f051
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,37 @@ public boolean handle(Request request, Response response, Callback callback) thr
ServletContextHandler.ServletScopedContext context = servletContextRequest.getErrorContext();
Integer errorStatus = (Integer)request.getAttribute(ERROR_STATUS);
Throwable errorCause = (Throwable)request.getAttribute(ERROR_EXCEPTION);
ErrorPageMapper.ErrorPage errorPage = (this instanceof ErrorPageMapper mapper) ? mapper.getErrorPage(errorStatus, errorCause) : null;
if (LOG.isDebugEnabled())
LOG.debug("{} {} {} -> {}", context, errorStatus, errorCause, errorPage);
if (errorPage != null && context.getServletContext().getRequestDispatcher(errorPage.errorPage) instanceof Dispatcher errorDispatcher)
if (this instanceof ErrorPageMapper mapper)
{
try
ErrorPageMapper.ErrorPage errorPage = mapper.getErrorPage(errorStatus, errorCause);
if (LOG.isDebugEnabled())
LOG.debug("{} {} {} -> {}", context, errorStatus, errorCause, errorPage);
if (errorPage != null && context.getServletContext().getRequestDispatcher(errorPage.errorPage) instanceof Dispatcher errorDispatcher)
{
try
{
contextHandler.requestInitialized(servletContextRequest, httpServletRequest);
errorDispatcher.error(httpServletRequest, httpServletResponse);
try
{
mapper.prepare(errorPage, httpServletRequest, httpServletResponse);
contextHandler.requestInitialized(servletContextRequest, httpServletRequest);
errorDispatcher.error(httpServletRequest, httpServletResponse);
}
finally
{
contextHandler.requestDestroyed(servletContextRequest, httpServletRequest);
}
callback.succeeded();
return true;
}
finally
catch (ServletException e)
{
contextHandler.requestDestroyed(servletContextRequest, httpServletRequest);
}
callback.succeeded();
return true;
}
catch (ServletException e)
{
if (LOG.isDebugEnabled())
LOG.debug("Unable to call error dispatcher", e);
if (response.isCommitted())
{
callback.failed(e);
return true;
if (LOG.isDebugEnabled())
LOG.debug("Unable to call error dispatcher", e);
if (response.isCommitted())
{
callback.failed(e);
return true;
}
}
}
}
Expand Down Expand Up @@ -163,7 +167,7 @@ enum PageLookupTechnique
THROWABLE, STATUS_CODE, GLOBAL
}

record ErrorPage(String errorPage, PageLookupTechnique match, Throwable cause, Class<?> matchedClass)
record ErrorPage(String errorPage, PageLookupTechnique match, Throwable error, Throwable cause, Class<?> matchedClass)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void setUnwrapServletException(boolean unwrapServletException)
@Override
public void prepare(ErrorPage errorPage, HttpServletRequest request, HttpServletResponse response)
{
if (errorPage.cause() instanceof ServletException && _unwrapServletException)
if (errorPage.error() instanceof ServletException && _unwrapServletException)
{
Throwable unwrapped = unwrapServletException(errorPage.cause(), errorPage.matchedClass());
Throwable unwrapped = unwrapServletException(errorPage.error(), errorPage.matchedClass());
if (unwrapped != null)
{
request.setAttribute(org.eclipse.jetty.server.handler.ErrorHandler.ERROR_EXCEPTION, unwrapped);
Expand All @@ -82,7 +82,7 @@ public ErrorPage getErrorPage(Integer errorStatusCode, Throwable error)
{
errorPage = _errorPages.get(exClass.getName());
if (errorPage != null)
return new ErrorPage(errorPage, PageLookupTechnique.THROWABLE, cause, exClass);
return new ErrorPage(errorPage, PageLookupTechnique.THROWABLE, error, cause, exClass);
exClass = exClass.getSuperclass();
}

Expand All @@ -94,20 +94,20 @@ public ErrorPage getErrorPage(Integer errorStatusCode, Throwable error)
{
errorPage = _errorPages.get(Integer.toString(errorStatusCode));
if (errorPage != null)
return new ErrorPage(errorPage, PageLookupTechnique.STATUS_CODE, error, null);
return new ErrorPage(errorPage, PageLookupTechnique.STATUS_CODE, error, error, null);

// look for an error code range match.
for (ErrorCodeRange errCode : _errorPageList)
{
if (errCode.isInRange(errorStatusCode))
return new ErrorPage(errCode.getUri(), PageLookupTechnique.STATUS_CODE, error, null);
return new ErrorPage(errCode.getUri(), PageLookupTechnique.STATUS_CODE, error, error, null);
}
}

// Try servlet 3.x global error page.
errorPage = _errorPages.get(GLOBAL_ERROR_PAGE);
if (errorPage != null)
return new ErrorPage(errorPage, PageLookupTechnique.GLOBAL, error, null);
return new ErrorPage(errorPage, PageLookupTechnique.GLOBAL, error, error, null);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
import org.slf4j.LoggerFactory;

import static jakarta.servlet.ServletContext.TEMPDIR;
import static org.eclipse.jetty.server.handler.ErrorHandler.ERROR_EXCEPTION;
import static org.eclipse.jetty.server.handler.ErrorHandler.ERROR_STATUS;

/**
Expand Down Expand Up @@ -1201,9 +1200,7 @@ protected boolean handleByContextHandler(String pathInContext, ContextRequest re
{
if (getErrorHandler() instanceof ErrorHandler.ErrorPageMapper mapper)
{
Integer errorStatus = (Integer)request.getAttribute(ERROR_STATUS);
Throwable errorCause = (Throwable)request.getAttribute(ERROR_EXCEPTION);
ErrorHandler.ErrorPageMapper.ErrorPage errorPage = mapper.getErrorPage(errorStatus, errorCause);
ErrorHandler.ErrorPageMapper.ErrorPage errorPage = mapper.getErrorPage(404, null);
if (errorPage != null)
{
// Do nothing here other than set the error status so that the ServletHandler will handle as if a sendError
Expand Down

0 comments on commit db3f051

Please sign in to comment.