nicolasb29 commented on code in PR #2746:
URL: https://github.com/apache/thrift/pull/2746#discussion_r1095434105
##########
lib/java/src/main/java/org/apache/thrift/transport/THttpClient.java:
##########
@@ -279,38 +297,38 @@ private void flushUsingHttpClient() throws
TTransportException {
if (null != customHeaders_) {
customHeaders_.forEach(post::addHeader);
}
- post.setEntity(new ByteArrayEntity(data));
- HttpResponse response = this.client.execute(this.host, post);
- handleResponse(response);
+ post.setEntity(new ByteArrayEntity(data, null));
+ client.execute(
+ this.host,
+ post,
+ response -> {
+ // Retrieve the InputStream BEFORE checking the status code so
+ // resources get freed in the with clause.
+ try (InputStream is = response.getEntity().getContent()) {
+ int responseCode = response.getCode();
+ if (responseCode != HttpStatus.SC_OK) {
+ throw new TTransportException("HTTP Response code: " +
responseCode);
+ }
+ byte[] readByteArray = readIntoByteArray(is);
+ try {
+ // Indicate we're done with the content.
+ consume(response.getEntity());
+ } catch (IOException ioe) {
+ // We ignore this exception, it might only mean the server has
no
+ // keep-alive capability.
+ }
+ inputStream_ = new ByteArrayInputStream(readByteArray);
+ } catch (IOException ioe) {
+ throw new TTransportException(ioe);
+ }
+ return null;
+ });
} catch (IOException ioe) {
// Abort method so the connection gets released back to the connection
manager
post.abort();
throw new TTransportException(ioe);
} finally {
resetConsumedMessageSize(-1);
- post.releaseConnection();
- }
- }
-
- private void handleResponse(HttpResponse response) throws
TTransportException {
Review Comment:
@Jimexist `execute` method as we knew are now
[deprecated](https://hc.apache.org/httpcomponents-client-5.2.x/current/httpclient5/apidocs/org/apache/hc/client5/http/classic/HttpClient.html#executeOpen-org.apache.hc.core5.http.HttpHost-org.apache.hc.core5.http.ClassicHttpRequest-org.apache.hc.core5.http.protocol.HttpContext-),
so I have used an inline function for the `HttpClientResponseHandler`. I just
created a `THttpClientResponseHandler` class to use it at external class in
the `execute` method, it's better and it avoid the RuntimeException in
TException. Another way is to use `executeOpen` but we have to close connection
manually.
##########
compiler/cpp/src/thrift/generate/t_java_generator.cc:
##########
@@ -5848,5 +5857,6 @@ THRIFT_REGISTER_GENERATOR(
" undated: suppress the date at @Generated
annotations\n"
" suppress: suppress @Generated annotations entirely\n"
" unsafe_binaries: Do not copy ByteBuffers in constructors, getters,
and setters.\n"
+ " javax_annotations: generate javax annotations (jakarta by default)\n"
Review Comment:
@Jimexist You are right ! I made modification in the 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]