55
55
import java .io .InputStream ;
56
56
import java .io .OutputStream ;
57
57
import java .lang .reflect .InvocationTargetException ;
58
+ import java .net .MalformedURLException ;
58
59
import java .net .URL ;
59
60
import java .nio .charset .StandardCharsets ;
60
61
import java .time .Duration ;
@@ -121,7 +122,7 @@ public class Client implements AutoCloseable {
121
122
private final Map <String , Object > configuration ;
122
123
123
124
private final Map <String , String > readOnlyConfig ;
124
-
125
+
125
126
private final POJOSerDe pojoSerDe ;
126
127
127
128
private final ExecutorService sharedOperationExecutor ;
@@ -291,7 +292,7 @@ public Builder() {
291
292
*/
292
293
public Builder addEndpoint (String endpoint ) {
293
294
try {
294
- URL endpointURL = new java . net . URL (endpoint );
295
+ URL endpointURL = new URL (endpoint );
295
296
296
297
if (endpointURL .getProtocol ().equalsIgnoreCase ("https" )) {
297
298
addEndpoint (Protocol .HTTP , endpointURL .getHost (), endpointURL .getPort (), true );
@@ -300,7 +301,7 @@ public Builder addEndpoint(String endpoint) {
300
301
} else {
301
302
throw new IllegalArgumentException ("Only HTTP and HTTPS protocols are supported" );
302
303
}
303
- } catch (java . net . MalformedURLException e ) {
304
+ } catch (MalformedURLException e ) {
304
305
throw new IllegalArgumentException ("Endpoint should be a valid URL string, but was " + endpoint , e );
305
306
}
306
307
return this ;
@@ -380,7 +381,7 @@ public Builder setAccessToken(String accessToken) {
380
381
381
382
/**
382
383
* Makes client to use SSL Client Certificate to authenticate with server.
383
- * Client certificate should be set as well. {@link Client. Builder#setClientCertificate(String)}
384
+ * Client certificate should be set as well. {@link Builder#setClientCertificate(String)}
384
385
* @param useSSLAuthentication
385
386
* @return
386
387
*/
@@ -1583,8 +1584,9 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
1583
1584
Endpoint selectedEndpoint = getNextAliveNode ();
1584
1585
RuntimeException lastException = null ;
1585
1586
for (int i = 0 ; i <= retries ; i ++) {
1587
+ ClassicHttpResponse httpResponse = null ;
1586
1588
try {
1587
- ClassicHttpResponse httpResponse =
1589
+ httpResponse =
1588
1590
httpClientHelper .executeRequest (selectedEndpoint , finalSettings .getAllSettings (), lz4Factory , output -> {
1589
1591
output .write (sqlQuery .getBytes (StandardCharsets .UTF_8 ));
1590
1592
output .close ();
@@ -1614,6 +1616,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
1614
1616
return new QueryResponse (httpResponse , responseFormat , finalSettings , metrics );
1615
1617
1616
1618
} catch (Exception e ) {
1619
+ httpClientHelper .closeQuietly (httpResponse );
1617
1620
lastException = httpClientHelper .wrapException (String .format ("Query request failed (Attempt: %s/%s - Duration: %s)" ,
1618
1621
(i + 1 ), (retries + 1 ), System .nanoTime () - startTime ), e );
1619
1622
if (httpClientHelper .shouldRetry (e , finalSettings .getAllSettings ())) {
0 commit comments