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

fix infinite redirect bug in ResourceFileServlet for EE10 #113

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHandler;
import org.eclipse.jetty.ee10.servlet.ServletMapping;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class ResourceFileServlet extends HttpServlet {
private FileSender fSender;
ServletContextHandler chandler;
ServletContext context;
String defaultServletName;

/**
* Initialize the servlet by extracting some useful configuration data from the current {@link
Expand All @@ -79,6 +81,12 @@ public void init() throws ServletException {
// we access Jetty's internal state.
welcomeFiles = chandler.getWelcomeFiles();

ServletMapping servletMapping = chandler.getServletHandler().getServletMapping("/");
if (servletMapping == null) {
throw new ServletException("No servlet mapping found");
}
defaultServletName = servletMapping.getServletName();

try {
// TODO: review use of root factory.
resourceBase =
Expand Down Expand Up @@ -256,13 +264,12 @@ private boolean maybeServeWelcomeFile(
(AppVersion) getServletContext().getAttribute(JettyConstants.APP_VERSION_CONTEXT_ATTR);
ServletHandler handler = chandler.getServletHandler();

ServletHandler.MappedServlet defaultEntry = handler.getMappedServlet("/");

for (String welcomeName : welcomeFiles) {
String welcomePath = path + welcomeName;
String relativePath = welcomePath.substring(1);

if (!Objects.equals(handler.getMappedServlet(welcomePath), defaultEntry)) {
ServletHandler.MappedServlet mappedServlet = handler.getMappedServlet(welcomePath);
if (!Objects.equals(mappedServlet.getServletHolder().getName(), defaultServletName)) {
// It's a path mapped to a servlet. Forward to it.
RequestDispatcher dispatcher = request.getRequestDispatcher(path + welcomeName);
return serveWelcomeFileAsForward(dispatcher, included, request, response);
Expand Down
Loading