chrisdennis commented on code in PR #274:
URL: https://github.com/apache/calcite-avatica/pull/274#discussion_r1949425754
##########
core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java:
##########
@@ -151,14 +154,21 @@ private RequestConfig createRequestConfig() {
}
@Override public byte[] send(byte[] request) {
Review Comment:
I think I'd prefer an approach like this for adapting to the new
`ensureOpen(...)` syntax since it avoids the need for any pass-by-instance
semantics:
```java
@Override public byte[] send(byte[] request) {
// Create the client with the AuthSchemeRegistry and manager
HttpPost post = new HttpPost(uri);
try {
HttpHost host = RoutingSupport.determineHost(post);
while (true) {
ByteArrayEntity entity = new ByteArrayEntity(request,
ContentType.APPLICATION_OCTET_STREAM);
post.setEntity(entity);
try (ClassicHttpResponse response = executeOpen(host, post, context)) {
final int statusCode = response.getCode();
if (HttpURLConnection.HTTP_OK == statusCode
|| HttpURLConnection.HTTP_INTERNAL_ERROR == statusCode) {
userToken = context.getUserToken();
return EntityUtils.toByteArray(response.getEntity());
} else if (HttpURLConnection.HTTP_UNAVAILABLE == statusCode) {
LOG.debug("Failed to connect to server (HTTP/503), retrying");
continue;
}
throw new RuntimeException(
"Failed to execute HTTP Request, got HTTP/" + statusCode);
} catch (NoHttpResponseException e) {
// This can happen when sitting behind a load balancer and a backend
server dies
LOG.debug("The server failed to issue an HTTP response, retrying");
continue;
}
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
LOG.debug("Failed to execute HTTP request", e);
throw new RuntimeException(e);
}
}
```
--
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]