You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "ebyhr (via GitHub)" <gi...@apache.org> on 2026/04/28 23:38:22 UTC

[PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

ebyhr opened a new pull request, #16149:
URL: https://github.com/apache/iceberg/pull/16149

   Replaces the deprecated method usage `execute(ClassicHttpRequest, HttpContext)` with `execute(ClassicHttpRequest, HttpClientResponseHandler)`. 
   
   I recommend reviewing this RP with the hiding whitespace option. 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "ebyhr (via GitHub)" <gi...@apache.org>.
ebyhr commented on code in PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#discussion_r3167337396


##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -318,53 +317,69 @@ protected <T extends RESTResponse> T execute(
     }
 
     HttpContext context = HttpClientContext.create();
-    try (CloseableHttpResponse response = httpClient.execute(request, context)) {
-      Map<String, String> respHeaders = Maps.newHashMap();
-      for (Header header : response.getHeaders()) {
-        respHeaders.put(header.getName(), header.getValue());
-      }
-
-      responseHeaders.accept(respHeaders);
-
-      // Skip parsing the response stream for any successful request not expecting a response body
-      if (emptyBody(response, responseType)) {
-        if (response.getCode() == HttpStatus.SC_NOT_MODIFIED
-            && !req.headers().contains(HttpHeaders.IF_NONE_MATCH)) {
-          // 304-NOT_MODIFIED is used for freshness-aware loading and requires an ETag sent to the
-          // server via IF_NONE_MATCH header in the request. If no ETag was sent, we shouldn't
-          // receive a 304.
-          throw new RESTException(
-              "Invalid (NOT_MODIFIED) response for request: method=%s, path=%s",
-              req.method(), req.path());
-        }
+    try {
+      return httpClient.execute(
+          request,
+          context,
+          response ->

Review Comment:
   @gaborkaszab I don't think this needs to be addressed at the moment. We can expose it for testing later if there's a clear need.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "ebyhr (via GitHub)" <gi...@apache.org>.
ebyhr commented on code in PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#discussion_r3167337396


##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -318,53 +317,69 @@ protected <T extends RESTResponse> T execute(
     }
 
     HttpContext context = HttpClientContext.create();
-    try (CloseableHttpResponse response = httpClient.execute(request, context)) {
-      Map<String, String> respHeaders = Maps.newHashMap();
-      for (Header header : response.getHeaders()) {
-        respHeaders.put(header.getName(), header.getValue());
-      }
-
-      responseHeaders.accept(respHeaders);
-
-      // Skip parsing the response stream for any successful request not expecting a response body
-      if (emptyBody(response, responseType)) {
-        if (response.getCode() == HttpStatus.SC_NOT_MODIFIED
-            && !req.headers().contains(HttpHeaders.IF_NONE_MATCH)) {
-          // 304-NOT_MODIFIED is used for freshness-aware loading and requires an ETag sent to the
-          // server via IF_NONE_MATCH header in the request. If no ETag was sent, we shouldn't
-          // receive a 304.
-          throw new RESTException(
-              "Invalid (NOT_MODIFIED) response for request: method=%s, path=%s",
-              req.method(), req.path());
-        }
+    try {
+      return httpClient.execute(
+          request,
+          context,
+          response ->

Review Comment:
   @gaborkaszab I don't think we need to address this right now. We can expose it for testing later if a clear need arises. I extracted the class locally but discarded it since it didn’t simplify the current code.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary merged PR #16149:
URL: https://github.com/apache/iceberg/pull/16149


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#issuecomment-4476608136

   Maybe @pvary, would you mind taking a look?


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on code in PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#discussion_r3161971151


##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -317,54 +314,61 @@ protected <T extends RESTResponse> T execute(
       request.setEntity(new StringEntity(encodedBody));
     }
 
-    HttpContext context = HttpClientContext.create();
-    try (CloseableHttpResponse response = httpClient.execute(request, context)) {
-      Map<String, String> respHeaders = Maps.newHashMap();
-      for (Header header : response.getHeaders()) {
-        respHeaders.put(header.getName(), header.getValue());
-      }
-
-      responseHeaders.accept(respHeaders);
-
-      // Skip parsing the response stream for any successful request not expecting a response body
-      if (emptyBody(response, responseType)) {
-        if (response.getCode() == HttpStatus.SC_NOT_MODIFIED
-            && !req.headers().contains(HttpHeaders.IF_NONE_MATCH)) {
-          // 304-NOT_MODIFIED is used for freshness-aware loading and requires an ETag sent to the
-          // server via IF_NONE_MATCH header in the request. If no ETag was sent, we shouldn't
-          // receive a 304.
-          throw new RESTException(
-              "Invalid (NOT_MODIFIED) response for request: method=%s, path=%s",
-              req.method(), req.path());
-        }
-
-        return null;
-      }
-
-      if (!isSuccessful(response)) {
-        // The provided error handler is expected to throw, but a RESTException is thrown if not.
-        String responseBody = extractResponseBodyAsString(response);
-        throwFailure(response, responseBody, errorHandler);
-      }
-
-      if (response.getEntity() == null) {
-        throw new RESTException(
-            "Invalid (null) response body for request (expected %s): method=%s, path=%s, status=%d",
-            responseType.getSimpleName(), req.method(), req.path(), response.getCode());
-      }
-
-      ObjectReader reader = objectReaderCache.computeIfAbsent(responseType, mapper::readerFor);
-      if (parserContext != null && !parserContext.isEmpty()) {
-        reader = reader.with(parserContext.toInjectableValues());
-      }
-      return reader.readValue(response.getEntity().getContent());
+    try {
+      return httpClient.execute(

Review Comment:
   I see before we used the signature with HttpContext and now you went for the one without. Just to be on the safe side, since we passed an "empty context" this is fine here, right?



##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -317,54 +314,61 @@ protected <T extends RESTResponse> T execute(
       request.setEntity(new StringEntity(encodedBody));
     }
 
-    HttpContext context = HttpClientContext.create();
-    try (CloseableHttpResponse response = httpClient.execute(request, context)) {
-      Map<String, String> respHeaders = Maps.newHashMap();
-      for (Header header : response.getHeaders()) {
-        respHeaders.put(header.getName(), header.getValue());
-      }
-
-      responseHeaders.accept(respHeaders);
-
-      // Skip parsing the response stream for any successful request not expecting a response body
-      if (emptyBody(response, responseType)) {
-        if (response.getCode() == HttpStatus.SC_NOT_MODIFIED
-            && !req.headers().contains(HttpHeaders.IF_NONE_MATCH)) {
-          // 304-NOT_MODIFIED is used for freshness-aware loading and requires an ETag sent to the
-          // server via IF_NONE_MATCH header in the request. If no ETag was sent, we shouldn't
-          // receive a 304.
-          throw new RESTException(
-              "Invalid (NOT_MODIFIED) response for request: method=%s, path=%s",
-              req.method(), req.path());
-        }
-
-        return null;
-      }
-
-      if (!isSuccessful(response)) {
-        // The provided error handler is expected to throw, but a RESTException is thrown if not.
-        String responseBody = extractResponseBodyAsString(response);
-        throwFailure(response, responseBody, errorHandler);
-      }
-
-      if (response.getEntity() == null) {
-        throw new RESTException(
-            "Invalid (null) response body for request (expected %s): method=%s, path=%s, status=%d",
-            responseType.getSimpleName(), req.method(), req.path(), response.getCode());
-      }
-
-      ObjectReader reader = objectReaderCache.computeIfAbsent(responseType, mapper::readerFor);
-      if (parserContext != null && !parserContext.isEmpty()) {
-        reader = reader.with(parserContext.toInjectableValues());
-      }
-      return reader.readValue(response.getEntity().getContent());
+    try {

Review Comment:
   nit: maybe introducing a separate function for the response handler implementation instead of inline lambda? Might help with the indentations, and could introduce some flexibility for testing too later on.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#issuecomment-4531869081

   Merged to main.
   Thanks @ebyhr for the PR and @gaborkaszab for the review!


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on code in PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#discussion_r3167457483


##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -318,53 +317,69 @@ protected <T extends RESTResponse> T execute(
     }
 
     HttpContext context = HttpClientContext.create();
-    try (CloseableHttpResponse response = httpClient.execute(request, context)) {
-      Map<String, String> respHeaders = Maps.newHashMap();
-      for (Header header : response.getHeaders()) {
-        respHeaders.put(header.getName(), header.getValue());
-      }
-
-      responseHeaders.accept(respHeaders);
-
-      // Skip parsing the response stream for any successful request not expecting a response body
-      if (emptyBody(response, responseType)) {
-        if (response.getCode() == HttpStatus.SC_NOT_MODIFIED
-            && !req.headers().contains(HttpHeaders.IF_NONE_MATCH)) {
-          // 304-NOT_MODIFIED is used for freshness-aware loading and requires an ETag sent to the
-          // server via IF_NONE_MATCH header in the request. If no ETag was sent, we shouldn't
-          // receive a 304.
-          throw new RESTException(
-              "Invalid (NOT_MODIFIED) response for request: method=%s, path=%s",
-              req.method(), req.path());
-        }
+    try {
+      return httpClient.execute(
+          request,
+          context,
+          response ->

Review Comment:
   I didn't mean to expose it now, it would be out of scope for this PR. What I meant is that instead having a `handleResponse` function and using it in the lambda, we could have an `HttpClientResponseHandler` implementation as a member of this class.
   No strong feelings though, up to you.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on code in PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#discussion_r3166552846


##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -318,53 +317,69 @@ protected <T extends RESTResponse> T execute(
     }
 
     HttpContext context = HttpClientContext.create();
-    try (CloseableHttpResponse response = httpClient.execute(request, context)) {
-      Map<String, String> respHeaders = Maps.newHashMap();
-      for (Header header : response.getHeaders()) {
-        respHeaders.put(header.getName(), header.getValue());
-      }
-
-      responseHeaders.accept(respHeaders);
-
-      // Skip parsing the response stream for any successful request not expecting a response body
-      if (emptyBody(response, responseType)) {
-        if (response.getCode() == HttpStatus.SC_NOT_MODIFIED
-            && !req.headers().contains(HttpHeaders.IF_NONE_MATCH)) {
-          // 304-NOT_MODIFIED is used for freshness-aware loading and requires an ETag sent to the
-          // server via IF_NONE_MATCH header in the request. If no ETag was sent, we shouldn't
-          // receive a 304.
-          throw new RESTException(
-              "Invalid (NOT_MODIFIED) response for request: method=%s, path=%s",
-              req.method(), req.path());
-        }
+    try {
+      return httpClient.execute(
+          request,
+          context,
+          response ->

Review Comment:
   Thanks you for the changes @ebyhr !
   Here, probably it doesn't matter much, but what I had in mind is to have a member of the class that implements `HttpClientResponseHandler`, and instead of a lambda we could pass that member here.
   It would be helpful later on to swap that out for some custom handler (maybe wrap it into one that could verify content of HTTP response) for testing.
   Let me know if this is over engineering, or too unrelated to this PR. I figured since we touch this part, would also make sense.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Replace deprecated CloseableHttpClient.execute [iceberg]

Posted by "ebyhr (via GitHub)" <gi...@apache.org>.
ebyhr commented on PR #16149:
URL: https://github.com/apache/iceberg/pull/16149#issuecomment-4531385989

   @pvary Can we merge this PR? 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org