Skip to content

Commit

Permalink
Merge pull request #314 from simonjhy/BLADE-737
Browse files Browse the repository at this point in the history
BLADE-737 upgrade httpclient version to 5.2.1
  • Loading branch information
drewbrokke authored Oct 27, 2023
2 parents 1a0bbb5 + 1b4ce44 commit b82b34b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 71 deletions.
70 changes: 39 additions & 31 deletions cli/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,45 @@ Private-Package:\
\
org.apache.groovy.json.internal,\
\
org.apache.http;-split-package:=merge-first,\
org.apache.http.auth;-split-package:=merge-first,\
org.apache.http.client;-split-package:=merge-first,\
org.apache.http.client.config;-split-package:=merge-first,\
org.apache.http.client.entity;-split-package:=merge-first,\
org.apache.http.client.methods;-split-package:=merge-first,\
org.apache.http.client.protocol;-split-package:=merge-first,\
org.apache.http.client.utils;-split-package:=merge-first,\
org.apache.http.cookie;-split-package:=merge-first,\
org.apache.http.concurrent;-split-package:=merge-first,\
org.apache.http.config;-split-package:=merge-first,\
org.apache.http.conn;-split-package:=merge-first,\
org.apache.http.conn.routing;-split-package:=merge-first,\
org.apache.http.conn.socket;-split-package:=merge-first,\
org.apache.http.conn.ssl;-split-package:=merge-first,\
org.apache.http.conn.util;-split-package:=merge-first,\
org.apache.http.entity;-split-package:=merge-first,\
org.apache.http.impl;-split-package:=merge-first,\
org.apache.http.impl.auth;-split-package:=merge-first,\
org.apache.http.impl.client;-split-package:=merge-first,\
org.apache.http.impl.cookie;-split-package:=merge-first,\
org.apache.http.impl.conn;-split-package:=merge-first,\
org.apache.http.impl.entity;-split-package:=merge-first,\
org.apache.http.impl.execchain;-split-package:=merge-first,\
org.apache.http.impl.io;-split-package:=merge-first,\
org.apache.http.io;-split-package:=merge-first,\
org.apache.http.message;-split-package:=merge-first,\
org.apache.http.params;-split-package:=merge-first,\
org.apache.http.pool;-split-package:=merge-first,\
org.apache.http.protocol;-split-package:=merge-first,\
org.apache.http.util;-split-package:=merge-first,\
org.apache.hc.client5.http;-split-package:=merge-first,\
org.apache.hc.client5.http.auth;-split-package:=merge-first,\
org.apache.hc.client5.http.classic;-split-package:=merge-first,\
org.apache.hc.client5.http.classic.methods;-split-package:=merge-first,\
org.apache.hc.client5.http.config;-split-package:=merge-first,\
org.apache.hc.client5.http.cookie;-split-package:=merge-first,\
org.apache.hc.client5.http.entity;-split-package:=merge-first,\
org.apache.hc.client5.http.impl;-split-package:=merge-first,\
org.apache.hc.client5.http.impl.auth;-split-package:=merge-first,\
org.apache.hc.client5.http.impl.cookie;-split-package:=merge-first,\
org.apache.hc.client5.http.impl.classic;-split-package:=merge-first,\
org.apache.hc.client5.http.impl.io;-split-package:=merge-first,\
org.apache.hc.client5.http.impl.routing;-split-package:=merge-first,\
org.apache.hc.client5.http.io;-split-package:=merge-first,\
org.apache.hc.client5.http.protocol;-split-package:=merge-first,\
org.apache.hc.client5.http.psl;-split-package:=merge-first,\
org.apache.hc.client5.http.routing;-split-package:=merge-first,\
org.apache.hc.client5.http.socket;-split-package:=merge-first,\
org.apache.hc.client5.http.ssl;-split-package:=merge-first,\
org.apache.hc.client5.http.utils;-split-package:=merge-first,\
org.apache.hc.core5.concurrent;-split-package:=merge-first,\
org.apache.hc.core5.function;-split-package:=merge-first,\
org.apache.hc.core5.http;-split-package:=merge-first,\
org.apache.hc.core5.http.config;-split-package:=merge-first,\
org.apache.hc.core5.http.impl;-split-package:=merge-first,\
org.apache.hc.core5.http.impl.io;-split-package:=merge-first,\
org.apache.hc.core5.http.io;-split-package:=merge-first,\
org.apache.hc.core5.http.io.entity;-split-package:=merge-first,\
org.apache.hc.core5.http.io.support;-split-package:=merge-first,\
org.apache.hc.core5.http.message;-split-package:=merge-first,\
org.apache.hc.core5.http.protocol;-split-package:=merge-first,\
org.apache.hc.core5.http.ssl;-split-package:=merge-first,\
org.apache.hc.core5.http.support;-split-package:=merge-first,\
org.apache.hc.core5.http2;-split-package:=merge-first,\
org.apache.hc.core5.io;-split-package:=merge-first,\
org.apache.hc.core5.net;-split-package:=merge-first,\
org.apache.hc.core5.pool;-split-package:=merge-first,\
org.apache.hc.core5.ssl;-split-package:=merge-first,\
org.apache.hc.core5.util;-split-package:=merge-first,\
\
org.apache.tools.ant;-split-package:=merge-first,\
org.apache.tools.ant.filters;-split-package:=merge-first,\
Expand Down
8 changes: 3 additions & 5 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ dependencies {
api group: "org.apache.commons", name: "commons-compress", version: "1.21"
api group: "org.apache.commons", name: "commons-configuration2", version: "2.8.0"
api group: "org.apache.commons", name: "commons-text", version: "1.10.0"
api group: "org.apache.httpcomponents", name: "httpclient", version: "4.5.14"
api group: "org.apache.httpcomponents", name: "httpcore", version: "4.4.14"
api group: "org.apache.httpcomponents.client5", name: "httpclient5", version: "5.2.1"
api group: "org.apache.httpcomponents.client5", name: "httpclient5-fluent", version: "5.2.1"
api group: "org.apache.maven", name: "maven-resolver-provider", version: "3.6.3"
api group: "org.apache.maven", name: "maven-settings", version: "3.6.3"
api group: "org.apache.maven", name: "maven-settings-builder", version: "3.6.3"
Expand Down Expand Up @@ -224,7 +224,7 @@ repositories {
}
}

