Skip to content

Commit fb910bd

Browse files
ashutoshcipherAshutosh Gupta
andauthored
HDFS-16453. Upgrade okhttp from 2.7.5 to 4.9.3 (#4229)
Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com> Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
1 parent 0773fae commit fb910bd

File tree

9 files changed

+135
-87
lines changed

9 files changed

+135
-87
lines changed

LICENSE-binary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ com.google.guava:guava:27.0-jre
241241
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
242242
com.microsoft.azure:azure-storage:7.0.0
243243
com.nimbusds:nimbus-jose-jwt:9.8.1
244-
com.squareup.okhttp:okhttp:2.7.5
244+
com.squareup.okhttp3:okhttp:4.9.3
245245
com.squareup.okio:okio:1.6.0
246246
com.zaxxer:HikariCP:4.0.3
247247
commons-beanutils:commons-beanutils:1.9.3

hadoop-client-modules/hadoop-client/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@
114114
<groupId>org.eclipse.jetty</groupId>
115115
<artifactId>jetty-server</artifactId>
116116
</exclusion>
117+
<exclusion>
118+
<groupId>org.jetbrains.kotlin</groupId>
119+
<artifactId>kotlin-stdlib</artifactId>
120+
</exclusion>
121+
<exclusion>
122+
<groupId>org.jetbrains.kotlin</groupId>
123+
<artifactId>kotlin-stdlib-common</artifactId>
124+
</exclusion>
125+
<exclusion>
126+
<groupId>com.squareup.okhttp3</groupId>
127+
<artifactId>okhttp</artifactId>
128+
</exclusion>
117129
<exclusion>
118130
<groupId>com.sun.jersey</groupId>
119131
<artifactId>jersey-core</artifactId>

hadoop-hdfs-project/hadoop-hdfs-client/dev-support/findbugsExcludeFile.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,17 @@
9494
<Bug pattern="EI_EXPOSE_REP" />
9595
</Match>
9696

97+
<!--okhttp classes from Kotlin are not analysed for NP check. -->
98+
<Match>
99+
<Class name="org.apache.hadoop.hdfs.web.oauth2.ConfRefreshTokenBasedAccessTokenProvider" />
100+
<Method name="refresh" />
101+
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" />
102+
</Match>
103+
104+
<Match>
105+
<Class name="org.apache.hadoop.hdfs.web.oauth2.CredentialBasedAccessTokenProvider" />
106+
<Method name="refresh" />
107+
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" />
108+
</Match>
109+
97110
</FindBugsFilter>

hadoop-hdfs-project/hadoop-hdfs-client/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
3535

3636
<dependencies>
3737
<dependency>
38-
<groupId>com.squareup.okhttp</groupId>
38+
<groupId>com.squareup.okhttp3</groupId>
3939
<artifactId>okhttp</artifactId>
4040
</dependency>
41+
<dependency>
42+
<groupId>org.jetbrains.kotlin</groupId>
43+
<artifactId>kotlin-stdlib</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.jetbrains.kotlin</groupId>
47+
<artifactId>kotlin-stdlib-common</artifactId>
48+
</dependency>
4149
<dependency>
4250
<groupId>org.apache.hadoop</groupId>
4351
<artifactId>hadoop-common</artifactId>

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
*/
1919
package org.apache.hadoop.hdfs.web.oauth2;
2020

21-
import com.squareup.okhttp.OkHttpClient;
22-
import com.squareup.okhttp.Request;
23-
import com.squareup.okhttp.RequestBody;
24-
import com.squareup.okhttp.Response;
21+
import java.io.IOException;
22+
import java.util.Map;
23+
import java.util.concurrent.TimeUnit;
24+
25+
import okhttp3.OkHttpClient;
26+
import okhttp3.Request;
27+
import okhttp3.RequestBody;
28+
import okhttp3.Response;
29+
2530
import org.apache.hadoop.classification.InterfaceAudience;
2631
import org.apache.hadoop.classification.InterfaceStability;
2732
import org.apache.hadoop.conf.Configuration;
@@ -30,10 +35,6 @@
3035
import org.apache.hadoop.util.Timer;
3136
import org.apache.http.HttpStatus;
3237

33-
import java.io.IOException;
34-
import java.util.Map;
35-
import java.util.concurrent.TimeUnit;
36-
3738
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY;
3839
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_REFRESH_URL_KEY;
3940
import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.ACCESS_TOKEN;
@@ -102,37 +103,34 @@ public synchronized String getAccessToken() throws IOException {
102103
}
103104

104105
void refresh() throws IOException {
105-
try {
106-
OkHttpClient client = new OkHttpClient();
107-
client.setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
108-
TimeUnit.MILLISECONDS);
109-
client.setReadTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
110-
TimeUnit.MILLISECONDS);
111-
112-
String bodyString = Utils.postBody(GRANT_TYPE, REFRESH_TOKEN,
113-
REFRESH_TOKEN, refreshToken,
114-
CLIENT_ID, clientId);
115-
116-
RequestBody body = RequestBody.create(URLENCODED, bodyString);
117-
118-
Request request = new Request.Builder()
119-
.url(refreshURL)
120-
.post(body)
121-
.build();
122-
Response responseBody = client.newCall(request).execute();
123-
124-
if (responseBody.code() != HttpStatus.SC_OK) {
125-
throw new IllegalArgumentException("Received invalid http response: "
126-
+ responseBody.code() + ", text = " + responseBody.toString());
106+
OkHttpClient client =
107+
new OkHttpClient.Builder().connectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
108+
TimeUnit.MILLISECONDS)
109+
.readTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS)
110+
.build();
111+
112+
String bodyString =
113+
Utils.postBody(GRANT_TYPE, REFRESH_TOKEN, REFRESH_TOKEN, refreshToken, CLIENT_ID, clientId);
114+
115+
RequestBody body = RequestBody.create(bodyString, URLENCODED);
116+
117+
Request request = new Request.Builder().url(refreshURL).post(body).build();
118+
try (Response response = client.newCall(request).execute()) {
119+
if (!response.isSuccessful()) {
120+
throw new IOException("Unexpected code " + response);
121+
}
122+
if (response.code() != HttpStatus.SC_OK) {
123+
throw new IllegalArgumentException(
124+
"Received invalid http response: " + response.code() + ", text = "
125+
+ response.toString());
127126
}
128127

129-
Map<?, ?> response = JsonSerialization.mapReader().readValue(
130-
responseBody.body().string());
128+
Map<?, ?> responseBody = JsonSerialization.mapReader().readValue(response.body().string());
131129

132-
String newExpiresIn = response.get(EXPIRES_IN).toString();
130+
String newExpiresIn = responseBody.get(EXPIRES_IN).toString();
133131
accessTokenTimer.setExpiresIn(newExpiresIn);
134132

135-
accessToken = response.get(ACCESS_TOKEN).toString();
133+
accessToken = responseBody.get(ACCESS_TOKEN).toString();
136134
} catch (Exception e) {
137135
throw new IOException("Exception while refreshing access token", e);
138136
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/CredentialBasedAccessTokenProvider.java

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
*/
1919
package org.apache.hadoop.hdfs.web.oauth2;
2020

21-
import com.squareup.okhttp.OkHttpClient;
22-
import com.squareup.okhttp.Request;
23-
import com.squareup.okhttp.RequestBody;
24-
import com.squareup.okhttp.Response;
21+
import java.io.IOException;
22+
import java.util.Map;
23+
import java.util.concurrent.TimeUnit;
24+
25+
import okhttp3.OkHttpClient;
26+
import okhttp3.Request;
27+
import okhttp3.RequestBody;
28+
import okhttp3.Response;
29+
2530
import org.apache.hadoop.classification.InterfaceAudience;
2631
import org.apache.hadoop.classification.InterfaceStability;
2732
import org.apache.hadoop.conf.Configuration;
@@ -30,10 +35,6 @@
3035
import org.apache.hadoop.util.Timer;
3136
import org.apache.http.HttpStatus;
3237

33-
import java.io.IOException;
34-
import java.util.Map;
35-
import java.util.concurrent.TimeUnit;
36-
3738
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_CLIENT_ID_KEY;
3839
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.OAUTH_REFRESH_URL_KEY;
3940
import static org.apache.hadoop.hdfs.web.oauth2.OAuth2Constants.ACCESS_TOKEN;
@@ -96,38 +97,38 @@ public synchronized String getAccessToken() throws IOException {
9697
}
9798

9899
void refresh() throws IOException {
99-
try {
100-
OkHttpClient client = new OkHttpClient();
101-
client.setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
102-
TimeUnit.MILLISECONDS);
103-
client.setReadTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
104-
TimeUnit.MILLISECONDS);
105-
106-
String bodyString = Utils.postBody(CLIENT_SECRET, getCredential(),
107-
GRANT_TYPE, CLIENT_CREDENTIALS,
108-
CLIENT_ID, clientId);
109-
110-
RequestBody body = RequestBody.create(URLENCODED, bodyString);
111-
112-
Request request = new Request.Builder()
113-
.url(refreshURL)
114-
.post(body)
115-
.build();
116-
Response responseBody = client.newCall(request).execute();
117-
118-
if (responseBody.code() != HttpStatus.SC_OK) {
100+
OkHttpClient client = new OkHttpClient.Builder()
101+
.connectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS)
102+
.readTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS)
103+
.build();
104+
105+
String bodyString = Utils.postBody(CLIENT_SECRET, getCredential(),
106+
GRANT_TYPE, CLIENT_CREDENTIALS,
107+
CLIENT_ID, clientId);
108+
109+
RequestBody body = RequestBody.create(bodyString, URLENCODED);
110+
111+
Request request = new Request.Builder()
112+
.url(refreshURL)
113+
.post(body)
114+
.build();
115+
try (Response response = client.newCall(request).execute()) {
116+
if (!response.isSuccessful()) {
117+
throw new IOException("Unexpected code " + response);
118+
}
119+
120+
if (response.code() != HttpStatus.SC_OK) {
119121
throw new IllegalArgumentException("Received invalid http response: "
120-
+ responseBody.code() + ", text = " + responseBody.toString());
122+
+ response.code() + ", text = " + response.toString());
121123
}
122124

