Skip to content

Commit

Permalink
Make possible to set route per remote repository
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Jul 19, 2023
1 parent 259c6b4 commit 5759264
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
final class HttpTransporter extends AbstractTransporter {

static final String BIND_ADDRESS = "aether.connector.bind.address";

static final String SUPPORT_WEBDAV = "aether.connector.http.supportWebDav";

static final String PREEMPTIVE_PUT_AUTH = "aether.connector.http.preemptivePutAuth";
Expand Down Expand Up @@ -255,7 +256,7 @@ final class HttpTransporter extends AbstractTransporter {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(connectTimeout)
.setLocalAddress(getBindAddress(session))
.setLocalAddress(getBindAddress(session, repository))
.setSocketTimeout(requestTimeout)
.build();

Expand Down Expand Up @@ -300,17 +301,24 @@ final class HttpTransporter extends AbstractTransporter {
this.client = builder.build();
}

private InetAddress getBindAddress(RepositorySystemSession session) {
String bindAddress = ConfigUtils.getString(session, null, BIND_ADDRESS);
return Optional.ofNullable(bindAddress).map(this::resolveAddress).orElse(null);
}

private InetAddress resolveAddress(String bindAddress) {
try {
return InetAddress.getByName(bindAddress);
} catch (UnknownHostException uhe) {
throw new IllegalArgumentException("Given bind address (" + bindAddress + ") cannot be resolved.", uhe);
}
/**
* Returns non-null {@link InetAddress} if set in configuration, {@code null} otherwise.
*/
private InetAddress getBindAddress(RepositorySystemSession session, RemoteRepository repository) {
String bindAddress =
ConfigUtils.getString(session, null, BIND_ADDRESS + "." + repository.getId(), BIND_ADDRESS);
return Optional.ofNullable(bindAddress)
.map(a -> {
try {
return InetAddress.getByName(bindAddress);
} catch (UnknownHostException uhe) {
throw new IllegalArgumentException(
"Given bind address (" + bindAddress + ") cannot be resolved for remote repository "
+ repository,
uhe);
}
})
.orElse(null);
}

private static HttpHost toHost(Proxy proxy) {
Expand Down
2 changes: 1 addition & 1 deletion src/site/markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Option | Type | Description | Default Value | Supports Repo ID Suffix
`aether.connector.basic.parallelPut` | boolean | Enables or disables parallel PUT processing (parallel deploys) on basic connector globally or per remote repository. When disabled, connector behaves exactly as in Maven 3.8.x did: GETs are parallel while PUTs are sequential. | `true` | yes
`aether.connector.classpath.loader` | ClassLoader | `ClassLoader` from which resources should be retrieved which start with the `classpath:` protocol. | `Thread.currentThread().getContextClassLoader()` | no
`aether.connector.connectTimeout` | long | Connect timeout in milliseconds. | `10000` | yes
`aether.connector.http.bind.address` | String | Set the outgoing interface. Valid values are local accessible IP addresses or host names. The default will use the system's default route. Invalid addresses will result in a failing build. | `null` | no
`aether.connector.http.bind.address` | String | Set the outgoing interface (globally or per remote repository). Valid values are local accessible IP addresses or host names. The default will use the system's default route. Invalid addresses will result in a failing build. | `null` | yes
`aether.connector.http.cacheState` | boolean | Flag indicating whether a memory-based cache is used for user tokens, connection managers, expect continue requests and authentication schemes. | `true` | no
`aether.connector.http.connectionMaxTtl` | int | Time to live in seconds for an HTTP connection, after that time, the connection will be dropped. | `600` | yes
`aether.connector.http.credentialEncoding` | String | The encoding/charset to use when exchanging credentials with HTTP servers. | `"ISO-8859-1"` | yes
Expand Down

0 comments on commit 5759264

Please sign in to comment.