Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google-http-client 1.28.0 missing com.google.api.client.http.apache #576

Closed
chanseokoh opened this issue Jan 16, 2019 · 6 comments
Closed
Assignees

Comments

@chanseokoh
Copy link
Contributor

com.google.api.client.http.apache present in 1.27.0:

selection_002

However, missing in 1.28.0:

selection_003

Also, after upgrading to 1.28.0, I have to manually add the org.apache.httpcomponents:httpclient dependency to resolve org.apache.http.client.HttpClient, etc. Is this expected?

@chingor13
Copy link
Collaborator

We had to break the apache adapter into its own artifact google-http-client-apache and provide 2 implementations - 1.28.0 for legacy versions of Apache HttpClient and 2.0.0 for modern versions. The google-http-client-apache artifact includes the dependency on org.apache.httpcomponents:httpclient.

The legacy version was necessary for internal usage.

https://github.com/googleapis/google-http-java-client/releases/tag/v1.28.0

@chanseokoh
Copy link
Contributor Author

chanseokoh commented Jan 16, 2019

Thanks. I put google-http-client-apache, and I could see the package.

One thing I discovered I think worth documenting here: I see 1.28.0 pulls in guava:26.0-android, which made my Gradle build uses 26.0-android for everything even if I explicitly declared guava:23.5-jre in my build.gradle. For example,

testCompileClasspath - Compile classpath for source set 'test'.
+--- com.google.guava:guava:23.5-jre -> 26.0-android
|    +--- ...
+--- com.google.http-client:google-http-client:1.28.0
|    +--- com.google.code.findbugs:jsr305:3.0.2
|    +--- com.google.guava:guava:26.0-android (*)
|    +--- com.google.j2objc:j2objc-annotations:1.1
|    +--- io.opencensus:opencensus-api:0.18.0
|    |    \--- io.grpc:grpc-context:1.14.0
|    \--- io.opencensus:opencensus-contrib-http-util:0.18.0
|         +--- io.opencensus:opencensus-api:0.18.0 (*)
|         \--- com.google.guava:guava:20.0 -> 26.0-android (*)

This cause a lot of errors in my project, since the -android version lacks some classes and methods such as ImmutableList.toImmutableList(), MoreFiles, RecursiveDeleteOption, etc. I upgraded the direct guava:23.5-jre dependency to guava:26.0-jre to resolve the issue, but not everyone may be able to do it.

@chanseokoh
Copy link
Contributor Author

Also, my last question:

With 1.27.0, many classes and methods such as DefaultHttpClient were marked deprecated. That's why I was trying 1.28.0. But now I see they are not deprecated anymore with 1.28.0. Will they be kept non deprecated with the modern 2.0.0 version? I was trying to migrate away from the deprecated classes, but if they are not going to be deprecated, I don't have to touch my current codebase.

@chingor13
Copy link
Collaborator

Re guava: we chose the android flavor as we need to support Java 7 still and 26.0 to match grpc's dependency. It looks like the -android variant is a subset of the -jre version so using the -jre variant should be fine (ImmutableList.toImmutableList(), MoreFiles, and RecursiveDeleteOption appear to use Java > 8 APIs, so they are not included in the -android flavor).

As for the methods around DefaultHttpClient - the DefaultHttpClient class was deprecated so 2.0.0 removed references to that. We did keep a ApacheHttpTransport.newDefaultHttpClient(), but changed the return type to org.apache.http.client.HttpClient (was org.apache.http.client.DefaultHttpClient which is an implementation of HttpClient).

You may need to change your code anyways because the newer implementations of Apache HttpClient do not let you modify a HttpClient instance once it's built (hence the need for making a 2.0.0 and refactoring the Apache adapter).

@chanseokoh
Copy link
Contributor Author

Thanks for the info. Closing.

@chanseokoh
Copy link
Contributor Author

I have some annoyance with the new ApacheHttpTransport 2.0.0 API. I need to adjust some configs of HttpClient, e.g.,

            .setSSLContext(SslUtils.trustAllSSLContext())
            .setSSLHostnameVerifier(new NoopHostnameVerifier())

To achieve this, I need to duplicate the code of newDefaultHttpClient() like below to match the parity (there are other places in our code that just uses the default HttpClient):

    SocketConfig socketConfig =
        SocketConfig.custom()
            .setRcvBufSize(8192)
            .setSndBufSize(8192)
            .build();

    PoolingHttpClientConnectionManager connectionManager =
        new PoolingHttpClientConnectionManager(-1, TimeUnit.MILLISECONDS);
    connectionManager.setValidateAfterInactivity(-1);

    HttpClient httpClient = HttpClientBuilder.create()
        .useSystemProperties()
        // not calling this, since I need custom "SSLContext" and "HostnameVerifier"
        // .setSSLSocketFactory(SSLConnectionSocketFactory.getSocketFactory())
        .setDefaultSocketConfig(socketConfig)
        .setMaxConnTotal(200)
        .setMaxConnPerRoute(20)
        .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()))
        .setConnectionManager(connectionManager)
        .disableRedirectHandling()
        .disableAutomaticRetries()
        // Just because of these two, I have to duplicate the whole code from google-http-client-apache
        .setSSLContext(SslUtils.trustAllSSLContext())
        .setSSLHostnameVerifier(new NoopHostnameVerifier())
        .build();

    ... = new ApacheHttpTransport(httpClient);

Any idea or advice on what the best option would be for me?

clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
@chingor13 This change keeps Maven 3.6.1 and later from spamming our CI logs with page after page of lists of artifacts it's downloading that makes it much harder to find the actual test output.

Source-Author: Elliotte Rusty Harold <elharo@users.noreply.github.com>
Source-Date: Thu Feb 18 19:58:59 2021 +0000
Source-Repo: googleapis/synthtool
Source-Sha: 1aeca92e4a38f47134cb955f52ea76f84f09ff88
Source-Link: googleapis/synthtool@1aeca92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants