Skip to content

Commit 6fe03de

Browse files
committed
switch to dropwizard httpclient config
1 parent 75b72d4 commit 6fe03de

File tree

7 files changed

+36
-133
lines changed

7 files changed

+36
-133
lines changed

maven-nodejs-proxy/config.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ npmBinariesUrl: "/npm/npm-${version}.${type}"
2020
nodeJsChecksumUrl: "/v${version}/SHASUMS.txt"
2121

2222
# HTTP Client settings
23-
httpClientConnectTimeout: 5000
24-
httpClientSocketTimeout: 15000
23+
httpClient:
24+
connectionTimeout: 2s
25+
timeout: 5s
26+
timeToLive: 1h
27+
cookiesEnabled: false
28+
retries: 2
29+
userAgent: Maven NodeJS Proxy
2530

26-
# Dropwizard config
31+
# Jetty configuration
2732
server:
2833
# Disable gzip compression to avoid corruption of tar.gz files
2934
gzip:

maven-nodejs-proxy/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@
4949
<version>${dropwizard.version}</version>
5050
<scope>compile</scope>
5151
</dependency>
52-
5352
<dependency>
54-
<groupId>org.apache.httpcomponents</groupId>
55-
<artifactId>httpclient</artifactId>
56-
<version>4.5</version>
53+
<groupId>io.dropwizard</groupId>
54+
<artifactId>dropwizard-client</artifactId>
55+
<version>${dropwizard.version}</version>
5756
<scope>compile</scope>
5857
</dependency>
5958

maven-nodejs-proxy/src/main/java/io/wcm/devops/maven/nodejsproxy/MavenProxyApplication.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
package io.wcm.devops.maven.nodejsproxy;
2121

2222
import io.dropwizard.Application;
23+
import io.dropwizard.client.HttpClientBuilder;
2324
import io.dropwizard.setup.Bootstrap;
2425
import io.dropwizard.setup.Environment;
2526
import io.wcm.devops.maven.nodejsproxy.health.NodeJsDistHealthCheck;
2627
import io.wcm.devops.maven.nodejsproxy.resource.MavenProxyResource;
2728

29+
import org.apache.http.impl.client.CloseableHttpClient;
30+
2831
/**
2932
* Dropwizard Application for Maven NodeJS Proxy.
3033
*/
@@ -41,11 +44,14 @@ public void initialize(Bootstrap<MavenProxyConfiguration> bootstrap) {
4144
}
4245

