private static final String EMPTY = "";
private static final List<Route> ROUTES = ImmutableList.of(
+ new WebServiceListRoute(),
new BatchRoute(),
new BatchBootstrapRoute(),
new ApiSourcesRoute(),
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)
*/
}
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;
}
}
when(request.getContextPath()).thenReturn("/sonarqube");
}
+ @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");
@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