Skip to content
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

Open
wants to merge 13 commits into
base: jetty-12.1.x
Choose a base branch
from

Conversation

janbartel
Copy link
Contributor

Fixes #12505

Addresses:

  • difference between jetty core error attributes and servlet api attributes
  • handling error generated in core before servlet context is selected

@gregw gregw marked this pull request as ready for review November 28, 2024 00:22
Copy link
Contributor Author

@janbartel janbartel left a 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

request.setAttribute(org.eclipse.jetty.server.handler.ErrorHandler.ERROR_STATUS, 404);
response.setStatus(HttpStatus.NOT_FOUND_404);
}
return false;
Copy link
Contributor Author

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?

Copy link
Contributor

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?)

Copy link
Contributor

@gregw gregw left a 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

Copy link
Contributor Author

@janbartel janbartel left a 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.

Copy link
Contributor

@lorban lorban left a 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;
Copy link
Contributor

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();
Copy link
Contributor

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?
Copy link
Contributor

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);
Copy link
Contributor

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();
Copy link
Contributor

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();

@joakime joakime changed the title Jetty 12.1.x 12505 server to servlet errorhandling Issue #12505 - Server to Servlet Error Handling Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

ErrorPageErrorHandler does not use the proper attributes for error handling
3 participants