Skip to content

Commit

Permalink
Deprecate the original Route class in favour of the new one
Browse files Browse the repository at this point in the history
Continue the process of making everything use HttpHandlers
by deprecating the Route class with the newer, shinier Route
class.
  • Loading branch information
shs96c committed Jul 4, 2019
1 parent 951f9f4 commit bd03257
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions java/server/src/org/openqa/selenium/grid/web/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.function.Function;
import java.util.function.Supplier;

@Deprecated
public abstract class Route<T extends Route> {

private final List<Function<CommandHandler, CommandHandler>> decorators = new ArrayList<>();
Expand Down
27 changes: 25 additions & 2 deletions java/server/src/org/openqa/selenium/grid/web/Routes.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class Routes {
@Deprecated
public class Routes implements HttpHandler, Predicate<HttpRequest> {

private final Function<HttpRequest, CommandHandler> handlerFunc;

Expand Down Expand Up @@ -72,8 +78,25 @@ public static CombinedRoute combine(
return new CombinedRoute(queue.reverse());
}

public Optional<CommandHandler> match(HttpRequest request) {
public Optional<CommandHandler> match(HttpRequest request) {
return Optional.ofNullable(handlerFunc.apply(request));
}

@Override
public boolean test(HttpRequest httpRequest) {
return match(httpRequest).isPresent();
}

@Override
public HttpResponse execute(HttpRequest req) {
HttpResponse res = new HttpResponse();
try {
Optional.of(handlerFunc.apply(req))
.orElseGet(() -> new NoHandler(new Json()))
.execute(req, res);
return res;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}

0 comments on commit bd03257

Please sign in to comment.