Search in sources :

Example 1 with ApacheHttpTransport

use of com.google.api.client.http.apache.v2.ApacheHttpTransport in project hub-alert by blackducksoftware.

the class AzureHttpRequestCreatorFactory method defaultHttpTransport.

private static ApacheHttpTransport defaultHttpTransport(Proxy proxy) {
    HttpHost httpHost = HttpHost.create(proxy.toString());
    CloseableHttpClient httpClient = ApacheHttpTransport.newDefaultHttpClientBuilder().setProxy(httpHost).build();
    return new ApacheHttpTransport(httpClient);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpHost(org.apache.http.HttpHost) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport)

Example 2 with ApacheHttpTransport

use of com.google.api.client.http.apache.v2.ApacheHttpTransport in project hub-alert by blackducksoftware.

the class AzureHttpRequestCreatorTest method init.

@BeforeAll
public static void init() {
    ApacheHttpTransport httpTransport = new ApacheHttpTransport(ApacheHttpTransport.newDefaultHttpClient());
    HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
    azureHttpRequestCreator = new AzureHttpRequestCreator(TEST_BASE_URL, GSON, requestFactory, API_VERSION_APPENDER);
}
Also used : HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with ApacheHttpTransport

use of com.google.api.client.http.apache.v2.ApacheHttpTransport in project hub-alert by blackducksoftware.

the class AzureBoardsProperties method createHttpTransport.

public HttpTransport createHttpTransport(ProxyInfo proxyInfo) {
    // Authenticated proxies aren't supported with the OAuth client library by default.
    // Need to use an Apache Http Client backed transport to support authenticated proxies.
    // Setup the client as the int-rest project does. That is known to setup a client that supports authenticated proxies.
    // https://github.com/googleapis/google-http-java-client/issues/190
    HttpClientBuilder httpClientBuilder = ApacheHttpTransport.newDefaultHttpClientBuilder();
    if (proxyInfo.shouldUseProxy()) {
        String proxyHost = proxyInfo.getHost().orElse(null);
        int proxyPort = proxyInfo.getPort();
        InetSocketAddress proxyAddress = InetSocketAddress.createUnresolved(proxyHost, proxyPort);
        ProxySelector proxySelector = ProxySelector.of(proxyAddress);
        httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(proxySelector));
        httpClientBuilder.setProxy(new HttpHost(proxyHost, proxyPort));
        if (proxyInfo.hasAuthenticatedProxySettings()) {
            NTCredentials credentials = new NTCredentials(proxyInfo.getUsername().orElse(null), proxyInfo.getPassword().orElse(null), proxyInfo.getNtlmWorkstation().orElse(null), proxyInfo.getNtlmDomain().orElse(null));
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(new AuthScope(proxyInfo.getHost().orElse(null), proxyInfo.getPort()), credentials);
            httpClientBuilder.setProxyAuthenticationStrategy(ProxyAuthenticationStrategy.INSTANCE);
            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        }
    }
    return new ApacheHttpTransport(httpClientBuilder.build());
}
Also used : ProxySelector(java.net.ProxySelector) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) InetSocketAddress(java.net.InetSocketAddress) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) SystemDefaultRoutePlanner(org.apache.http.impl.conn.SystemDefaultRoutePlanner) NTCredentials(org.apache.http.auth.NTCredentials)

Aggregations

ApacheHttpTransport (com.google.api.client.http.apache.v2.ApacheHttpTransport)3 HttpHost (org.apache.http.HttpHost)2 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)1 InetSocketAddress (java.net.InetSocketAddress)1 ProxySelector (java.net.ProxySelector)1 AuthScope (org.apache.http.auth.AuthScope)1 NTCredentials (org.apache.http.auth.NTCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1 SystemDefaultRoutePlanner (org.apache.http.impl.conn.SystemDefaultRoutePlanner)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1