123-
Map<?, ?> response = JsonSerialization.mapReader().readValue(
124-
responseBody.body().string());
125+
Map<?, ?> responseBody = JsonSerialization.mapReader().readValue(
126+
response.body().string());
125127

126-
String newExpiresIn = response.get(EXPIRES_IN).toString();
128+
String newExpiresIn = responseBody.get(EXPIRES_IN).toString();
127129
timer.setExpiresIn(newExpiresIn);
128130

129-
accessToken = response.get(ACCESS_TOKEN).toString();
130-
131+
accessToken = responseBody.get(ACCESS_TOKEN).toString();
131132
} catch (Exception e) {
132133
throw new IOException("Unable to obtain access token from credential", e);
133134
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/OAuth2Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package org.apache.hadoop.hdfs.web.oauth2;
2020

21-
import com.squareup.okhttp.MediaType;
21+
import okhttp3.MediaType;
2222
import org.apache.hadoop.classification.InterfaceAudience;
2323
import org.apache.hadoop.classification.InterfaceStability;
2424

hadoop-project/pom.xml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
<hikari.version>4.0.3</hikari.version>
136136
<mssql.version>6.2.1.jre7</mssql.version>
137137
<okhttp.version>2.7.5</okhttp.version>
138+
<okhttp3.version>4.9.3</okhttp3.version>
139+
<kotlin-stdlib.verion>1.4.10</kotlin-stdlib.verion>
140+
<kotlin-stdlib-common.version>1.4.10</kotlin-stdlib-common.version>
138141
<jdom2.version>2.0.6.1</jdom2.version>
139142
<jna.version>5.2.0</jna.version>
140143
<grizzly.version>2.2.21</grizzly.version>
@@ -222,14 +225,40 @@
222225
<dependencyManagement>
223226
<dependencies>
224227
<dependency>
225-
<groupId>com.squareup.okhttp</groupId>
228+
<groupId>com.squareup.okhttp3</groupId>
226229
<artifactId>okhttp</artifactId>
227-
<version>${okhttp.version}</version>
230+
<version>${okhttp3.version}</version>
231+
<exclusions>
232+
<exclusion>
233+
<groupId>org.jetbrains.kotlin</groupId>
234+
<artifactId>kotlin-stdlib</artifactId>
235+
</exclusion>
236+
<exclusion>
237+
<groupId>org.jetbrains.kotlin</groupId>
238+
<artifactId>kotlin-stdlib-common</artifactId>
239+
</exclusion>
240+
</exclusions>
241+
</dependency>
242+
<dependency>
243+
<groupId>org.jetbrains.kotlin</groupId>
244+
<artifactId>kotlin-stdlib</artifactId>
245+
<version>${kotlin-stdlib.verion}</version>
246+
<exclusions>
247+
<exclusion>
248+
<groupId>org.jetbrains</groupId>
249+
<artifactId>annotations</artifactId>
250+
</exclusion>
251+
</exclusions>
252+
</dependency>
253+
<dependency>
254+
<groupId>org.jetbrains.kotlin</groupId>
255+
<artifactId>kotlin-stdlib-common</artifactId>
256+
<version>${kotlin-stdlib-common.version}</version>
228257
</dependency>
229258
<dependency>
230259
<groupId>com.squareup.okhttp3</groupId>
231260
<artifactId>mockwebserver</artifactId>
232-
<version>3.7.0</version>
261+
<version>4.9.3</version>
233262
<scope>test</scope>
234263
</dependency>
235264
<dependency>

hadoop-tools/hadoop-azure-datalake/pom.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
</description>
3030
<packaging>jar</packaging>
3131
<properties>
32-
<okHttpVersion>${okhttp.version}</okHttpVersion>
3332
<minimalJsonVersion>0.9.1</minimalJsonVersion>
3433
<file.encoding>UTF-8</file.encoding>
3534
<downloadSources>true</downloadSources>
@@ -118,12 +117,6 @@
118117
<artifactId>hadoop-common</artifactId>
119118
<scope>provided</scope>
120119
</dependency>
121-
<dependency>
122-
<groupId>com.squareup.okhttp</groupId>
123-
<artifactId>okhttp</artifactId>
124-
<version>${okhttp.version}</version>
125-
<scope>test</scope>
126-
</dependency>
127120
<dependency>
128121
<groupId>junit</groupId>
129122
<artifactId>junit</artifactId>
@@ -141,12 +134,6 @@
141134
<scope>test</scope>
142135
<type>test-jar</type>
143136
</dependency>
144-
<dependency>
145-
<groupId>com.squareup.okhttp</groupId>
146-
<artifactId>mockwebserver</artifactId>
147-
<version>${okhttp.version}</version>
148-
<scope>test</scope>
149-
</dependency>
150137

151138
<dependency>
152139
<groupId>org.apache.hadoop</groupId>

0 commit comments

Comments
 (0)