4346
@Override
44-
public void run(MavenProxyConfiguration configuration,
45-
Environment environment) {
46-
final MavenProxyResource resource = new MavenProxyResource(configuration);
47+
public void run(MavenProxyConfiguration config, Environment environment) {
48+
final CloseableHttpClient httpClient = new HttpClientBuilder(environment)
49+
.using(config.getHttpClient())
50+
.build("default");
51+
52+
final MavenProxyResource resource = new MavenProxyResource(config, httpClient);
4753

48-
final NodeJsDistHealthCheck healthCheck = new NodeJsDistHealthCheck(configuration);
54+
final NodeJsDistHealthCheck healthCheck = new NodeJsDistHealthCheck(config, httpClient);
4955
environment.healthChecks().register("nodeJsDist", healthCheck);
5056

5157
environment.jersey().register(resource);

maven-nodejs-proxy/src/main/java/io/wcm/devops/maven/nodejsproxy/MavenProxyConfiguration.java

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
package io.wcm.devops.maven.nodejsproxy;
2121

2222
import io.dropwizard.Configuration;
23+
import io.dropwizard.client.HttpClientConfiguration;
24+
25+
import javax.validation.Valid;
26+
import javax.validation.constraints.NotNull;
2327

2428
import org.hibernate.validator.constraints.NotEmpty;
2529

@@ -48,116 +52,59 @@ public class MavenProxyConfiguration extends Configuration {
4852
private String npmBinariesUrl;
4953
@NotEmpty
5054
private String nodeJsChecksumUrl;
51-
private int httpClientConnectTimeout = 5000;
52-
private int httpClientSocketTimeout = 15000;
55+
56+
@Valid
57+
@NotNull
58+
private HttpClientConfiguration httpClient = new HttpClientConfiguration();
5359

5460
@JsonProperty
5561
public String getGroupId() {
5662
return this.groupId;
5763
}
5864

59-
@JsonProperty
60-
public void setGroupId(String groupId) {
61-
this.groupId = groupId;
62-
}
63-
6465
@JsonProperty
6566
public String getNodeJsArtifactId() {
6667
return this.nodeJsArtifactId;
6768
}
6869

69-
@JsonProperty
70-
public void setNodeJsArtifactId(String nodeJsArtifactId) {
71-
this.nodeJsArtifactId = nodeJsArtifactId;
72-
}
73-
7470
@JsonProperty
7571
public String getNpmArtifactId() {
7672
return this.npmArtifactId;
7773
}
7874

79-
@JsonProperty
80-
public void setNpmArtifactId(String npmArtifactId) {
81-
this.npmArtifactId = npmArtifactId;
82-
}
83-
8475
@JsonProperty
8576
public String getNodeJsBinariesRootUrl() {
8677
return this.nodeJsBinariesRootUrl;
8778
}
8879

89-
@JsonProperty
90-
public void setNodeJsBinariesRootUrl(String nodeJsBinariesRootUrl) {
91-
this.nodeJsBinariesRootUrl = nodeJsBinariesRootUrl;
92-
}
93-
9480
@JsonProperty
9581
public String getNodeJsBinariesUrl() {
9682
return this.nodeJsBinariesUrl;
9783
}
9884

99-
@JsonProperty
100-
public void setNodeJsBinariesUrl(String nodeJsBinariesUrl) {
101-
this.nodeJsBinariesUrl = nodeJsBinariesUrl;
102-
}
103-
10485
@JsonProperty
10586
public String getNodeJsBinariesUrlWindows() {
10687
return this.nodeJsBinariesUrlWindows;
10788
}
10889

109-
@JsonProperty
110-
public void setNodeJsBinariesUrlWindows(String nodeJsBinariesUrlWindows) {
111-
this.nodeJsBinariesUrlWindows = nodeJsBinariesUrlWindows;
112-
}
113-
11490
@JsonProperty
11591
public String getNodeJsBinariesUrlWindowsX86() {
11692
return this.nodeJsBinariesUrlWindowsX86;
11793
}
11894

119-
@JsonProperty
120-
public void setNodeJsBinariesUrlWindowsX86(String nodeJsBinariesUrlWindowsX86) {
121-
this.nodeJsBinariesUrlWindowsX86 = nodeJsBinariesUrlWindowsX86;
122-
}
123-
12495
@JsonProperty
12596
public String getNpmBinariesUrl() {
12697
return this.npmBinariesUrl;
12798
}
12899

129-
@JsonProperty
130-
public void setNpmBinariesUrl(String npmBinariesUrl) {
131-
this.npmBinariesUrl = npmBinariesUrl;
132-
}
133100
@JsonProperty
134101
public String getNodeJsChecksumUrl() {
135102
return this.nodeJsChecksumUrl;
136103
}
137104

138-
@JsonProperty
139-
public void setNodeJsChecksumUrl(String nodeJsChecksumUrl) {
140-
this.nodeJsChecksumUrl = nodeJsChecksumUrl;
141-
}
142-
143-
@JsonProperty
144-
public int getHttpClientConnectTimeout() {
145-
return this.httpClientConnectTimeout;
146-
}
147-
148-
@JsonProperty
149-
public void setHttpClientConnectTimeout(int httpClientConnectTimeout) {
150-
this.httpClientConnectTimeout = httpClientConnectTimeout;
151-
}
152-
153-
@JsonProperty
154-
public int getHttpClientSocketTimeout() {
155-
return this.httpClientSocketTimeout;
156-
}
157-
158-
@JsonProperty
159-
public void setHttpClientSocketTimeout(int httpClientSocketTimeout) {
160-
this.httpClientSocketTimeout = httpClientSocketTimeout;
105+
@JsonProperty("httpClient")
106+
public HttpClientConfiguration getHttpClient() {
107+
return httpClient;
161108
}
162109

163110
}

maven-nodejs-proxy/src/main/java/io/wcm/devops/maven/nodejsproxy/health/NodeJsDistHealthCheck.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package io.wcm.devops.maven.nodejsproxy.health;
2121

2222
import io.wcm.devops.maven.nodejsproxy.MavenProxyConfiguration;
23-
import io.wcm.devops.maven.nodejsproxy.resource.HttpClientBuilder;
2423

2524
import javax.servlet.http.HttpServletResponse;
2625

@@ -46,9 +45,9 @@ public class NodeJsDistHealthCheck extends HealthCheck {
4645
/**
4746
* @param config Configuration
4847
*/
49-
public NodeJsDistHealthCheck(MavenProxyConfiguration config) {
48+
public NodeJsDistHealthCheck(MavenProxyConfiguration config, CloseableHttpClient httpClient) {
5049
this.config = config;
51-
httpClient = HttpClientBuilder.build(config);
50+
this.httpClient = httpClient;
5251
}
5352

5453
@Override

maven-nodejs-proxy/src/main/java/io/wcm/devops/maven/nodejsproxy/resource/HttpClientBuilder.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

maven-nodejs-proxy/src/main/java/io/wcm/devops/maven/nodejsproxy/resource/MavenProxyResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public class MavenProxyResource {
5757
/**
5858
* @param config Configuration
5959
*/
60-
public MavenProxyResource(MavenProxyConfiguration config) {
60+
public MavenProxyResource(MavenProxyConfiguration config, CloseableHttpClient httpClient) {
6161
this.config = config;
62-
httpClient = HttpClientBuilder.build(config);
62+
this.httpClient = httpClient;
6363
}
6464

6565
/**

0 commit comments

Comments
 (0)