1616
1717package com .google .apphosting .runtime .jetty .ee8 ;
1818
19- import com .google .apphosting .runtime .AppVersion ;
2019import com .google .apphosting .runtime .AppEngineConstants ;
20+ import com .google .apphosting .runtime .AppVersion ;
2121import com .google .apphosting .utils .config .AppYaml ;
2222import com .google .common .base .Ascii ;
2323import com .google .common .flogger .GoogleLogger ;
3030import javax .servlet .http .HttpServletRequest ;
3131import javax .servlet .http .HttpServletResponse ;
3232import org .eclipse .jetty .ee8 .nested .ContextHandler ;
33+ import org .eclipse .jetty .ee8 .servlet .ServletContextHandler ;
3334import org .eclipse .jetty .ee8 .servlet .ServletHandler ;
34- import org .eclipse .jetty .http . pathmap . MappedResource ;
35+ import org .eclipse .jetty .ee8 . servlet . ServletMapping ;
3536import org .eclipse .jetty .util .StringUtil ;
3637import org .eclipse .jetty .util .URIUtil ;
3738import org .eclipse .jetty .util .resource .Resource ;
@@ -57,8 +58,9 @@ public class ResourceFileServlet extends HttpServlet {
5758 private Resource resourceBase ;
5859 private String [] welcomeFiles ;
5960 private FileSender fSender ;
60- ContextHandler chandler ;
61+ ServletContextHandler chandler ;
6162 ServletContext context ;
63+ String defaultServletName ;
6264
6365 /**
6466 * Initialize the servlet by extracting some useful configuration data from the current {@link
@@ -69,7 +71,7 @@ public void init() throws ServletException {
6971 context = getServletContext ();
7072 AppVersion appVersion =
7173 (AppVersion ) context .getAttribute (AppEngineConstants .APP_VERSION_CONTEXT_ATTR );
72- chandler = ContextHandler . getContextHandler (context );
74+ chandler = ServletContextHandler . getServletContextHandler (context );
7375
7476 AppYaml appYaml =
7577 (AppYaml ) chandler .getServer ().getAttribute (AppEngineConstants .APP_YAML_ATTRIBUTE_TARGET );
@@ -78,6 +80,12 @@ public void init() throws ServletException {
7880 // we access Jetty's internal state.
7981 welcomeFiles = chandler .getWelcomeFiles ();
8082
83+ ServletMapping servletMapping = chandler .getServletHandler ().getServletMapping ("/" );
84+ if (servletMapping == null ) {
85+ throw new ServletException ("No servlet mapping found" );
86+ }
87+ defaultServletName = servletMapping .getServletName ();
88+
8189 try {
8290 // TODO: review use of root factory.
8391 resourceBase = ResourceFactory .root ().newResource (context .getResource ("/" + appVersion .getPublicRoot ()));
@@ -254,13 +262,12 @@ private boolean maybeServeWelcomeFile(
254262 (AppVersion ) getServletContext ().getAttribute (AppEngineConstants .APP_VERSION_CONTEXT_ATTR );
255263 ServletHandler handler = chandler .getChildHandlerByClass (ServletHandler .class );
256264
257- MappedResource <ServletHandler .MappedServlet > defaultEntry = handler .getHolderEntry ("/" );
258-
259265 for (String welcomeName : welcomeFiles ) {
260266 String welcomePath = path + welcomeName ;
261267 String relativePath = welcomePath .substring (1 );
262268
263- if (!Objects .equals (handler .getHolderEntry (welcomePath ), defaultEntry )) {
269+ ServletHandler .MappedServlet mappedServlet = handler .getMappedServlet (welcomePath );
270+ if (!Objects .equals (mappedServlet .getServletHolder ().getName (), defaultServletName )) {
264271 // It's a path mapped to a servlet. Forward to it.
265272 RequestDispatcher dispatcher = request .getRequestDispatcher (path + welcomeName );
266273 return serveWelcomeFileAsForward (dispatcher , included , request , response );
0 commit comments