private final String userAgent;
private ServerConnection(String serverUrl, String app, String appVersion) {
- this.serverUrl = serverUrl;
+ this.serverUrl = removeEndSlash(serverUrl);
this.userAgent = app + "/" + appVersion;
}
+ private String removeEndSlash(String url) {
+ if (url == null) {
+ return null;
+ }
+ return url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
+ }
+
static ServerConnection create(Properties properties) {
String serverUrl = properties.getProperty("sonar.host.url");
String app = properties.getProperty(InternalProperties.RUNNER_APP);
import org.apache.commons.io.IOUtils;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.HttpException;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
Handler handler = new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
+ // SONARPLUGINS-3061
+ if (target.startsWith("//")) {
+ throw new HttpException(404, "Not found");
+ }
Request baseRequest = request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
setResponseBody(getMockResponseData());
setRequestBody(IOUtils.toString(baseRequest.getInputStream()));
assertThat(FileUtils.readFileToString(toFile)).isEqualTo("abcde");
}
+ // SONARPLUGINS-3061
+ @Test
+ public void should_support_trailing_slash() throws Exception {
+ httpServer.setMockResponseData("abcde");
+ Properties props = new Properties();
+ props.setProperty("sonar.host.url", httpServer.url() + "/");
+
+ ServerConnection connection = ServerConnection.create(props);
+ File toFile = temp.newFile();
+ connection.download("/batch/index.txt", toFile);
+
+ assertThat(FileUtils.readFileToString(toFile)).isEqualTo("abcde");
+ }
+
@Test
public void should_not_download_file_when_host_is_down() throws Exception {
Properties props = new Properties();