diff --git a/java/server/src/org/openqa/selenium/grid/commands/Hub.java b/java/server/src/org/openqa/selenium/grid/commands/Hub.java index 4b4a1b2bc1956..18f1c5b6a38bc 100644 --- a/java/server/src/org/openqa/selenium/grid/commands/Hub.java +++ b/java/server/src/org/openqa/selenium/grid/commands/Hub.java @@ -17,11 +17,10 @@ package org.openqa.selenium.grid.commands; -import com.google.auto.service.AutoService; - import com.beust.jcommander.JCommander; import com.beust.jcommander.ParameterException; - +import com.google.auto.service.AutoService; +import io.opentracing.Tracer; import org.openqa.selenium.BuildInfo; import org.openqa.selenium.cli.CliCommand; import org.openqa.selenium.events.EventBus; @@ -36,9 +35,10 @@ import org.openqa.selenium.grid.router.Router; import org.openqa.selenium.grid.server.BaseServerFlags; import org.openqa.selenium.grid.server.BaseServerOptions; -import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.EventBusFlags; +import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.HelpFlags; +import org.openqa.selenium.grid.server.NetworkOptions; import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap; @@ -47,8 +47,6 @@ import org.openqa.selenium.netty.server.NettyServer; import org.openqa.selenium.remote.http.HttpClient; -import io.opentracing.Tracer; - import java.util.logging.Logger; @AutoService(CliCommand.class) @@ -114,10 +112,11 @@ public Executable configure(String... args) { BaseServerOptions serverOptions = new BaseServerOptions(config); + NetworkOptions networkOptions = new NetworkOptions(config); HttpClient.Factory clientFactory = new RoutableHttpClientFactory( serverOptions.getExternalUri().toURL(), handler, - HttpClient.Factory.createDefault()); + networkOptions.getHttpClientFactory()); Distributor distributor = new LocalDistributor( tracer, diff --git a/java/server/src/org/openqa/selenium/grid/commands/Standalone.java b/java/server/src/org/openqa/selenium/grid/commands/Standalone.java index 740e84e20a8c0..6120aeeaf5802 100644 --- a/java/server/src/org/openqa/selenium/grid/commands/Standalone.java +++ b/java/server/src/org/openqa/selenium/grid/commands/Standalone.java @@ -41,9 +41,10 @@ import org.openqa.selenium.grid.router.Router; import org.openqa.selenium.grid.server.BaseServerFlags; import org.openqa.selenium.grid.server.BaseServerOptions; -import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.EventBusFlags; +import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.HelpFlags; +import org.openqa.selenium.grid.server.NetworkOptions; import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap; @@ -52,7 +53,6 @@ import org.openqa.selenium.net.NetworkUtils; import org.openqa.selenium.netty.server.NettyServer; import org.openqa.selenium.remote.http.HttpClient; -import org.openqa.selenium.remote.tracing.TracedHttpClient; import java.net.URI; import java.net.URISyntaxException; @@ -136,13 +136,12 @@ public Executable configure(String... args) { throw new RuntimeException(e); } + NetworkOptions networkOptions = new NetworkOptions(config); CombinedHandler combinedHandler = new CombinedHandler(); - HttpClient.Factory clientFactory = new TracedHttpClient.Factory( - tracer, - new RoutableHttpClientFactory( + HttpClient.Factory clientFactory = new RoutableHttpClientFactory( localhost.toURL(), combinedHandler, - HttpClient.Factory.createDefault())); + networkOptions.getHttpClientFactory()); SessionMap sessions = new LocalSessionMap(tracer, bus); combinedHandler.addHandler(sessions); diff --git a/java/server/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java b/java/server/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java index d43e06fdf197a..5ba162d46c955 100644 --- a/java/server/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java +++ b/java/server/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java @@ -34,16 +34,16 @@ import org.openqa.selenium.grid.log.LoggingOptions; import org.openqa.selenium.grid.server.BaseServerFlags; import org.openqa.selenium.grid.server.BaseServerOptions; -import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.EventBusFlags; +import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.HelpFlags; +import org.openqa.selenium.grid.server.NetworkOptions; import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionmap.config.SessionMapFlags; import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions; import org.openqa.selenium.netty.server.NettyServer; import org.openqa.selenium.remote.http.HttpClient; -import org.openqa.selenium.remote.tracing.TracedHttpClient; import java.util.logging.Logger; @@ -109,7 +109,8 @@ public Executable configure(String... args) { EventBusOptions events = new EventBusOptions(config); EventBus bus = events.getEventBus(); - HttpClient.Factory clientFactory = new TracedHttpClient.Factory(tracer, HttpClient.Factory.createDefault()); + NetworkOptions networkOptions = new NetworkOptions(config); + HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(); SessionMap sessions = new SessionMapOptions(config).getSessionMap(tracer, clientFactory); diff --git a/java/server/src/org/openqa/selenium/grid/docker/DockerSessionFactory.java b/java/server/src/org/openqa/selenium/grid/docker/DockerSessionFactory.java index 3d3df2ff356d9..a4d2b918a17d0 100644 --- a/java/server/src/org/openqa/selenium/grid/docker/DockerSessionFactory.java +++ b/java/server/src/org/openqa/selenium/grid/docker/DockerSessionFactory.java @@ -17,11 +17,6 @@ package org.openqa.selenium.grid.docker; -import static org.openqa.selenium.docker.ContainerInfo.image; -import static org.openqa.selenium.remote.Dialect.W3C; -import static org.openqa.selenium.remote.http.Contents.string; -import static org.openqa.selenium.remote.http.HttpMethod.GET; - import io.opentracing.Tracer; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ImmutableCapabilities; @@ -58,6 +53,11 @@ import java.util.logging.Level; import java.util.logging.Logger; +import static org.openqa.selenium.docker.ContainerInfo.image; +import static org.openqa.selenium.remote.Dialect.W3C; +import static org.openqa.selenium.remote.http.Contents.string; +import static org.openqa.selenium.remote.http.HttpMethod.GET; + public class DockerSessionFactory implements SessionFactory { private static final Logger LOG = Logger.getLogger(DockerSessionFactory.class.getName()); diff --git a/java/server/src/org/openqa/selenium/grid/node/httpd/NodeServer.java b/java/server/src/org/openqa/selenium/grid/node/httpd/NodeServer.java index 2f59877d34468..b31b272d492e7 100644 --- a/java/server/src/org/openqa/selenium/grid/node/httpd/NodeServer.java +++ b/java/server/src/org/openqa/selenium/grid/node/httpd/NodeServer.java @@ -39,13 +39,13 @@ import org.openqa.selenium.grid.node.local.LocalNode; import org.openqa.selenium.grid.server.BaseServerFlags; import org.openqa.selenium.grid.server.BaseServerOptions; -import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.EventBusFlags; +import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.HelpFlags; +import org.openqa.selenium.grid.server.NetworkOptions; import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.netty.server.NettyServer; import org.openqa.selenium.remote.http.HttpClient; -import org.openqa.selenium.remote.tracing.TracedHttpClient; import java.time.Duration; import java.util.logging.Logger; @@ -113,7 +113,8 @@ public Executable configure(String... args) { EventBusOptions events = new EventBusOptions(config); EventBus bus = events.getEventBus(); - HttpClient.Factory clientFactory = new TracedHttpClient.Factory(tracer, HttpClient.Factory.createDefault()); + NetworkOptions networkOptions = new NetworkOptions(config); + HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(); BaseServerOptions serverOptions = new BaseServerOptions(config); diff --git a/java/server/src/org/openqa/selenium/grid/router/httpd/RouterServer.java b/java/server/src/org/openqa/selenium/grid/router/httpd/RouterServer.java index 1be2a0d2f1c06..27d1d8ecb3327 100644 --- a/java/server/src/org/openqa/selenium/grid/router/httpd/RouterServer.java +++ b/java/server/src/org/openqa/selenium/grid/router/httpd/RouterServer.java @@ -36,13 +36,13 @@ import org.openqa.selenium.grid.server.BaseServerFlags; import org.openqa.selenium.grid.server.BaseServerOptions; import org.openqa.selenium.grid.server.HelpFlags; +import org.openqa.selenium.grid.server.NetworkOptions; import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionmap.config.SessionMapFlags; import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions; import org.openqa.selenium.netty.server.NettyServer; import org.openqa.selenium.remote.http.HttpClient; -import org.openqa.selenium.remote.tracing.TracedHttpClient; import java.util.logging.Logger; @@ -102,7 +102,8 @@ public Executable configure(String... args) { loggingOptions.configureLogging(); Tracer tracer = loggingOptions.getTracer(); - HttpClient.Factory clientFactory = new TracedHttpClient.Factory(tracer, HttpClient.Factory.createDefault()); + NetworkOptions networkOptions = new NetworkOptions(config); + HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(); SessionMapOptions sessionsOptions = new SessionMapOptions(config); SessionMap sessions = sessionsOptions.getSessionMap(tracer, clientFactory); diff --git a/java/server/src/org/openqa/selenium/grid/server/BUILD.bazel b/java/server/src/org/openqa/selenium/grid/server/BUILD.bazel index 78970ed0b2d9a..54083e6ded44d 100644 --- a/java/server/src/org/openqa/selenium/grid/server/BUILD.bazel +++ b/java/server/src/org/openqa/selenium/grid/server/BUILD.bazel @@ -18,6 +18,7 @@ java_library( "//java/server/src/org/openqa/selenium/events", "//java/server/src/org/openqa/selenium/grid/component", "//java/server/src/org/openqa/selenium/grid/config", + "//java/server/src/org/openqa/selenium/grid/log", "//java/server/src/org/openqa/selenium/grid/web", artifact("com.beust:jcommander"), artifact("com.google.guava:guava"), diff --git a/java/server/src/org/openqa/selenium/grid/server/NetworkOptions.java b/java/server/src/org/openqa/selenium/grid/server/NetworkOptions.java new file mode 100644 index 0000000000000..b9a7ba4bed6bf --- /dev/null +++ b/java/server/src/org/openqa/selenium/grid/server/NetworkOptions.java @@ -0,0 +1,40 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.openqa.selenium.grid.server; + +import io.opentracing.Tracer; +import org.openqa.selenium.grid.config.Config; +import org.openqa.selenium.grid.log.LoggingOptions; +import org.openqa.selenium.remote.http.HttpClient; +import org.openqa.selenium.remote.tracing.TracedHttpClient; + +import java.util.Objects; + +public class NetworkOptions { + + private final Config config; + + public NetworkOptions(Config config) { + this.config = Objects.requireNonNull(config, "Config to use must be set."); + } + + public HttpClient.Factory getHttpClientFactory() { + Tracer tracer = new LoggingOptions(config).getTracer(); + return new TracedHttpClient.Factory(tracer, HttpClient.Factory.createDefault()); + } +} diff --git a/java/server/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java b/java/server/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java index e973ddb56b0f9..9f613f4ed0ab9 100644 --- a/java/server/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java +++ b/java/server/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java @@ -34,8 +34,8 @@ import org.openqa.selenium.grid.log.LoggingOptions; import org.openqa.selenium.grid.server.BaseServerFlags; import org.openqa.selenium.grid.server.BaseServerOptions; -import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.EventBusFlags; +import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.HelpFlags; import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.sessionmap.SessionMap;