Skip to content

Commit

Permalink
Allow null resource base in ResourceFileServlet
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Jan 24, 2025
1 parent 48be4eb commit caade35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.google.apphosting.runtime.jetty.ee10;

import com.google.apphosting.runtime.AppVersion;
import com.google.apphosting.runtime.AppEngineConstants;
import com.google.apphosting.runtime.AppVersion;
import com.google.apphosting.utils.config.AppYaml;
import com.google.common.base.Ascii;
import com.google.common.flogger.GoogleLogger;
Expand All @@ -27,6 +27,9 @@
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHandler;
import org.eclipse.jetty.ee10.servlet.ServletMapping;
Expand All @@ -36,9 +39,6 @@
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;

import java.io.IOException;
import java.util.Objects;

/**
* {@code ResourceFileServlet} is a copy of {@code org.mortbay.jetty.servlet.DefaultServlet} that
* has been trimmed down to only support the subset of features that we want to take advantage of
Expand Down Expand Up @@ -88,9 +88,8 @@ public void init() throws ServletException {
defaultServletName = servletMapping.getServletName();

try {
// TODO: review use of root factory.
resourceBase =
ResourceFactory.root().newResource(context.getResource("/" + appVersion.getPublicRoot()));
URL resourceBaseUrl = context.getResource("/" + appVersion.getPublicRoot());
resourceBase = (resourceBaseUrl == null) ? null : ResourceFactory.of(chandler).newResource(resourceBaseUrl);
} catch (Exception ex) {
throw new ServletException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package com.google.apphosting.runtime.jetty.ee8;

import com.google.apphosting.runtime.AppVersion;
import com.google.apphosting.runtime.AppEngineConstants;
import com.google.apphosting.runtime.AppVersion;
import com.google.apphosting.utils.config.AppYaml;
import com.google.common.base.Ascii;
import com.google.common.flogger.GoogleLogger;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
Expand Down Expand Up @@ -79,8 +80,8 @@ public void init() throws ServletException {
welcomeFiles = chandler.getWelcomeFiles();

try {
// TODO: review use of root factory.
resourceBase = ResourceFactory.root().newResource(context.getResource("/" + appVersion.getPublicRoot()));
URL resourceBaseUrl = context.getResource("/" + appVersion.getPublicRoot());
resourceBase = (resourceBaseUrl == null) ? null : ResourceFactory.of(chandler).newResource(resourceBaseUrl);
} catch (Exception ex) {
throw new ServletException(ex);
}
Expand Down

0 comments on commit caade35

Please sign in to comment.