From 3a553dbff7d4fe3151c37597dfb7ea864337afa1 Mon Sep 17 00:00:00 2001 From: liyu Date: Thu, 6 Feb 2025 00:30:17 +0800 Subject: [PATCH 1/2] add try-catch to ensure release of http resource --- .../folo/client/IndyFoloAdminClientModule.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java b/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java index b70b167..78e4b34 100644 --- a/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java +++ b/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java @@ -115,7 +115,21 @@ public TrackingIdsDTO getTrackingIds( final String trackingType ) public void deleteFilesFromStoreByTrackingID( final BatchDeleteRequest request ) throws IndyClientException { - http.postRaw( UrlUtils.buildUrl( "/folo/admin/batch/delete" ), request ); + String url = UrlUtils.buildUrl("/folo/admin/batch/delete"); + HttpResources resources = null; + try + { + resources = http.postRaw(url, request); + if (resources.getStatusCode() != HttpStatus.SC_OK) + { + throw new IndyClientException( resources.getStatusCode(), "Error deleting files: %s", + new IndyResponseErrorDetails( resources.getResponse() ) ); + } + } + finally + { + IOUtils.closeQuietly( resources ); + } } @Deprecated From 661859eb55f4dcbf5b1481820a7046ca921fb9c9 Mon Sep 17 00:00:00 2001 From: liyu Date: Tue, 11 Mar 2025 15:00:00 +0800 Subject: [PATCH 2/2] replace try with try-with-resource --- .../folo/client/IndyFoloAdminClientModule.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java b/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java index 78e4b34..010c38b 100644 --- a/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java +++ b/addons-client/folo/client-java/src/main/java/org/commonjava/indy/folo/client/IndyFoloAdminClientModule.java @@ -116,20 +116,12 @@ public void deleteFilesFromStoreByTrackingID( final BatchDeleteRequest request ) throws IndyClientException { String url = UrlUtils.buildUrl("/folo/admin/batch/delete"); - HttpResources resources = null; - try - { - resources = http.postRaw(url, request); - if (resources.getStatusCode() != HttpStatus.SC_OK) - { + try (HttpResources resources = http.postRaw(url, request)) { + if (resources.getStatusCode() != HttpStatus.SC_OK) { throw new IndyClientException( resources.getStatusCode(), "Error deleting files: %s", - new IndyResponseErrorDetails( resources.getResponse() ) ); + new IndyResponseErrorDetails( resources.getResponse() ) ); } } - finally - { - IOUtils.closeQuietly( resources ); - } } @Deprecated