1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.http;
19
20 import org.apache.any23.configuration.DefaultConfiguration;
21
22
23
24
25
26
27 public class DefaultHTTPClientConfiguration implements HTTPClientConfiguration {
28
29 private static DefaultHTTPClientConfiguration instance;
30
31 public static DefaultHTTPClientConfiguration singleton() {
32 if (instance == null) {
33 instance = new DefaultHTTPClientConfiguration();
34 }
35 return instance;
36 }
37
38 private String userAgent;
39 private int defaultTimeout;
40 private int maxConnections;
41 private String acceptHeader;
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public DefaultHTTPClientConfiguration(String userAgent, int defaultTimeout, int maxConnections,
56 String acceptHeader) {
57 if (userAgent == null)
58 throw new IllegalArgumentException("userAgent cannot be null.");
59 if (defaultTimeout <= 0)
60 throw new IllegalArgumentException("defaultTimeout cannot be <= 0 .");
61 if (maxConnections <= 0)
62 throw new IllegalArgumentException("maxConnections cannot be <= 0 .");
63 this.userAgent = userAgent;
64 this.defaultTimeout = defaultTimeout;
65 this.maxConnections = maxConnections;
66 this.acceptHeader = acceptHeader;
67 }
68
69
70
71
72
73
74
75 public DefaultHTTPClientConfiguration(String acceptHeader) {
76 this(DefaultConfiguration.singleton().getPropertyOrFail("any23.http.user.agent.default"),
77 DefaultConfiguration.singleton().getPropertyIntOrFail("any23.http.client.timeout"),
78 DefaultConfiguration.singleton().getPropertyIntOrFail("any23.http.client.max.connections"),
79 acceptHeader);
80 }
81
82
83
84
85 public DefaultHTTPClientConfiguration() {
86 this(null);
87 }
88
89 public String getUserAgent() {
90 return userAgent;
91 }
92
93 public int getDefaultTimeout() {
94 return defaultTimeout;
95 }
96
97 public int getMaxConnections() {
98 return maxConnections;
99 }
100
101 public String getAcceptHeader() {
102 return acceptHeader;
103 }
104
105 }