Index: sonar-commons/src/main/java/org/sonar/commons/ServerHttpClient.java =================================================================== --- sonar-commons/src/main/java/org/sonar/commons/ServerHttpClient.java (revision 2388) +++ sonar-commons/src/main/java/org/sonar/commons/ServerHttpClient.java (working copy) @@ -35,6 +35,8 @@ public class ServerHttpClient { private String url; + private Integer connectTimeoutMiliseconds = CONNECT_TIMEOUT_MILLISECONDS; + private Integer readTimeoutMiliseconds = READ_TIMEOUT_MILLISECONDS; protected static final String SERVER_API_PATH = "/api/server"; private static final String KEY_PATH = SERVER_API_PATH + "/key"; @@ -47,12 +49,22 @@ private static final int READ_TIMEOUT_MILLISECONDS = 60000; - public ServerHttpClient(String remoteServerUrl) { + public ServerHttpClient(String remoteServerUrl, + Integer connectTimeoutMiliseconds, + Integer readTimeoutMiliseconds) { this.url = StringUtils.chomp(remoteServerUrl, "/"); + if(connectTimeoutMiliseconds != null) { + this.connectTimeoutMiliseconds = connectTimeoutMiliseconds; + } + if(readTimeoutMiliseconds != null) { + this.readTimeoutMiliseconds = readTimeoutMiliseconds; + } } public ServerHttpClient(Configuration configuration) { - this(configuration.getString("sonar.host.url", "http://localhost:9000")); + this(configuration.getString("sonar.host.url", "http://localhost:9000"), + configuration.getInteger("sonar.host.connect.timeout.miliseconds", CONNECT_TIMEOUT_MILLISECONDS), + configuration.getInteger("sonar.host.read.timeout.miliseconds", READ_TIMEOUT_MILLISECONDS)); } /** @@ -139,10 +151,10 @@ } private HttpURLConnection getConnection(String url, String method) throws IOException { - URL page = new URL(url); + URL page = new URL(url); HttpURLConnection conn = (HttpURLConnection) page.openConnection(); - conn.setConnectTimeout(CONNECT_TIMEOUT_MILLISECONDS); - conn.setReadTimeout(READ_TIMEOUT_MILLISECONDS); + conn.setConnectTimeout(connectTimeoutMiliseconds); + conn.setReadTimeout(readTimeoutMiliseconds); conn.setRequestMethod(method); conn.connect(); return conn; Index: sonar-commons/src/test/java/org/sonar/commons/ServerHttpClientTest.java =================================================================== --- sonar-commons/src/test/java/org/sonar/commons/ServerHttpClientTest.java (revision 2388) +++ sonar-commons/src/test/java/org/sonar/commons/ServerHttpClientTest.java (working copy) @@ -29,17 +29,19 @@ public class ServerHttpClientTest { private String serverUrl = "http://test"; + private Integer connectTmotMilis = 30000; + private Integer readTmotMilis = 60000; private ServerHttpClient serverHttpClient; @Before public void before() { - serverHttpClient = new ServerHttpClient(serverUrl); + serverHttpClient = new ServerHttpClient(serverUrl, connectTmotMilis, readTmotMilis); } @Test public void shouldReturnAValidResult() throws IOException { final String validContent = "valid"; - ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl) { + ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl, connectTmotMilis, readTmotMilis) { protected String getRemoteContent(String url) { return (validContent); } @@ -50,14 +52,14 @@ @Test public void shouldRemoveLastUrlSlash() { - ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl + "/"); + ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl + "/", connectTmotMilis, readTmotMilis); assertThat(serverHttpClient.getUrl(), is(serverUrl)); } @Test(expected = ServerApiEmptyContentException.class) public void shouldThrowAnExceptionIfResultIsEmpty() throws IOException { final String invalidContent = " "; - ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl) { + ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl, connectTmotMilis, readTmotMilis) { protected String getRemoteContent(String url) { return (invalidContent); } @@ -76,7 +78,7 @@ public void shouldLaunchBatchUsedGoodUrl() { int snapshotId = 1; final String[] urlUsed = new String[]{" "}; - ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl) { + ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl, connectTmotMilis, readTmotMilis) { protected void postRemoteContent(String url) { urlUsed[0] = url; } @@ -88,7 +90,7 @@ @Test(expected = ServerConnectionException.class) public void shouldFailIfCanNotConnectToServer() { - ServerHttpClient serverHttpClient = new ServerHttpClient("fake") { + ServerHttpClient serverHttpClient = new ServerHttpClient("fake", connectTmotMilis, readTmotMilis) { protected String getRemoteContent(String url) throws IOException { throw new IOException(""); } Index: sonar-core-maven-plugin/src/main/java/org/sonar/maven/BatchMojo.java =================================================================== --- sonar-core-maven-plugin/src/main/java/org/sonar/maven/BatchMojo.java (revision 2388) +++ sonar-core-maven-plugin/src/main/java/org/sonar/maven/BatchMojo.java (working copy) @@ -47,6 +47,20 @@ * @parameter expression="${sonar.host.url}" default-value="http://localhost:9000" alias="sonar.host.url" */ private String sonarHostURL; + + /** + * Sonar host connection timeout + * + * @parameter expression="${sonar.host.connect.timeout.miliseconds}" default-value="30000" alias="sonar.host.connect.timeout.miliseconds" + */ + private Integer sonarHostConnectTimeoutMilis; + + /** + * Sonar host read timeout + * + * @parameter expression="${sonar.host.read.timeout.miliseconds}" default-value="60000" alias="sonar.host.read.timeout.miliseconds" + */ + private Integer sonarHostReadTimeoutMilis; private ServerHttpClient serverHttpClient; private DatabaseSession session; @@ -78,7 +92,7 @@ private void notifyServer(Snapshot topLevel) { if (serverHttpClient == null) { - serverHttpClient = new ServerHttpClient(sonarHostURL); + serverHttpClient = new ServerHttpClient(sonarHostURL, sonarHostConnectTimeoutMilis, sonarHostReadTimeoutMilis); } serverHttpClient.launchBatch(topLevel.getId()); } Index: sonar-core-maven-plugin/src/main/java/org/sonar/maven/DependenciesInjectionMojo.java =================================================================== --- sonar-core-maven-plugin/src/main/java/org/sonar/maven/DependenciesInjectionMojo.java (revision 2388) +++ sonar-core-maven-plugin/src/main/java/org/sonar/maven/DependenciesInjectionMojo.java (working copy) @@ -51,6 +51,21 @@ private String sonarHostURL; /** + * Sonar host connection timeout + * + * @parameter expression="${sonar.host.connect.timeout.miliseconds}" default-value="30000" alias="sonar.host.connect.timeout.miliseconds" + */ + private Integer sonarHostConnectTimeoutMilis; + + /** + * Sonar host read timeout + * + * @parameter expression="${sonar.host.read.timeout.miliseconds}" default-value="60000" alias="sonar.host.read.timeout.miliseconds" + */ + private Integer sonarHostReadTimeoutMilis; + + + /** * Sonar server version * @parameter expression="${sonar.server.version}" alias="sonar.server.version" */ @@ -72,7 +87,7 @@ public void execute() throws MojoExecutionException { if ( serverHttpClient == null ) { - serverHttpClient = new ServerHttpClient( sonarHostURL ); + serverHttpClient = new ServerHttpClient(sonarHostURL, sonarHostConnectTimeoutMilis, sonarHostReadTimeoutMilis); } try { preparePomForSonar(); Index: sonar-core-maven-plugin/src/test/java/org/sonar/maven/DependenciesInjectionMojoTest.java =================================================================== --- sonar-core-maven-plugin/src/test/java/org/sonar/maven/DependenciesInjectionMojoTest.java (revision 2388) +++ sonar-core-maven-plugin/src/test/java/org/sonar/maven/DependenciesInjectionMojoTest.java (working copy) @@ -42,7 +42,7 @@ protected void setUp() throws Exception { super.setUp(); - serverHttpClient = new PMTestWebInterfaceService("http://www.test.com"); + serverHttpClient = new PMTestWebInterfaceService("http://www.test.com", 30000, 60000); baseTestDir = PlexusTestCase.getBasedir() + "/src/test/resources/DependenciesInjectionMojoTest/target"; new File(baseTestDir).mkdir(); serverId = "serverId"; @@ -125,8 +125,8 @@ private class PMTestWebInterfaceService extends ServerHttpClient { - public PMTestWebInterfaceService(String remoteServerUrl) { - super(remoteServerUrl); + public PMTestWebInterfaceService(String remoteServerUrl, Integer connectTmotMilis, Integer readTmotMilis) { + super(remoteServerUrl, connectTmotMilis, readTmotMilis); } public String getMavenRepositoryUrl() { Index: sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java =================================================================== --- sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java (revision 2388) +++ sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java (working copy) @@ -88,8 +88,21 @@ * @parameter expression="${sonar.host.url}" default-value="http://localhost:9000" alias="sonar.host.url" */ private String sonarHostURL; + + /** + * Sonar host connection timeout + * + * @parameter expression="${sonar.host.connect.timeout.miliseconds}" default-value="30000" alias="sonar.host.connect.timeout.miliseconds" + */ + private Integer sonarHostConnectTimeoutMilis; + + /** + * Sonar host read timeout + * + * @parameter expression="${sonar.host.read.timeout.miliseconds}" default-value="60000" alias="sonar.host.read.timeout.miliseconds" + */ + private Integer sonarHostReadTimeoutMilis; - /** * Modules from the project to skip * @@ -105,7 +118,7 @@ private Boolean collectOnly = Boolean.FALSE; public void execute() throws MojoExecutionException { - ServerHttpClient server = new ServerHttpClient(sonarHostURL); + ServerHttpClient server = new ServerHttpClient(sonarHostURL, sonarHostConnectTimeoutMilis, sonarHostReadTimeoutMilis);; server.checkUp(); String sonarServerVersion = getServerVersion(server); Index: tests/integration/src/it/java/org/sonar/itests/ServerHttpClientTest.java =================================================================== --- tests/integration/src/it/java/org/sonar/itests/ServerHttpClientTest.java (revision 2388) +++ tests/integration/src/it/java/org/sonar/itests/ServerHttpClientTest.java (working copy) @@ -35,7 +35,9 @@ @Before public void before() { String sonarUrl = IntegrationTestUtils.getConfiguration().getString("sonar.url"); - serverHttpClient = new ServerHttpClient(sonarUrl); + Integer connectTmotMilis = IntegrationTestUtils.getConfiguration().getInteger("sonar.connect.timeout.milis"); + Integer readTmotMilis = IntegrationTestUtils.getConfiguration().getInteger("sonar.read.timeout.milis"); + serverHttpClient = new ServerHttpClient(sonarUrl, connectTmotMilis, readTmotMilis); } @Test Index: tests/integration/src/it/resources/context.properties =================================================================== --- tests/integration/src/it/resources/context.properties (revision 2388) +++ tests/integration/src/it/resources/context.properties (working copy) @@ -1,4 +1,6 @@ # # properties used by java tests only. Selenium reads configuration from pom.xml. # -sonar.url = http://localhost:9000 \ No newline at end of file +sonar.url = http://localhost:9000 +sonar.connect.timeout.milis = 30000 +sonar.read.timeout.milis = 60000 \ No newline at end of file