1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.http;
18
19 import java.time.Duration;
20
21 import org.apache.commons.httpclient.Cookie;
22 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
23 import org.apache.commons.httpclient.params.HttpConnectionParams;
24 import org.apache.commons.vfs2.FileSystem;
25 import org.apache.commons.vfs2.FileSystemConfigBuilder;
26 import org.apache.commons.vfs2.FileSystemOptions;
27 import org.apache.commons.vfs2.UserAuthenticator;
28
29
30
31
32
33
34 @Deprecated
35 public class HttpFileSystemConfigBuilder extends FileSystemConfigBuilder {
36
37
38
39
40 protected static final String KEY_FOLLOW_REDIRECT = "followRedirect";
41
42
43
44
45 protected static final String KEY_USER_AGENT = "userAgent";
46
47 private static final HttpFileSystemConfigBuilder BUILDER = new HttpFileSystemConfigBuilder();
48
49 private static final int DEFAULT_MAX_HOST_CONNECTIONS = 5;
50
51 private static final int DEFAULT_MAX_CONNECTIONS = 50;
52
53 private static final Duration DEFAULT_CONNECTION_TIMEOUT = Duration.ZERO;
54
55 private static final Duration DEFAULT_SO_TIMEOUT = Duration.ZERO;
56
57 private static final boolean DEFAULT_FOLLOW_REDIRECT = true;
58
59 private static final String DEFAULT_USER_AGENT = "Jakarta-Commons-VFS";
60
61 private static final String KEY_PREEMPTIVE_AUTHENTICATION = "preemptiveAuth";
62
63
64
65
66
67
68 public static HttpFileSystemConfigBuilder getInstance() {
69 return BUILDER;
70 }
71
72 private HttpFileSystemConfigBuilder() {
73 super("http.");
74 }
75
76
77
78
79
80
81
82 protected HttpFileSystemConfigBuilder(final String prefix) {
83 super(prefix);
84 }
85
86 @Override
87 protected Class<? extends FileSystem> getConfigClass() {
88 return HttpFileSystem.class;
89 }
90
91
92
93
94
95
96
97
98
99 @Deprecated
100 public int getConnectionTimeout(final FileSystemOptions opts) {
101 return getDurationInteger(opts, HttpConnectionParams.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
102 }
103
104
105
106
107
108
109
110
111 public Duration getConnectionTimeoutDuration(final FileSystemOptions opts) {
112 return getDuration(opts, HttpConnectionParams.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
113 }
114
115
116
117
118
119
120
121 public Cookie[] getCookies(final FileSystemOptions opts) {
122 return getParam(opts, "cookies");
123 }
124
125
126
127
128
129
130
131
132
133 public boolean getFollowRedirect(final FileSystemOptions opts) {
134 return getBoolean(opts, KEY_FOLLOW_REDIRECT, DEFAULT_FOLLOW_REDIRECT);
135 }
136
137
138
139
140
141
142
143
144 public int getMaxConnectionsPerHost(final FileSystemOptions opts) {
145 return getInteger(opts, HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, DEFAULT_MAX_HOST_CONNECTIONS);
146 }
147
148
149
150
151
152
153
154
155 public int getMaxTotalConnections(final FileSystemOptions opts) {
156 return getInteger(opts, HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_CONNECTIONS);
157 }
158
159
160
161
162
163
164
165 public UserAuthenticator getProxyAuthenticator(final FileSystemOptions opts) {
166 return getParam(opts, "proxyAuthenticator");
167 }
168
169
170
171
172
173
174
175
176
177 public String getProxyHost(final FileSystemOptions opts) {
178 return getString(opts, "proxyHost");
179 }
180
181
182
183
184
185
186
187
188
189 public int getProxyPort(final FileSystemOptions opts) {
190 return getInteger(opts, "proxyPort", 0);
191 }
192
193
194
195
196
197
198
199
200
201 @Deprecated
202 public int getSoTimeout(final FileSystemOptions opts) {
203 return getDurationInteger(opts, HttpConnectionParams.SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
204 }
205
206
207
208
209
210
211
212
213 public Duration getSoTimeoutDuration(final FileSystemOptions opts) {
214 return getDuration(opts, HttpConnectionParams.SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
215 }
216
217
218
219
220
221
222
223 public String getUrlCharset(final FileSystemOptions opts) {
224 return getString(opts, "urlCharset");
225 }
226
227
228
229
230
231
232
233 public String getUserAgent(final FileSystemOptions opts) {
234 final String userAgent = getParam(opts, KEY_USER_AGENT);
235 return userAgent != null ? userAgent : DEFAULT_USER_AGENT;
236 }
237
238
239
240
241
242
243
244
245 public boolean isPreemptiveAuth(final FileSystemOptions opts) {
246 return getBoolean(opts, KEY_PREEMPTIVE_AUTHENTICATION, Boolean.FALSE).booleanValue();
247 }
248
249
250
251
252
253
254
255
256 public void setConnectionTimeout(final FileSystemOptions opts, final Duration timeout) {
257 setParam(opts, HttpConnectionParams.CONNECTION_TIMEOUT, timeout);
258 }
259
260
261
262
263
264
265
266
267
268 @Deprecated
269 public void setConnectionTimeout(final FileSystemOptions opts, final int timeout) {
270 setConnectionTimeout(opts, Duration.ofMillis(timeout));
271 }
272
273
274
275
276
277
278
279 public void setCookies(final FileSystemOptions opts, final Cookie[] cookies) {
280 setParam(opts, "cookies", cookies);
281 }
282
283
284
285
286
287
288
289
290
291 public void setFollowRedirect(final FileSystemOptions opts, final boolean redirect) {
292 setParam(opts, KEY_FOLLOW_REDIRECT, redirect);
293 }
294
295
296
297
298
299
300
301
302 public void setMaxConnectionsPerHost(final FileSystemOptions opts, final int maxHostConnections) {
303 setParam(opts, HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, Integer.valueOf(maxHostConnections));
304 }
305
306
307
308
309
310
311
312
313 public void setMaxTotalConnections(final FileSystemOptions opts, final int maxTotalConnections) {
314 setParam(opts, HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, Integer.valueOf(maxTotalConnections));
315 }
316
317
318
319
320
321
322
323
324
325 public void setPreemptiveAuth(final FileSystemOptions opts, final boolean preemptiveAuth) {
326 setParam(opts, KEY_PREEMPTIVE_AUTHENTICATION, Boolean.valueOf(preemptiveAuth));
327 }
328
329
330
331
332
333
334
335 public void setProxyAuthenticator(final FileSystemOptions opts, final UserAuthenticator authenticator) {
336 setParam(opts, "proxyAuthenticator", authenticator);
337 }
338
339
340
341
342
343
344
345
346
347
348
349 public void setProxyHost(final FileSystemOptions opts, final String proxyHost) {
350 setParam(opts, "proxyHost", proxyHost);
351 }
352
353
354
355
356
357
358
359
360
361 public void setProxyPort(final FileSystemOptions opts, final int proxyPort) {
362 setParam(opts, "proxyPort", Integer.valueOf(proxyPort));
363 }
364
365
366
367
368
369
370
371
372 public void setSoTimeout(final FileSystemOptions opts, final Duration timeout) {
373 setParam(opts, HttpConnectionParams.SO_TIMEOUT, timeout);
374 }
375
376
377
378
379
380
381
382
383
384 @Deprecated
385 public void setSoTimeout(final FileSystemOptions opts, final int timeout) {
386 setSoTimeout(opts, Duration.ofMillis(timeout));
387 }
388
389
390
391
392
393
394
395 public void setUrlCharset(final FileSystemOptions opts, final String charset) {
396 setParam(opts, "urlCharset", charset);
397 }
398
399
400
401
402
403
404
405 public void setUserAgent(final FileSystemOptions opts, final String userAgent) {
406 setParam(opts, "userAgent", userAgent);
407 }
408 }