1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.jdk;
20
21 import java.net.InetAddress;
22 import java.net.UnknownHostException;
23 import java.net.http.HttpClient;
24
25 import org.eclipse.aether.ConfigurationProperties;
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.repository.RemoteRepository;
28 import org.eclipse.aether.util.ConfigUtils;
29
30
31
32
33
34
35 final class JdkHttpTransporterCustomizer {
36 private JdkHttpTransporterCustomizer() {}
37
38 static void customizeBuilder(
39 RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) {
40 InetAddress localAddress = getHttpLocalAddress(session, repository);
41 if (localAddress != null) {
42 builder.localAddress(localAddress);
43 }
44 }
45
46 static void customizeHttpClient(RepositorySystemSession session, RemoteRepository repository, HttpClient client) {}
47
48
49
50
51 private static InetAddress getHttpLocalAddress(RepositorySystemSession session, RemoteRepository repository) {
52 String bindAddress = ConfigUtils.getString(
53 session,
54 null,
55 ConfigurationProperties.HTTP_LOCAL_ADDRESS + "." + repository.getId(),
56 ConfigurationProperties.HTTP_LOCAL_ADDRESS);
57 if (bindAddress == null) {
58 return null;
59 }
60 try {
61 return InetAddress.getByName(bindAddress);
62 } catch (UnknownHostException uhe) {
63 throw new IllegalArgumentException(
64 "Given bind address (" + bindAddress + ") cannot be resolved for remote repository " + repository,
65 uhe);
66 }
67 }
68 }