33import com .fasterxml .uuid .Generators ;
44import com .fasterxml .uuid .impl .RandomBasedGenerator ;
55import jakarta .inject .Singleton ;
6+ import org .apache .hc .client5 .http .classic .methods .HttpGet ;
7+ import org .apache .hc .client5 .http .config .RequestConfig ;
8+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
9+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
10+ import org .apache .hc .client5 .http .impl .classic .HttpClients ;
11+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
12+ import org .apache .hc .core5 .http .HttpStatus ;
13+ import org .apache .hc .core5 .util .TimeValue ;
14+ import org .apache .hc .core5 .util .Timeout ;
615import org .slf4j .Logger ;
716import org .slf4j .LoggerFactory ;
8- import org .apache .http .HttpStatus ;
9- import org .apache .http .client .config .RequestConfig ;
10- import org .apache .http .client .methods .CloseableHttpResponse ;
11- import org .apache .http .client .methods .HttpGet ;
12- import org .apache .http .impl .client .CloseableHttpClient ;
13- import org .apache .http .impl .client .HttpClients ;
14- import org .apache .http .impl .conn .PoolingHttpClientConnectionManager ;
1517
1618import java .io .IOException ;
1719import java .io .InputStream ;
1820import java .nio .file .Files ;
1921import java .nio .file .Path ;
2022import java .nio .file .StandardCopyOption ;
2123import java .util .UUID ;
22- import java .util .concurrent .TimeUnit ;
2324
2425@ Singleton
2526public class FileDownloadService {
@@ -37,13 +38,17 @@ public FileDownloadService() {
3738 this .poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager ();
3839 this .poolingHttpClientConnectionManager .setMaxTotal (20 );
3940 this .poolingHttpClientConnectionManager .setDefaultMaxPerRoute (15 );
40- this .poolingHttpClientConnectionManager .setValidateAfterInactivity (15_000 );
41+ // Changed: int -> TimeValue
42+ this .poolingHttpClientConnectionManager .setValidateAfterInactivity (TimeValue .ofMilliseconds (15_000 ));
4143
4244 this .httpRequestConfig = RequestConfig .custom ()
43- .setConnectTimeout (10_000 )
44- .setSocketTimeout (10_000 )
45- .setConnectionRequestTimeout (3_000 )
46- .build ();
45+ // Changed: int -> Timeout
46+ .setConnectTimeout (Timeout .ofMilliseconds (10_000 ))
47+ // Changed: setSocketTimeout -> setResponseTimeout
48+ .setResponseTimeout (Timeout .ofMilliseconds (10_000 ))
49+ // Changed: int -> Timeout
50+ .setConnectionRequestTimeout (Timeout .ofMilliseconds (3_000 ))
51+ .build ();
4752
4853 try {
4954 this .sharedTempDir = Files .createTempDirectory (TEMP_DIR_NAME );
@@ -57,7 +62,8 @@ private CloseableHttpClient buildHttpClient() {
5762 .custom ()
5863 .setConnectionManager (poolingHttpClientConnectionManager )
5964 .setDefaultRequestConfig (httpRequestConfig )
60- .evictIdleConnections (30 , TimeUnit .SECONDS )
65+ // Changed: (int, TimeUnit) -> TimeValue
66+ .evictIdleConnections (TimeValue .ofSeconds (30 ))
6167 .evictExpiredConnections ()
6268 .build ();
6369 }
@@ -77,8 +83,10 @@ public Path downloadToTemp(final String url) throws IOException {
7783 final HttpGet httpGet = new HttpGet (url );
7884
7985 try (final CloseableHttpResponse response = buildHttpClient ().execute (httpGet )) {
80-
81- final int statusCode = response .getStatusLine ().getStatusCode ();
86+
87+ // Changed: getStatusLine().getStatusCode() -> getCode()
88+ final int statusCode = response .getCode ();
89+
8290 if (statusCode != HttpStatus .SC_OK ) {
8391 throw new IOException ("Non Resolvable url: " + url );
8492 }
@@ -92,6 +100,8 @@ public Path downloadToTemp(final String url) throws IOException {
92100 return tempFile ;
93101
94102 } catch (final IllegalArgumentException e ) {
103+ // Note: HttpGet in v5 might throw different runtime exceptions for bad URIs,
104+ // but catching IllegalArgumentException covers the general URI format errors.
95105 throw new IOException ("Invalid URL format: " + url , e );
96106 }
97107 }
@@ -122,4 +132,4 @@ private String generateUuidFilename() {
122132 final UUID uuid = generator .generate ();
123133 return uuid .toString () + ".csv" ;
124134 }
125- }
135+ }
0 commit comments