Skip to content

Commit 36072f2

Browse files
committed
Push more common resources into the handler
1 parent 620c9a6 commit 36072f2

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

java/client/test/org/openqa/selenium/environment/webserver/CommonWebResources.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717

1818
package org.openqa.selenium.environment.webserver;
1919

20+
import org.openqa.selenium.build.InProject;
21+
import org.openqa.selenium.grid.web.MergedResource;
2022
import org.openqa.selenium.grid.web.PathResource;
23+
import org.openqa.selenium.grid.web.Resource;
2124
import org.openqa.selenium.grid.web.ResourceHandler;
2225
import org.openqa.selenium.remote.http.HttpHandler;
2326
import org.openqa.selenium.remote.http.HttpRequest;
2427
import org.openqa.selenium.remote.http.HttpResponse;
2528
import org.openqa.selenium.remote.http.Routable;
29+
import org.openqa.selenium.remote.http.Route;
2630

2731
import java.io.UncheckedIOException;
2832
import java.nio.file.Path;
@@ -34,8 +38,21 @@ public class CommonWebResources implements Routable {
3438
private final Routable delegate;
3539

3640
public CommonWebResources() {
37-
Path common = locate("common/src/web").toAbsolutePath();
38-
delegate = new ResourceHandler(new PathResource(common));
41+
Resource resources = new MergedResource(new PathResource(locate("common/src/web")))
42+
.alsoCheck(new PathResource(locate("javascript")))
43+
.alsoCheck(new PathResource(locate("third_party/closure/goog")))
44+
.alsoCheck(new PathResource(locate("third_party/js")));
45+
46+
Path runfiles = InProject.findRunfilesRoot();
47+
if (runfiles != null) {
48+
ResourceHandler handler = new ResourceHandler(new PathResource(runfiles));
49+
delegate = Route.combine(
50+
new ResourceHandler(resources),
51+
Route.prefix("/filez").to(Route.combine(handler))
52+
);
53+
} else {
54+
delegate = new ResourceHandler(resources);
55+
}
3956
}
4057

4158
@Override

java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java

+17-27
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,14 @@ public JettyAppServer(String hostName, int httpPort, int httpsPort) {
118118
handlers = new ContextHandlerCollection();
119119

120120
Path webSrc = locate("common/src/web");
121-
ServletContextHandler defaultContext = addResourceHandler(
122-
DEFAULT_CONTEXT_PATH, webSrc);
121+
ServletContextHandler defaultContext = new ServletContextHandler();
122+
handlers.addHandler(defaultContext);
123123

124124
// Only non-null when running with bazel test.
125125
Path runfiles = InProject.findRunfilesRoot();
126-
if (runfiles != null) {
127-
addResourceHandler(FILEZ_CONTEXT_PATH, runfiles);
128-
}
129-
130-
addJsResourceHandler(JS_SRC_CONTEXT_PATH, "javascript");
131-
addJsResourceHandler(CLOSURE_CONTEXT_PATH, "third_party/closure/goog");
132-
addJsResourceHandler(THIRD_PARTY_JS_CONTEXT_PATH, "third_party/js");
126+
// if (runfiles != null) {
127+
// addResourceHandler(FILEZ_CONTEXT_PATH, runfiles);
128+
// }
133129

134130
TemporaryFilesystem tempFs = TemporaryFilesystem.getDefaultTmpFS();
135131
tempPageDir = tempFs.createTempDir("pages", "test");
@@ -160,30 +156,24 @@ public JettyAppServer(String hostName, int httpPort, int httpsPort) {
160156
Route.get("/sleep").to(SleepingHandler::new),
161157
Route.post("/upload").to(UploadHandler::new),
162158
Route.matching(req -> req.getUri().startsWith("/utf8/")).to(() -> new Utf8Handler(webSrc, "/utf8/")),
163-
Route.prefix(TEMP_SRC_CONTEXT_PATH).to(Route.combine(generatedPages))
164-
);
159+
Route.prefix(TEMP_SRC_CONTEXT_PATH).to(Route.combine(generatedPages)),
160+
new CommonWebResources());
161+
162+
// If we're not running inside `bazel test` this will be non-null
163+
// if (runfiles != null) {
164+
// route = Route.combine(
165+
// route,
166+
// Route.matching(req -> req.getUri().startsWith(FILEZ_CONTEXT_PATH)).to(new )
167+
// )
168+
// addResourceHandler(FILEZ_CONTEXT_PATH, runfiles);
169+
// }
170+
165171
Route prefixed = Route.prefix(DEFAULT_CONTEXT_PATH).to(route);
166172
defaultContext.addServlet(new ServletHolder(new HttpHandlerServlet(Route.combine(route, prefixed))), "/*");
167173

168174
server.setHandler(handlers);
169175
}
170176

171-
private void addJsResourceHandler(String handlerPath, String dirPath) {
172-
Path path;
173-
try {
174-
path = locate(dirPath);
175-
} catch (WebDriverException e) {
176-
// Ugly hack to get us started with bazel while sorting out missing data dependencies.
177-
if (Boolean.getBoolean(getClass().getPackage().getName() + ".ignoreMissingJsRoots")
178-
&& e.getCause() instanceof FileNotFoundException) {
179-
System.err.println("WARNING: failed to add resource handler " + handlerPath + ": " + e.getCause());
180-
return;
181-
}
182-
throw e;
183-
}
184-
addResourceHandler(handlerPath, path);
185-
}
186-
187177
private static Optional<Integer> getEnvValue(String key) {
188178
return Optional.ofNullable(System.getenv(key)).map(Integer::parseInt);
189179
}

0 commit comments

Comments
 (0)