7676import jakarta .json .JsonObjectBuilder ;
7777import jakarta .json .JsonArray ;
7878import jakarta .json .JsonReader ;
79- import org .apache .commons .httpclient .HttpClient ;
8079import org .apache .commons .io .IOUtils ;
81- import org .apache .commons .httpclient .methods .GetMethod ;
8280import java .util .Arrays ;
8381import java .util .Collection ;
8482import java .util .Set ;
8987import jakarta .servlet .http .HttpServletResponse ;
9088import org .apache .commons .lang3 .StringUtils ;
9189import org .apache .commons .lang3 .mutable .MutableBoolean ;
90+ import org .apache .hc .client5 .http .classic .methods .HttpGet ;
91+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
92+ import org .apache .hc .client5 .http .impl .classic .HttpClients ;
93+ import org .apache .hc .core5 .http .ClassicHttpResponse ;
94+ import org .apache .hc .core5 .http .HttpEntity ;
9295import org .primefaces .PrimeFaces ;
9396
9497/**
@@ -1336,46 +1339,6 @@ public String cancel() {
13361339 return returnToDatasetOnly ();
13371340 }
13381341
1339- /* deprecated; super inefficient, when called repeatedly on a long list
1340- of files!
1341- leaving the code here, commented out, for illustration purposes. -- 4.6
1342- public boolean isDuplicate(FileMetadata fileMetadata) {
1343-
1344- Map<String, Integer> MD5Map = new HashMap<String, Integer>();
1345-
1346- // TODO:
1347- // think of a way to do this that doesn't involve populating this
1348- // map for every file on the page?
1349- // may not be that much of a problem, if we paginate and never display
1350- // more than a certain number of files... Still, needs to be revisited
1351- // before the final 4.0.
1352- // -- L.A. 4.0
1353-
1354- // make a "defensive copy" to avoid java.util.ConcurrentModificationException from being thrown
1355- // when uploading 100+ files
1356- List<FileMetadata> wvCopy = new ArrayList<>(workingVersion.getFileMetadatas());
1357- Iterator<FileMetadata> fmIt = wvCopy.iterator();
1358-
1359- while (fmIt.hasNext()) {
1360- FileMetadata fm = fmIt.next();
1361- String md5 = fm.getDataFile().getChecksumValue();
1362- if (md5 != null) {
1363- if (MD5Map.get(md5) != null) {
1364- MD5Map.put(md5, MD5Map.get(md5).intValue() + 1);
1365- } else {
1366- MD5Map.put(md5, 1);
1367- }
1368- }
1369- }
1370-
1371- return MD5Map.get(thisMd5) != null && MD5Map.get(thisMd5).intValue() > 1;
1372- }*/
1373- private HttpClient getClient () {
1374- // TODO:
1375- // cache the http client? -- L.A. 4.0 alpha
1376- return new HttpClient ();
1377- }
1378-
13791342 /**
13801343 * Is this page in File Replace mode
13811344 *
@@ -1414,30 +1377,35 @@ public boolean showFileUploadComponent() {
14141377 * @param fileLink
14151378 * @return
14161379 */
1417- private InputStream getDropBoxInputStream (String fileLink , GetMethod dropBoxMethod ) {
1418-
1380+ private InputStream getDropBoxInputStream (String fileLink ) {
14191381 if (fileLink == null ) {
14201382 return null ;
14211383 }
14221384
1423- // -----------------------------------------------------------
1424- // Make http call, download the file:
1425- // -----------------------------------------------------------
1426- int status = 0 ;
1427- //InputStream dropBoxStream = null;
1428-
14291385 try {
1430- status = getClient ().executeMethod (dropBoxMethod );
1386+ CloseableHttpClient httpClient = HttpClients .createDefault ();
1387+ HttpGet httpGet = new HttpGet (fileLink );
1388+
1389+ // Use the non-deprecated execute method with ClassicHttpResponse
1390+ ClassicHttpResponse response = httpClient .executeOpen (null , httpGet , null );
1391+
1392+ int status = response .getCode ();
1393+
14311394 if (status == 200 ) {
1432- return dropBoxMethod .getResponseBodyAsStream ();
1395+ HttpEntity entity = response .getEntity ();
1396+ if (entity != null ) {
1397+ // Return the content as a stream directly
1398+ return entity .getContent ();
1399+ }
14331400 }
1401+
1402+ logger .log (Level .WARNING , "Failed to get DropBox InputStream for file: {0}. Status code: {1}" , new Object []{fileLink , status });
1403+ response .close ();
1404+ return null ;
14341405 } catch (IOException ex ) {
14351406 logger .log (Level .WARNING , "Failed to access DropBox url: {0}!" , fileLink );
14361407 return null ;
14371408 }
1438-
1439- logger .log (Level .WARNING , "Failed to get DropBox InputStream for file: {0}" , fileLink );
1440- return null ;
14411409 } // end: getDropBoxInputStream
14421410
14431411 /**
@@ -1464,7 +1432,6 @@ public void handleDropBoxUpload(ActionEvent event) {
14641432 // Iterate through the Dropbox file information (JSON)
14651433 // -----------------------------------------------------------
14661434 DataFile dFile = null ;
1467- GetMethod dropBoxMethod = null ;
14681435 String localWarningMessage = null ;
14691436 for (int i = 0 ; i < dbArray .size (); i ++) {
14701437 JsonObject dbObject = dbArray .getJsonObject (i );
@@ -1497,14 +1464,13 @@ public void handleDropBoxUpload(ActionEvent event) {
14971464 }
14981465
14991466 dFile = null ;
1500- dropBoxMethod = new GetMethod (fileLink );
15011467
15021468 // -----------------------------------------------------------
15031469 // Download the file
15041470 // -----------------------------------------------------------
1505- InputStream dropBoxStream = this .getDropBoxInputStream (fileLink , dropBoxMethod );
1471+ InputStream dropBoxStream = this .getDropBoxInputStream (fileLink );
15061472 if (dropBoxStream == null ) {
1507- logger .severe ("Could not retrieve dropgox input stream for: " + fileLink );
1473+ logger .severe ("Could not retrieve dropbox input stream for: " + fileLink );
15081474 continue ; // Error skip this file
15091475 }
15101476
@@ -1542,14 +1508,6 @@ public void handleDropBoxUpload(ActionEvent event) {
15421508 this.logger.log(Level.SEVERE, "Error during ingest of DropBox file {0} from link {1}: {2}", new Object[]{fileName, fileLink, ex.getMessage()});
15431509 continue;
15441510 }*/ finally {
1545- // -----------------------------------------------------------
1546- // release connection for dropBoxMethod
1547- // -----------------------------------------------------------
1548-
1549- if (dropBoxMethod != null ) {
1550- dropBoxMethod .releaseConnection ();
1551- }
1552-
15531511 // -----------------------------------------------------------
15541512 // close the dropBoxStream
15551513 // -----------------------------------------------------------
0 commit comments