Skip to content

Commit

Permalink
[MRESOLVER-382] allow setting outgoing interface (#315)
Browse files Browse the repository at this point in the history
Make possible to set route per remote repository

---------

Co-authored-by: Tamas Cservenak <[email protected]>
https://issues.apache.org/jira/browse/MRESOLVER-382
  • Loading branch information
bmarwell authored Jul 19, 2023
1 parent d9d2370 commit a348787
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -98,6 +100,8 @@
*/
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 @@ -251,6 +255,7 @@ final class HttpTransporter extends AbstractTransporter {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(connectTimeout)
.setLocalAddress(getBindAddress(session, repository))
.setSocketTimeout(requestTimeout)
.build();

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

/**
* 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);
if (bindAddress == null) {
return null;
}
try {
return InetAddress.getByName(bindAddress);
} catch (UnknownHostException uhe) {
throw new IllegalArgumentException(
"Given bind address (" + bindAddress + ") cannot be resolved for remote repository " + repository,
uhe);
}
}

private static HttpHost toHost(Proxy proxy) {
HttpHost host = null;
if (proxy != null) {
Expand Down
1 change: 1 addition & 0 deletions src/site/markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +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 (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 HttpTransport creation failure. | `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 a348787

Please sign in to comment.