Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Apache HTTP Client to version 5.4 #963

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
<groupId>io.jenkins.plugins</groupId>
<artifactId>apache-httpcomponents-client-5-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -92,6 +92,12 @@
<artifactId>git</artifactId>
<!-- TODO: remove when in bom -->
<version>5.7.0</version>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -116,6 +122,12 @@
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -177,6 +189,10 @@
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Expand Down Expand Up @@ -233,16 +249,6 @@
</execution>
</executions>
</plugin>
<plugin> <!-- TODO scm-api gratuitously restricts deprecated APIs, preventing us from compiling even deprecated classes in *this* plugin -->
<groupId>org.kohsuke</groupId>
<artifactId>access-modifier-checker</artifactId>
<executions>
<execution>
<id>default-enforce</id>
<phase /> <!-- https://stackoverflow.com/a/19540026/12916 -->
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import hudson.plugins.git.GitSCM;
import jenkins.authentication.tokens.api.AuthenticationTokenContext;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;

/**
* Support for various different methods of authenticating with Bitbucket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFile;
import com.cloudbees.jenkins.plugins.bitbucket.impl.client.AbstractBitbucketApi;
import com.cloudbees.jenkins.plugins.bitbucket.impl.credentials.BitbucketUsernamePasswordAuthenticator;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.JsonParser;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.damnhandy.uri.template.UriTemplate;
Expand All @@ -69,24 +70,26 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import javax.imageio.ImageIO;
import jenkins.scm.api.SCMFile;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.config.SocketConfig;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http.message.BasicNameValuePair;

import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MINUTES;

public class BitbucketCloudApiClient extends AbstractBitbucketApi implements BitbucketApi {

private static final HttpHost API_HOST = HttpHost.create("https://api.bitbucket.org");
private static final HttpHost API_HOST = BitbucketApiUtils.toHttpHost("https://api.bitbucket.org");
private static final String V2_API_BASE_URL = "https://api.bitbucket.org/2.0/repositories";
private static final String V2_WORKSPACES_API_BASE_URL = "https://api.bitbucket.org/2.0/workspaces";
private static final String REPO_URL_TEMPLATE = V2_API_BASE_URL + "{/owner,repo}";
Expand All @@ -109,11 +112,24 @@ public class BitbucketCloudApiClient extends AbstractBitbucketApi implements Bit

private static HttpClientConnectionManager connectionManager() {
try {
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); // NOSONAR
connManager.setDefaultMaxPerRoute(20);
connManager.setMaxTotal(22);
connManager.setSocketConfig(API_HOST, SocketConfig.custom().setSoTimeout(60 * 1000).build());
return connManager;
int connectTimeout = Integer.getInteger("http.connect.timeout", 10);
int socketTimeout = Integer.getInteger("http.socket.timeout", 60);

ConnectionConfig connCfg = ConnectionConfig.custom()
.setConnectTimeout(connectTimeout, TimeUnit.SECONDS)
.setSocketTimeout(socketTimeout, TimeUnit.SECONDS)
.build();

SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(60, TimeUnit.SECONDS)
.build();

return PoolingHttpClientConnectionManagerBuilder.create()
.setMaxConnPerRoute(20)
.setMaxConnTotal(22)
.setDefaultConnectionConfig(connCfg)
.setSocketConfigResolver(host -> host.getTargetHost().equals(API_HOST) ? socketConfig : SocketConfig.DEFAULT)
.build();
} catch (Exception e) {
// in case of exception this avoids ClassNotFoundError which prevents the classloader from loading this class again
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import java.io.IOException;
import java.io.InputStream;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;

public class ClosingConnectionInputStream extends InputStream {

private final CloseableHttpResponse response;
private final ClassicHttpResponse response;

private final HttpRequestBase method;
private final HttpUriRequest method;

private final HttpClientConnectionManager connectionManager;

private final InputStream delegate;

public ClosingConnectionInputStream(final CloseableHttpResponse response, final HttpRequestBase method,
final HttpClientConnectionManager connectionmanager)
throws UnsupportedOperationException, IOException {
public ClosingConnectionInputStream(final ClassicHttpResponse response,
final HttpUriRequest method,
final HttpClientConnectionManager connectionmanager) throws IOException {
this.response = response;
this.method = method;
this.connectionManager = connectionmanager;
Expand All @@ -35,8 +35,8 @@ public int available() throws IOException {
public void close() throws IOException {
EntityUtils.consume(response.getEntity());
delegate.close();
method.releaseConnection();
connectionManager.closeExpiredConnections();
//FIXME method.releaseConnection();
//FIXME connectionManager.closeExpiredConnections();
}

@Override
Expand Down
Loading
Loading