diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-02-17 17:24:44 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-02-22 17:41:33 +0100 |
commit | 02c8865621660708a6301b15770b729681dba94d (patch) | |
tree | 49ea29e161be79231f960b233db4cbf455578330 /server | |
parent | 009b71015a299d024c7cadee120568f9a80b4865 (diff) | |
download | sonarqube-02c8865621660708a6301b15770b729681dba94d.tar.gz sonarqube-02c8865621660708a6301b15770b729681dba94d.zip |
Improve readability of RoutesFilter
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/platform/web/RoutesFilter.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RoutesFilter.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/RoutesFilter.java index 6f4808f2957..3c96011d1a8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RoutesFilter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/RoutesFilter.java @@ -34,7 +34,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.sonar.core.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; public class RoutesFilter implements Filter { @@ -52,15 +51,21 @@ public class RoutesFilter implements Filter { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = extractPath(request); + Predicate<Route> match = route -> route.test(path); List<Route> routes = ROUTES.stream() - .filter(route -> route.test(path)) + .filter(match) .collect(Collectors.toList()); - checkState(routes.isEmpty() || routes.size() == 1, "Multiple routes have been found for '%s'", path); - if (routes.isEmpty()) { - chain.doFilter(request, response); - return; + + switch (routes.size()) { + case 0: + chain.doFilter(request, response); + break; + case 1: + response.sendRedirect(routes.get(0).apply(request)); + break; + default: + throw new IllegalStateException(format("Multiple routes have been found for '%s'", path)); } - response.sendRedirect(routes.get(0).apply(request)); } @Override |