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

Upgrade google-http-client to eliminate deprecated usage #1882

Merged
merged 30 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
61f8f6e
Upgrade google-http-client
chanseokoh Jan 14, 2019
3d7ee63
Handle SSLHandshakeException
chanseokoh Jan 14, 2019
0035803
SSLException for all
chanseokoh Jan 14, 2019
400a736
Migrate deprecated usage
chanseokoh Jan 14, 2019
876a8d7
Upgrade Guava and Google HTTP Client
chanseokoh Jan 16, 2019
feff8c7
Merge branch 'master' into remove-deprecated
chanseokoh Jan 16, 2019
63f558b
Migrate
chanseokoh Jan 16, 2019
977ec71
No need to set proxy credentials on our side
chanseokoh Jan 17, 2019
1cd8c30
Merge branch 'master' into upgrade-guava-google-http-client
chanseokoh Jun 13, 2019
ea9bbf0
Merge branch 'upgrade-guava-google-http-client' into remove-deprecated
chanseokoh Jun 13, 2019
6aebc6b
Wrap up
chanseokoh Jun 13, 2019
1b7ca66
Merge branch 'remove-deprecated' into remove-deprecated-simplified
chanseokoh Jun 13, 2019
33ca70a
Update comment
chanseokoh Jun 13, 2019
deb9be4
Upgrade to newer verisons
chanseokoh Jun 13, 2019
093f22c
wip
chanseokoh Jun 13, 2019
7beb767
Apply fix from google-http-client PR
chanseokoh Jun 14, 2019
d3c80ed
Unset default SSLSocketFactory to create new one
chanseokoh Jun 14, 2019
0ea9d03
Add test for proxy credential properties
chanseokoh Jun 14, 2019
08e8e4b
Update comment
chanseokoh Jun 14, 2019
be287c0
Merge branch 'master' into remove-deprecated-simplified
chanseokoh Jun 24, 2019
4bea273
Add proxy properties test
chanseokoh Jun 24, 2019
3b152f7
No need to create readers repeatedly
chanseokoh Jun 24, 2019
633e8b5
Simplify
chanseokoh Jun 24, 2019
f918275
Merge branch 'proxy-property-test' into remove-deprecated-simplified
chanseokoh Jun 24, 2019
69878ef
Merge branch 'master' into remove-deprecated-simplified
chanseokoh Jun 25, 2019
2647c70
Remove blank lines
chanseokoh Jul 3, 2019
3da1724
Merge branch 'master' into remove-deprecated-simplified
chanseokoh Jul 3, 2019
3005f2f
Use Apache v2 client
chanseokoh Jul 8, 2019
5441390
Merge branch 'master' into remove-deprecated-simplified
chanseokoh Aug 1, 2019
a4d9523
Migrate to 1.31
chanseokoh Aug 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jib-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ group 'com.google.cloud.tools'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs += [ '-Xlint:deprecation' ]
compileTestJava.options.compilerArgs += [ '-Xlint:deprecation' ]

