Skip to content

Commit

Permalink
Reshade httphost (#964)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rnorth authored Nov 7, 2018
1 parent a5ce244 commit 53e2657
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ subprojects {
relocate('META-INF/native/libnetty', 'META-INF/native/liborg-testcontainers-shaded-netty')

[
"org.apache.http",
"org.apache.commons.lang",
"org.apache.commons.io",
"org.apache.commons.codec",
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ shadowJar {
mergeServiceFiles()

exclude 'org/newsclub/**'
exclude 'org/apache/http/**'

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

dependencies {
include(dependency('org.apache.httpcomponents:.*'))
include(dependency('org.glassfish.*:.*'))
include(dependency('org.aopalliance.*:.*'))
include(dependency('javax.ws.rs:.*'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.testcontainers.elasticsearch;

import org.apache.http.HttpHost;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.utility.Base58;
Expand Down Expand Up @@ -56,7 +55,7 @@ public ElasticsearchContainer(String dockerImageName) {
.withStartupTimeout(Duration.ofMinutes(2)));
}

public HttpHost getHost() {
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
public String getHttpHostAddress() {
return getContainerIpAddress() + ":" + getMappedPort(ELASTICSEARCH_DEFAULT_PORT);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.testcontainers.elasticsearch;


import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
Expand Down Expand Up @@ -90,7 +91,7 @@ private RestClient getClient(ElasticsearchContainer container) {
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD));

client = RestClient.builder(container.getHost())
client = RestClient.builder(HttpHost.create(container.getHttpHostAddress()))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
.build();
}
Expand Down

0 comments on commit 53e2657

Please sign in to comment.