Skip to content

Commit

Permalink
Replace bazel identified instanceof checks of CommandHandler with Htt…
Browse files Browse the repository at this point in the history
…pHandler
  • Loading branch information
shs96c committed Jul 4, 2019
1 parent 2c24f30 commit 21a2ceb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
18 changes: 6 additions & 12 deletions java/server/src/org/openqa/selenium/grid/router/HandleSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.grid.sessionmap.SessionMap;
import org.openqa.selenium.grid.web.CommandHandler;
import org.openqa.selenium.grid.web.ReverseProxyHandler;
import org.openqa.selenium.net.Urls;
import org.openqa.selenium.remote.SessionId;
Expand All @@ -34,8 +33,6 @@
import org.openqa.selenium.remote.tracing.DistributedTracer;
import org.openqa.selenium.remote.tracing.Span;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
Expand All @@ -44,7 +41,7 @@

class HandleSession implements HttpHandler {

private final LoadingCache<SessionId, CommandHandler> knownSessions;
private final LoadingCache<SessionId, HttpHandler> knownSessions;
private final DistributedTracer tracer;

public HandleSession(
Expand All @@ -56,12 +53,12 @@ public HandleSession(

this.knownSessions = CacheBuilder.newBuilder()
.expireAfterAccess(Duration.ofMinutes(1))
.build(new CacheLoader<SessionId, CommandHandler>() {
.build(new CacheLoader<SessionId, HttpHandler>() {
@Override
public CommandHandler load(SessionId id) {
public HttpHandler load(SessionId id) {
Session session = sessions.get(id);
if (session instanceof CommandHandler) {
return (CommandHandler) session;
if (session instanceof HttpHandler) {
return (HttpHandler) session;
}
HttpClient client = httpClientFactory.createClient(Urls.fromUri(session.getUri()));
return new ReverseProxyHandler(client);
Expand All @@ -81,8 +78,7 @@ public HttpResponse execute(HttpRequest req) {
span.addTag("session.id", id);

try {
HttpResponse resp = new HttpResponse();
knownSessions.get(id).execute(req, resp);
HttpResponse resp = knownSessions.get(id).execute(req);
span.addTag("http.status", resp.getStatus());
return resp;
} catch (ExecutionException e) {
Expand All @@ -93,8 +89,6 @@ public HttpResponse execute(HttpRequest req) {
throw (RuntimeException) cause;
}
throw new RuntimeException(cause);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.openqa.selenium.grid.web.CommandHandler;
import org.openqa.selenium.remote.Dialect;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

Expand Down Expand Up @@ -77,8 +78,8 @@ public void stop() {

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
if (session instanceof CommandHandler) {
((CommandHandler) session).execute(req, resp);
if (session instanceof HttpHandler) {
copyResponse(((HttpHandler) session).execute(req), resp);
} else {
// Do nothing.
}
Expand Down

0 comments on commit 21a2ceb

Please sign in to comment.