3131import javax .servlet .http .HttpServletRequest ;
3232import javax .servlet .http .HttpServletResponse ;
3333import org .eclipse .jetty .ee8 .nested .ContextHandler ;
34+ import org .eclipse .jetty .ee8 .servlet .ServletContextHandler ;
3435import org .eclipse .jetty .ee8 .servlet .ServletHandler ;
35- import org .eclipse .jetty .http . pathmap . MappedResource ;
36+ import org .eclipse .jetty .ee8 . servlet . ServletMapping ;
3637import org .eclipse .jetty .util .StringUtil ;
3738import org .eclipse .jetty .util .URIUtil ;
3839import org .eclipse .jetty .util .resource .Resource ;
@@ -58,8 +59,9 @@ public class ResourceFileServlet extends HttpServlet {
5859 private Resource resourceBase ;
5960 private String [] welcomeFiles ;
6061 private FileSender fSender ;
61- ContextHandler chandler ;
62+ ServletContextHandler chandler ;
6263 ServletContext context ;
64+ String defaultServletName ;
6365
6466 /**
6567 * Initialize the servlet by extracting some useful configuration data from the current {@link
@@ -70,7 +72,7 @@ public void init() throws ServletException {
7072 context = getServletContext ();
7173 AppVersion appVersion =
7274 (AppVersion ) context .getAttribute (AppEngineConstants .APP_VERSION_CONTEXT_ATTR );
73- chandler = ContextHandler . getContextHandler (context );
75+ chandler = ServletContextHandler . getServletContextHandler (context );
7476
7577 AppYaml appYaml =
7678 (AppYaml ) chandler .getServer ().getAttribute (AppEngineConstants .APP_YAML_ATTRIBUTE_TARGET );
@@ -79,6 +81,12 @@ public void init() throws ServletException {
7981 // we access Jetty's internal state.
8082 welcomeFiles = chandler .getWelcomeFiles ();
8183
84+ ServletMapping servletMapping = chandler .getServletHandler ().getServletMapping ("/" );
85+ if (servletMapping == null ) {
86+ throw new ServletException ("No servlet mapping found" );
87+ }
88+ defaultServletName = servletMapping .getServletName ();
89+
8290 try {
8391 URL resourceBaseUrl = context .getResource ("/" + appVersion .getPublicRoot ());
8492 resourceBase = (resourceBaseUrl == null ) ? null : ResourceFactory .of (chandler ).newResource (resourceBaseUrl );
@@ -255,13 +263,12 @@ private boolean maybeServeWelcomeFile(
255263 (AppVersion ) getServletContext ().getAttribute (AppEngineConstants .APP_VERSION_CONTEXT_ATTR );
256264 ServletHandler handler = chandler .getChildHandlerByClass (ServletHandler .class );
257265
258- MappedResource <ServletHandler .MappedServlet > defaultEntry = handler .getHolderEntry ("/" );
259-
260266 for (String welcomeName : welcomeFiles ) {
261267 String welcomePath = path + welcomeName ;
262268 String relativePath = welcomePath .substring (1 );
263269
264- if (!Objects .equals (handler .getHolderEntry (welcomePath ), defaultEntry )) {
270+ ServletHandler .MappedServlet mappedServlet = handler .getMappedServlet (welcomePath );
271+ if (!Objects .equals (mappedServlet .getServletHolder ().getName (), defaultServletName )) {
265272 // It's a path mapped to a servlet. Forward to it.
266273 RequestDispatcher dispatcher = request .getRequestDispatcher (path + welcomeName );
267274 return serveWelcomeFileAsForward (dispatcher , included , request , response );
0 commit comments