jcenter()
mavenCentral()

maven {
url "https://${repoHost}/nexus/content/repositories/liferay-public-releases/"
Expand All @@ -239,8 +239,6 @@ repositories {
maven {
url "https://repo.gradle.org/gradle/libs-releases-local/"
}

mavenCentral()
}

sourceSets {
Expand Down
64 changes: 29 additions & 35 deletions cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,27 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.auth.AuthScope;
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.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.DateUtils;
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.client.RedirectLocations;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpHead;
import org.apache.hc.client5.http.config.RequestConfig;
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.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.protocol.RedirectLocations;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;

import org.gradle.internal.impldep.com.google.common.base.Strings;

Expand Down Expand Up @@ -156,7 +153,7 @@ public static Path downloadFile(String urlString, Path cacheDirPath, String targ
return Paths.get(downladURI);
}

try (CloseableHttpClient closeableHttpClient = getHttpClient(downladURL.toURI(), null, null, -1)) {
try (CloseableHttpClient closeableHttpClient = getHttpClient(downladURL.toURI(), null, null)) {
return _downloadFile(closeableHttpClient, downladURI, cacheDirPath, targetFileName);
}
}
Expand Down Expand Up @@ -264,13 +261,12 @@ public static File getGradleWrapper(File dir) {
return null;
}

public static CloseableHttpClient getHttpClient(URI uri, String userName, String password, int connectionTimeout) {
public static CloseableHttpClient getHttpClient(URI uri, String userName, String password) {
HttpClientBuilder httpClientBuilder = HttpClients.custom();

RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();

requestConfigBuilder.setConnectTimeout(connectionTimeout);
requestConfigBuilder.setCookieSpec(CookieSpecs.STANDARD);
requestConfigBuilder.setCookieSpec(RequestConfig.DEFAULT.getCookieSpec());
requestConfigBuilder.setRedirectsEnabled(true);

httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
Expand All @@ -293,12 +289,12 @@ public static CloseableHttpClient getHttpClient(URI uri, String userName, String
}

if ((proxyUser != null) && (proxyPassword != null)) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();

if ((proxyHost != null) && (proxyPort != null)) {
credentialsProvider.setCredentials(
new AuthScope(proxyHost, Integer.parseInt(proxyPort)),
new UsernamePasswordCredentials(proxyUser, proxyPassword));
new UsernamePasswordCredentials(proxyUser, proxyPassword.toCharArray()));
}

httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
Expand Down Expand Up @@ -808,10 +804,8 @@ private static boolean _canConnect(InetSocketAddress localAddress, InetSocketAdd
}

private static void _checkResponseStatus(HttpResponse httpResponse) throws IOException {
StatusLine statusLine = httpResponse.getStatusLine();

if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
throw new IOException(statusLine.getReasonPhrase());
if (httpResponse.getCode() != HttpStatus.SC_OK) {
throw new IOException(httpResponse.getReasonPhrase());
}
}

Expand All @@ -834,7 +828,7 @@ private static Path _downloadFile(
RedirectLocations redirectLocations = (RedirectLocations)httpContext.getAttribute(
HttpClientContext.REDIRECT_LOCATIONS);

if (redirectLocations != null) {
if ((redirectLocations != null) && (redirectLocations.size() > 0)) {
uri = redirectLocations.get(redirectLocations.size() - 1);
}
}
Expand Down

0 comments on commit b82b34b

Please sign in to comment.