This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new fb5b6d7e Migrate to HttpClient 5 and HttpCore 5
fb5b6d7e is described below
commit fb5b6d7ea750dcc7388566eff66a68da14a6705d
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Fri Nov 20 07:19:33 2026 +0100
Migrate to HttpClient 5 and HttpCore 5
Replace the end-of-life HttpComponents 4.x dependencies with the current
5.x releases and update the Javadoc link fetcher to the HttpClient 5 classic
API.
---
pom.xml | 12 ++--
.../apache/maven/plugins/javadoc/JavadocUtil.java | 84 +++++++++++-----------
2 files changed, 47 insertions(+), 49 deletions(-)
diff --git a/pom.xml b/pom.xml
index ca8344c0..3be58f80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -261,14 +261,14 @@ under the License.
<version>3.22.0</version>
</dependency>
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>4.5.14</version>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <version>5.6.5</version>
</dependency>
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpcore</artifactId>
- <version>4.4.16</version>
+ <groupId>org.apache.httpcomponents.core5</groupId>
+ <artifactId>httpcore5</artifactId>
+ <version>5.5</version>
</dependency>
<dependency>
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index fb9e0f9b..012926f4 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -56,6 +56,7 @@ import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.regex.Matcher;
@@ -64,29 +65,30 @@ import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import org.apache.commons.lang3.SystemUtils;
-import org.apache.http.HttpHeaders;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.config.CookieSpecs;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.config.Registry;
-import org.apache.http.config.RegistryBuilder;
-import org.apache.http.conn.socket.ConnectionSocketFactory;
-import org.apache.http.conn.socket.PlainConnectionSocketFactory;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.message.BasicHeader;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.Credentials;
+import org.apache.hc.client5.http.auth.CredentialsStore;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.cookie.StandardCookieSpec;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.protocol.RedirectLocations;
+import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
+import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.config.Registry;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.maven.executor.ExecutorException;
import org.apache.maven.executor.ExecutorRequest;
import org.apache.maven.executor.ExecutorResult;
@@ -1358,14 +1360,15 @@ public class JavadocUtil {
try (CloseableHttpClient httpClient = createHttpClient(settings, url))
{
HttpClientContext httpContext = HttpClientContext.create();
HttpGet httpMethod = new HttpGet(url.toString());
- HttpResponse response = httpClient.execute(httpMethod,
httpContext);
- int status = response.getStatusLine().getStatusCode();
+ ClassicHttpResponse response = httpClient.execute(httpMethod,
httpContext);
+ int status = response.getCode();
if (status != HttpStatus.SC_OK) {
throw new FileNotFoundException(
"Unexpected HTTP status code " + status + " getting
resource " + url.toExternalForm() + ".");
}
- List<URI> redirects = httpContext.getRedirectLocations();
+ RedirectLocations redirectLocations =
httpContext.getRedirectLocations();
+ List<URI> redirects = redirectLocations == null ? null :
redirectLocations.getAll();
if (isEmpty(redirects)) {
return url;
@@ -1455,7 +1458,7 @@ public class JavadocUtil {
final HttpGet httpMethod = new HttpGet(url.toString());
- HttpResponse response;
+ ClassicHttpResponse response;
HttpClientContext httpContext = HttpClientContext.create();
try {
response = httpClient.execute(httpMethod, httpContext);
@@ -1464,13 +1467,14 @@ public class JavadocUtil {
response = httpClient.execute(httpMethod, httpContext);
}
- int status = response.getStatusLine().getStatusCode();
+ int status = response.getCode();
if (status != HttpStatus.SC_OK) {
throw new FileNotFoundException(
"Unexpected HTTP status code " + status + " getting
resource " + url.toExternalForm() + ".");
} else {
int pos = url.getPath().lastIndexOf('/');
- List<URI> redirects = httpContext.getRedirectLocations();
+ RedirectLocations redirectLocations =
httpContext.getRedirectLocations();
+ List<URI> redirects = redirectLocations == null ? null :
redirectLocations.getAll();
if (pos >= 0 && isNotEmpty(redirects)) {
URI location = redirects.get(redirects.size() - 1);
String suffix = url.getPath().substring(pos);
@@ -1488,13 +1492,7 @@ public class JavadocUtil {
@Override
public void close() throws IOException {
super.close();
-
- if (httpMethod != null) {
- httpMethod.releaseConnection();
- }
- if (httpClient != null) {
- httpClient.close();
- }
+ httpClient.close();
}
};
}
@@ -1553,10 +1551,10 @@ public class JavadocUtil {
builder.setConnectionManager(new
PoolingHttpClientConnectionManager(csfRegistry));
builder.setDefaultRequestConfig(RequestConfig.custom()
- .setSocketTimeout(DEFAULT_TIMEOUT)
- .setConnectTimeout(DEFAULT_TIMEOUT)
+ .setResponseTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
+ .setConnectTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
.setCircularRedirectsAllowed(true)
- .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
+ .setCookieSpec(StandardCookieSpec.IGNORE)
.build());
// Some web servers don't allow the default user-agent sent by
httpClient
@@ -1579,11 +1577,11 @@ public class JavadocUtil {
if (activeProxyUsername != null
&& !activeProxyUsername.isEmpty()
&& activeProxy.getPassword() != null) {
- Credentials credentials =
- new
UsernamePasswordCredentials(activeProxyUsername, activeProxy.getPassword());
+ Credentials credentials = new UsernamePasswordCredentials(
+ activeProxyUsername,
activeProxy.getPassword().toCharArray());
- CredentialsProvider credentialsProvider = new
BasicCredentialsProvider();
- credentialsProvider.setCredentials(AuthScope.ANY,
credentials);
+ CredentialsStore credentialsProvider = new
BasicCredentialsProvider();
+ credentialsProvider.setCredentials(new AuthScope(proxy),
credentials);
builder.setDefaultCredentialsProvider(credentialsProvider);
}
}