Skip to content

Commit 53e2657

Browse files
authored
Reshade httphost (#964)
FYI @dadoonet, relating to #958 As httpcore is a transitive dependency that we don't want to conflict with user's libs, we unfortunately need to: * roll back #959, where we disabled the shading of this module. As is, we're at risk of internal breakage when transitive deps clash. * in turn, stop exposing `HttpHost` in our public API. We should take a general stance of keeping our public APIs free of transitive deps (especially shaded ones) The API method in ElasticsearchContainer will thus change, from: ```java public HttpHost getHost() ``` to: ```java public String getHttpHostAddress() ``` Usage in turn changes from: ```java RestClient client = RestClient.builder(container.getHost()).build(); ``` to the slightly more verbose but equivalent: ```java RestClient client = RestClient.builder(HttpHost.create(container.getHttpHostAddress())).build(); ``` @bsideup, @kiview and I have discussed at length and concluded that this is the only approach that we're comfortable with - despite the fact that this raises an unfortunate breaking change in the API of the Elasticsearch module, which we reluctantly have to do. We are sorry that we did not catch this particular issue at PR stage - we're going to upgrade our static analysis to guard against inadvertent leakage of shaded dependencies. In the longer term we also, obviously, wish to reduce the weight of our dependency chain, both unshaded and shaded, so that this does not happen again. We intend for this change to go out as 1.10.1. I hope this is OK with you @dadoonet - our apologies again for not catching this before release.
1 parent a5ce244 commit 53e2657

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ subprojects {
5959
relocate('META-INF/native/libnetty', 'META-INF/native/liborg-testcontainers-shaded-netty')
6060

6161
[
62+
"org.apache.http",
6263
"org.apache.commons.lang",
6364
"org.apache.commons.io",
6465
"org.apache.commons.codec",

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ shadowJar {
1919
mergeServiceFiles()
2020

2121
exclude 'org/newsclub/**'
22-
exclude 'org/apache/http/**'
2322

2423
[
2524
'META-INF/io.netty.versions.properties',
@@ -41,6 +40,7 @@ shadowJar {
4140
].each { exclude(it) }
4241

4342
dependencies {
43+
include(dependency('org.apache.httpcomponents:.*'))
4444
include(dependency('org.glassfish.*:.*'))
4545
include(dependency('org.aopalliance.*:.*'))
4646
include(dependency('javax.ws.rs:.*'))

modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/ElasticsearchContainer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.testcontainers.elasticsearch;
22

3-
import org.apache.http.HttpHost;
43
import org.testcontainers.containers.GenericContainer;
54
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
65
import org.testcontainers.utility.Base58;
@@ -56,7 +55,7 @@ public ElasticsearchContainer(String dockerImageName) {
5655
.withStartupTimeout(Duration.ofMinutes(2)));
5756
}
5857

59-
public HttpHost getHost() {
60-
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
58+
public String getHttpHostAddress() {
59+
return getContainerIpAddress() + ":" + getMappedPort(ELASTICSEARCH_DEFAULT_PORT);
6160
}
6261
}

modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.testcontainers.elasticsearch;
22

33

4+
import org.apache.http.HttpHost;
45
import org.apache.http.auth.AuthScope;
56
import org.apache.http.auth.UsernamePasswordCredentials;
67
import org.apache.http.client.CredentialsProvider;
@@ -90,7 +91,7 @@ private RestClient getClient(ElasticsearchContainer container) {
9091
credentialsProvider.setCredentials(AuthScope.ANY,
9192
new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD));
9293

93-
client = RestClient.builder(container.getHost())
94+
client = RestClient.builder(HttpHost.create(container.getHttpHostAddress()))
9495
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
9596
.build();
9697
}

0 commit comments

Comments
 (0)