repositories {
mavenCentral()
Expand All @@ -35,7 +37,8 @@ configurations {

dependencies {
// Make sure these are consistent with jib-maven-plugin.
implementation 'com.google.http-client:google-http-client:1.27.0'
implementation 'com.google.http-client:google-http-client:1.31.0'
implementation 'com.google.http-client:google-http-client-apache-v2:1.31.0'
implementation 'org.apache.commons:commons-compress:1.18'
implementation 'com.google.guava:guava:27.0.1-jre'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.http.apache.v2.ApacheHttpTransport;
import com.google.api.client.util.SslUtils;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.io.Closeable;
Expand All @@ -31,9 +32,8 @@
import java.security.GeneralSecurityException;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;

/**
* Sends an HTTP {@link Request} and stores the {@link Response}. Clients should not send more than
Expand All @@ -56,17 +56,12 @@ public class Connection implements Closeable {
* @return {@link Connection} factory, a function that generates a {@link Connection} to a URL
*/
public static Function<URL, Connection> getConnectionFactory() {
/*
* Do not use {@link NetHttpTransport}. It does not process response errors properly. A new
* {@link ApacheHttpTransport} needs to be created for each connection because otherwise HTTP
* connection persistence causes the connection to throw {@link NoHttpResponseException}.
*
* @see <a
* href="https://github.com/google/google-http-java-client/issues/39">https://github.com/google/google-http-java-client/issues/39</a>
*/
ApacheHttpTransport transport = new ApacheHttpTransport();
addProxyCredentials(transport);
return url -> new Connection(url, transport);
// Do not use NetHttpTransport. It does not process response errors properly.
// See https://github.com/google/google-http-java-client/issues/39
//
// A new ApacheHttpTransport needs to be created for each connection because otherwise HTTP
// connection persistence causes the connection to throw NoHttpResponseException.
return url -> new Connection(url, new ApacheHttpTransport());
}

/**
Expand All @@ -77,44 +72,14 @@ public static Function<URL, Connection> getConnectionFactory() {
*/
public static Function<URL, Connection> getInsecureConnectionFactory()
throws GeneralSecurityException {
// Do not use {@link NetHttpTransport}. See {@link getConnectionFactory} for details.
ApacheHttpTransport transport =
new ApacheHttpTransport.Builder().doNotValidateCertificate().build();
addProxyCredentials(transport);
return url -> new Connection(url, transport);
}

/**
* Registers proxy credentials onto transport client, in order to deal with proxies that require
* basic authentication.
*
* @param transport Apache HTTP transport
*/
@VisibleForTesting
static void addProxyCredentials(ApacheHttpTransport transport) {
addProxyCredentials(transport, "https");
addProxyCredentials(transport, "http");
}

private static void addProxyCredentials(ApacheHttpTransport transport, String protocol) {
Preconditions.checkArgument(protocol.equals("http") || protocol.equals("https"));

String proxyHost = System.getProperty(protocol + ".proxyHost");
String proxyUser = System.getProperty(protocol + ".proxyUser");
String proxyPassword = System.getProperty(protocol + ".proxyPassword");
if (proxyHost == null || proxyUser == null || proxyPassword == null) {
return;
}

String defaultProxyPort = protocol.equals("http") ? "80" : "443";
int proxyPort = Integer.parseInt(System.getProperty(protocol + ".proxyPort", defaultProxyPort));

DefaultHttpClient httpClient = (DefaultHttpClient) transport.getHttpClient();
httpClient
.getCredentialsProvider()
.setCredentials(
new AuthScope(proxyHost, proxyPort),
new UsernamePasswordCredentials(proxyUser, proxyPassword));
HttpClientBuilder httpClientBuilder =
ApacheHttpTransport.newDefaultHttpClientBuilder()
.setSSLSocketFactory(null) // creates new factory with the SSLContext given below
.setSSLContext(SslUtils.trustAllSSLContext())
.setSSLHostnameVerifier(new NoopHostnameVerifier());

// Do not use NetHttpTransport. See comments in getConnectionFactory for details.
return url -> new Connection(url, new ApacheHttpTransport(httpClientBuilder.build()));
}

private HttpRequestFactory requestFactory;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.cloud.tools.jib.http;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.http.apache.v2.ApacheHttpTransport;
import java.io.IOException;
import java.util.function.BiFunction;

Expand Down
3 changes: 2 additions & 1 deletion jib-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ configurations {

dependencies {
// These are copied over from jib-core and are necessary for the jib-core sourcesets.
compile 'com.google.http-client:google-http-client:1.27.0'
compile 'com.google.http-client:google-http-client:1.31.0'
compile 'com.google.http-client:google-http-client-apache-v2:1.31.0'
compile 'org.apache.commons:commons-compress:1.18'
compile 'com.google.guava:guava:27.0.1-jre'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9.1'
Expand Down
8 changes: 7 additions & 1 deletion jib-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.27.0</version>
<version>1.31.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-apache-v2</artifactId>
<version>1.31.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
3 changes: 2 additions & 1 deletion jib-plugins-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ sourceSets {

dependencies {
// Make sure these are consistent with jib-maven-plugin.
compile 'com.google.http-client:google-http-client:1.27.0'
compile 'com.google.http-client:google-http-client:1.31.0'
compile 'com.google.http-client:google-http-client-apache-v2:1.31.0'
compile 'org.apache.commons:commons-compress:1.18'
compile 'com.google.guava:guava:27.0.1-jre'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9.1'
Expand Down