aajisaka commented on code in PR #4229:
URL: https://github.com/apache/hadoop/pull/4229#discussion_r857265232
##########
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java:
##########
@@ -103,36 +104,39 @@ public synchronized String getAccessToken() throws
IOException {
void refresh() throws IOException {
try {
- OkHttpClient client = new OkHttpClient();
- client.setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
- TimeUnit.MILLISECONDS);
- client.setReadTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
- TimeUnit.MILLISECONDS);
+ OkHttpClient client =
+ new
OkHttpClient.Builder().connectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
+ TimeUnit.MILLISECONDS)
+ .readTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
TimeUnit.MILLISECONDS)
+ .build();
Review Comment:
Would you use try-with-resources for `OkHttpClient`?
##########
hadoop-project/pom.xml:
##########
@@ -227,6 +230,37 @@
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
Review Comment:
I suppose `com.squareup.okhttp:okhttp` can be removed.
##########
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/oauth2/ConfRefreshTokenBasedAccessTokenProvider.java:
##########
@@ -103,36 +104,39 @@ public synchronized String getAccessToken() throws
IOException {
void refresh() throws IOException {
try {
- OkHttpClient client = new OkHttpClient();
- client.setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
- TimeUnit.MILLISECONDS);
- client.setReadTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
- TimeUnit.MILLISECONDS);
+ OkHttpClient client =
+ new
OkHttpClient.Builder().connectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
+ TimeUnit.MILLISECONDS)
+ .readTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT,
TimeUnit.MILLISECONDS)
+ .build();
- String bodyString = Utils.postBody(GRANT_TYPE, REFRESH_TOKEN,
- REFRESH_TOKEN, refreshToken,
- CLIENT_ID, clientId);
+ String bodyString =
+ Utils.postBody(GRANT_TYPE, REFRESH_TOKEN, REFRESH_TOKEN,
refreshToken, CLIENT_ID,
+ clientId);
RequestBody body = RequestBody.create(URLENCODED, bodyString);
- Request request = new Request.Builder()
- .url(refreshURL)
- .post(body)
- .build();
+ Request request = new
Request.Builder().url(refreshURL).post(body).build();
Response responseBody = client.newCall(request).execute();
- if (responseBody.code() != HttpStatus.SC_OK) {
- throw new IllegalArgumentException("Received invalid http response: "
- + responseBody.code() + ", text = " + responseBody.toString());
- }
+ if (responseBody != null) {
+
+ if (responseBody.code() != HttpStatus.SC_OK) {
+ throw new IllegalArgumentException(
+ "Received invalid http response: " + responseBody.code() + ",
text = "
+ + responseBody);
+ }
+
+ Map<?, ?> response = JsonSerialization.mapReader()
+ .readValue(Objects.requireNonNull(responseBody.body()).string());
- Map<?, ?> response = JsonSerialization.mapReader().readValue(
- responseBody.body().string());
+ String newExpiresIn = response.get(EXPIRES_IN).toString();
+ accessTokenTimer.setExpiresIn(newExpiresIn);
- String newExpiresIn = response.get(EXPIRES_IN).toString();
- accessTokenTimer.setExpiresIn(newExpiresIn);
+ accessToken = response.get(ACCESS_TOKEN).toString();
+
+ }
Review Comment:
Would you minimize the formatting change as possible? The main purpose of
the PR is to upgrade the version of okhttp, so you can do the formatting fixes
in a separate issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]