Search in sources :

Example 1 with HttpConnector

use of org.sonarqube.ws.client.HttpConnector in project sonarqube by SonarSource.

the class ScannerWsClientProviderTest method provide_client_with_default_settings.

@Test
public void provide_client_with_default_settings() {
    GlobalProperties settings = new GlobalProperties(new HashMap<>());
    ScannerWsClient client = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
    assertThat(client).isNotNull();
    assertThat(client.baseUrl()).isEqualTo("http://localhost:9000/");
    HttpConnector httpConnector = (HttpConnector) client.wsConnector();
    assertThat(httpConnector.baseUrl()).isEqualTo("http://localhost:9000/");
    assertThat(httpConnector.okHttpClient().proxy()).isNull();
    assertThat(httpConnector.okHttpClient().connectTimeoutMillis()).isEqualTo(5_000);
    assertThat(httpConnector.okHttpClient().readTimeoutMillis()).isEqualTo(60_000);
}
Also used : HttpConnector(org.sonarqube.ws.client.HttpConnector) Test(org.junit.Test)

Example 2 with HttpConnector

use of org.sonarqube.ws.client.HttpConnector in project sonarqube by SonarSource.

the class ScannerWsClientProviderTest method provide_client_with_custom_settings.

@Test
public void provide_client_with_custom_settings() {
    Map<String, String> props = new HashMap<>();
    props.put("sonar.host.url", "https://here/sonarqube");
    props.put("sonar.login", "theLogin");
    props.put("sonar.password", "thePassword");
    props.put("sonar.ws.timeout", "42");
    GlobalProperties settings = new GlobalProperties(props);
    ScannerWsClient client = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
    assertThat(client).isNotNull();
    HttpConnector httpConnector = (HttpConnector) client.wsConnector();
    assertThat(httpConnector.baseUrl()).isEqualTo("https://here/sonarqube/");
    assertThat(httpConnector.okHttpClient().proxy()).isNull();
}
Also used : HttpConnector(org.sonarqube.ws.client.HttpConnector) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with HttpConnector

use of org.sonarqube.ws.client.HttpConnector in project sonar-scanner-jenkins by SonarSource.

the class HttpClient method getHttp.

public String getHttp(String url, @Nullable String token) {
    String baseUrl = StringUtils.substringBeforeLast(url, "/");
    String path = StringUtils.substringAfterLast(url, "/");
    HttpConnector httpConnector = HttpConnector.newBuilder().userAgent("Scanner for Jenkins").url(baseUrl).credentials(token, null).build();
    WsResponse response = httpConnector.call(new GetRequest(path));
    response.failIfNotSuccessful();
    return response.content();
}
Also used : HttpConnector(org.sonarqube.ws.client.HttpConnector) GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Aggregations

HttpConnector (org.sonarqube.ws.client.HttpConnector)3 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 GetRequest (org.sonarqube.ws.client.GetRequest)1 WsResponse (org.sonarqube.ws.client.WsResponse)1