aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-01-23 16:54:03 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-01-24 18:36:49 +0100
commit604dd82bc19dd57340556f6a4a761a0f77ccbbfe (patch)
treee390e87e8c4534f09e03328640b57c0ec498f5c4
parent72c16503f4dd9cf14e75836206992fdd4ec954e4 (diff)
downloadsonarqube-604dd82bc19dd57340556f6a4a761a0f77ccbbfe.tar.gz
sonarqube-604dd82bc19dd57340556f6a4a761a0f77ccbbfe.zip
SONAR-8684 Redirect /api to /api/webservices/list
This redirection was previously done by rails
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/web/RoutesFilter.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/web/RoutesFilterTest.java9
2 files changed, 31 insertions, 1 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 dff0f867a28..23a38770c02 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
@@ -42,6 +42,7 @@ public class RoutesFilter implements Filter {
private static final String EMPTY = "";
private static final List<Route> ROUTES = ImmutableList.of(
+ new WebServiceListRoute(),
new BatchRoute(),
new BatchBootstrapRoute(),
new ApiSourcesRoute(),
@@ -81,6 +82,19 @@ public class RoutesFilter implements Filter {
String apply(HttpServletRequest request);
}
+ private static class WebServiceListRoute implements Route {
+
+ @Override
+ public boolean test(String path) {
+ return "/api".equals(path);
+ }
+
+ @Override
+ public String apply(HttpServletRequest request) {
+ return format("%s/api/webservices/list", request.getContextPath());
+ }
+ }
+
/**
* Old scanners were using /batch/file.jar url (see SCANNERAPI-167)
*/
@@ -154,6 +168,13 @@ public class RoutesFilter implements Filter {
}
private static String extractPath(HttpServletRequest request) {
- return request.getRequestURI().replaceFirst(request.getContextPath(), EMPTY);
+ return sanitizePath(request.getRequestURI().replaceFirst(request.getContextPath(), EMPTY));
+ }
+
+ private static String sanitizePath(String path) {
+ if (path.length() > 1 && path.endsWith("/")) {
+ return path.substring(0, path.length() - 1);
+ }
+ return path;
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/RoutesFilterTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/RoutesFilterTest.java
index 46b374497e9..1e8930a0fee 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/web/RoutesFilterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/web/RoutesFilterTest.java
@@ -50,6 +50,12 @@ public class RoutesFilterTest {
}
@Test
+ public void send_redirect_when_url_contains_only_api() throws Exception {
+ verifyRedirection("/api", null, "/sonarqube/api/webservices/list");
+ verifyRedirection("/api/", null, "/sonarqube/api/webservices/list");
+ }
+
+ @Test
public void send_redirect_when_url_contains_batch_with_jar() throws Exception {
verifyRedirection("/batch/file.jar", null, "/sonarqube/batch/file?name=file.jar");
}
@@ -57,16 +63,19 @@ public class RoutesFilterTest {
@Test
public void send_redirect_when_url_contains_batch_bootstrap() throws Exception {
verifyRedirection("/batch_bootstrap/index", null, "/sonarqube/batch/index");
+ verifyRedirection("/batch_bootstrap/index/", null, "/sonarqube/batch/index");
}
@Test
public void send_redirect_when_url_contains_api_sources() throws Exception {
verifyRedirection("/api/sources", "resource=my.project", "/sonarqube/api/sources/index?resource=my.project");
+ verifyRedirection("/api/sources/", "resource=my.project", "/sonarqube/api/sources/index?resource=my.project");
}
@Test
public void send_redirect_when_url_contains_profiles_export() throws Exception {
verifyRedirection("/profiles/export", "format=pmd", "/sonarqube/api/qualityprofiles/export?format=pmd");
+ verifyRedirection("/profiles/export/", "format=pmd", "/sonarqube/api/qualityprofiles/export?format=pmd");
}
@Test