-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #12505 - Server to Servlet Error Handling #12586
base: jetty-12.1.x
Are you sure you want to change the base?
Issue #12505 - Server to Servlet Error Handling #12586
Conversation
…12505-server-to-servlet-errorhandling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things
jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/WebAppContextTest.java
Outdated
Show resolved
Hide resolved
...e11/jetty-ee11-servlet/src/main/java/org/eclipse/jetty/ee11/servlet/ServletChannelState.java
Outdated
Show resolved
Hide resolved
jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java
Outdated
Show resolved
Hide resolved
jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java
Show resolved
Hide resolved
request.setAttribute(org.eclipse.jetty.server.handler.ErrorHandler.ERROR_STATUS, 404); | ||
response.setStatus(HttpStatus.NOT_FOUND_404); | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now different to ee11
- is that on purpose or an omission?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in ee11 required a change to the ErrorPageMapper API and implementation, that I do not want to do in EE10, so just doing the simplest solution here. In EE11, I have tried to clean up the ErrorPageMapper API somewhat... but I think more could be done (maybe a different PR?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve, but then I have worked on this, so my review is not enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve! But I can't officially as I've created the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just found a few nits.
@@ -753,9 +756,12 @@ public Enumeration<String> getAttributeNames() | |||
|
|||
private class ErrorRequest extends ParameterRequestWrapper | |||
{ | |||
private final HttpServletRequest _httpServletRequest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is oddly aligned. I'm surprised checkstyle let it go through.
{ | ||
return switch (name) | ||
{ | ||
case ERROR_REQUEST_URI -> _httpServletRequest.getRequestURI(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could call getRequest
and cast it to HttpServletRequest
instead of introducing the _httpServletRequest
field.
@Override | ||
public Enumeration<String> getAttributeNames() | ||
{ | ||
// TODO add all names? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you add all the names present in getAttribute()
's switch
?
@@ -1067,12 +1077,15 @@ public void sendError(int code, String message) | |||
// Set Jetty Specific Attributes. | |||
request.setAttribute(ErrorHandler.ERROR_CONTEXT, servletContextRequest.getServletContext()); | |||
request.setAttribute(ErrorHandler.ERROR_MESSAGE, message); | |||
request.setAttribute(ErrorHandler.ERROR_STATUS, code); | |||
request.setAttribute(ERROR_STATUS, code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was ERROR_STATUS
statically imported? Other constants are not.
{ | ||
pageSource = PageLookupTechnique.GLOBAL; | ||
errorPage = _errorPages.get(GLOBAL_ERROR_PAGE); | ||
cause = (cause instanceof ServletException) ? ((ServletException)cause).getRootCause() : cause.getCause(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--- cause = (cause instanceof ServletException) ? ((ServletException)cause).getRootCause() : cause.getCause();
+++ cause = (cause instanceof ServletException se) ? se.getRootCause() : cause.getCause();
Fixes #12505
Addresses: