1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.apache;
20
21 import java.io.Closeable;
22 import java.util.concurrent.ConcurrentHashMap;
23 import java.util.concurrent.ConcurrentMap;
24
25 import org.apache.http.HttpHost;
26 import org.apache.http.auth.AuthScheme;
27 import org.apache.http.conn.HttpClientConnectionManager;
28 import org.eclipse.aether.RepositorySystemSession;
29 import org.eclipse.aether.repository.RemoteRepository;
30
31
32
33
34
35 final class LocalState implements Closeable {
36 private final GlobalState global;
37
38 private final HttpClientConnectionManager connMgr;
39
40 private final GlobalState.CompoundKey userTokenKey;
41
42 private volatile Object userToken;
43
44 private final GlobalState.CompoundKey expectContinueKey;
45
46 private volatile Boolean expectContinue;
47
48 private volatile Boolean webDav;
49
50 private final ConcurrentMap<HttpHost, AuthSchemePool> authSchemePools;
51
52 LocalState(RepositorySystemSession session, RemoteRepository repo, ConnMgrConfig connMgrConfig) {
53 global = GlobalState.get(session);
54 userToken = this;
55 if (global == null) {
56 connMgr = GlobalState.newConnectionManager(connMgrConfig);
57 userTokenKey = null;
58 expectContinueKey = null;
59 authSchemePools = new ConcurrentHashMap<>();
60 } else {
61 connMgr = global.getConnectionManager(connMgrConfig);
62 userTokenKey =
63 new GlobalState.CompoundKey(repo.getId(), repo.getUrl(), repo.getAuthentication(), repo.getProxy());
64 expectContinueKey = new GlobalState.CompoundKey(repo.getUrl(), repo.getProxy());
65 authSchemePools = global.getAuthSchemePools();
66 }
67 }
68
69 public HttpClientConnectionManager getConnectionManager() {
70 return connMgr;
71 }
72
73 public Object getUserToken() {
74 if (userToken == this) {
75 userToken = (global != null) ? global.getUserToken(userTokenKey) : null;
76 }
77 return userToken;
78 }
79
80 public void setUserToken(Object userToken) {
81 this.userToken = userToken;
82 if (global != null) {
83 global.setUserToken(userTokenKey, userToken);
84 }
85 }
86
87 public boolean isExpectContinue() {
88 if (expectContinue == null) {
89 expectContinue =
90 !Boolean.FALSE.equals((global != null) ? global.getExpectContinue(expectContinueKey) : null);
91 }
92 return expectContinue;
93 }
94
95 public void setExpectContinue(boolean enabled) {
96 expectContinue = enabled;
97 if (global != null) {
98 global.setExpectContinue(expectContinueKey, enabled);
99 }
100 }
101
102 public Boolean getWebDav() {
103 return webDav;
104 }
105
106 public void setWebDav(boolean webDav) {
107 this.webDav = webDav;
108 }
109
110 public AuthScheme getAuthScheme(HttpHost host) {
111 AuthSchemePool pool = authSchemePools.get(host);
112 if (pool != null) {
113 return pool.get();
114 }
115 return null;
116 }
117
118 public void setAuthScheme(HttpHost host, AuthScheme authScheme) {
119 AuthSchemePool pool = authSchemePools.get(host);
120 if (pool == null) {
121 AuthSchemePool p = new AuthSchemePool();
122 pool = authSchemePools.putIfAbsent(host, p);
123 if (pool == null) {
124 pool = p;
125 }
126 }
127 pool.put(authScheme);
128 }
129
130 @Override
131 public void close() {
132 if (global == null) {
133 connMgr.shutdown();
134 }
135 }
136 }