| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package net.sf.arestc.configuration; |
| 21 |
|
|
| 22 |
|
import java.util.List; |
| 23 |
|
|
| 24 |
|
import org.apache.commons.configuration.ConfigurationException; |
| 25 |
|
import org.apache.commons.configuration.XMLConfiguration; |
| 26 |
|
import org.apache.commons.httpclient.Credentials; |
| 27 |
|
import org.apache.commons.httpclient.HttpClient; |
| 28 |
|
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
| 29 |
|
import org.apache.commons.httpclient.auth.AuthScope; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@author |
| 37 |
|
|
|
|
|
| 91.8% |
Uncovered Elements: 4 (49) |
Complexity: 14 |
Complexity Density: 0.41 |
|
| 38 |
|
public class ClientConfigurationFactory { |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
private static final String HTTPCONFIGURATION_FILENAME = "httpconfiguration.xml"; |
| 42 |
|
|
| 43 |
|
private static final ClientConfigurationFactory _instance = new ClientConfigurationFactory(); |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@return |
| 49 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
4
|
public static ClientConfigurationFactory getInstance() {... |
| 51 |
4
|
return _instance; |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
private HttpClient localClient; |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
@param |
| 60 |
|
|
| 61 |
|
@throws |
| 62 |
|
|
| 63 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 64 |
3
|
public void configure(final HttpClient client)... |
| 65 |
|
throws ConfigurationException { |
| 66 |
3
|
if (null == localClient || !localClient.equals(client)) { |
| 67 |
3
|
final XMLConfiguration config = new XMLConfiguration( |
| 68 |
|
HTTPCONFIGURATION_FILENAME); |
| 69 |
3
|
control(config, client); |
| 70 |
3
|
localClient = client; |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
@param |
| 79 |
|
|
| 80 |
|
@param |
| 81 |
|
|
| 82 |
|
@throws |
| 83 |
|
|
| 84 |
|
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 85 |
2
|
public void configure(final HttpClient client, final String configFileName)... |
| 86 |
|
throws ConfigurationException { |
| 87 |
2
|
if (null == localClient || !localClient.equals(client)) { |
| 88 |
1
|
XMLConfiguration config; |
| 89 |
1
|
try { |
| 90 |
1
|
config = new XMLConfiguration(configFileName); |
| 91 |
0
|
control(config, client); |
| 92 |
|
} catch (final ConfigurationException e) { |
| 93 |
1
|
configure(client); |
| 94 |
|
} finally { |
| 95 |
1
|
config = null; |
| 96 |
1
|
localClient = client; |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
@param |
| 105 |
|
|
| 106 |
|
@param |
| 107 |
|
|
| 108 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 109 |
3
|
protected void configureHosts(final XMLConfiguration config,... |
| 110 |
|
final HttpClient client) { |
| 111 |
3
|
final List<String> hosts = config.getList("hosts.host.server"); |
| 112 |
6
|
for (int i = 0; i < hosts.size(); i++) { |
| 113 |
3
|
final String hostInstance = "hosts.host(" + i + ")."; |
| 114 |
3
|
final String username = config.getString(hostInstance + "username", |
| 115 |
|
"admin"); |
| 116 |
3
|
final String password = config.getString(hostInstance + "password", |
| 117 |
|
"admin1"); |
| 118 |
3
|
final String host = config.getString(hostInstance + "server", |
| 119 |
|
"localhost"); |
| 120 |
3
|
final int port = config.getInt(hostInstance + "port", 80); |
| 121 |
|
|
| 122 |
3
|
final Credentials defaultcreds = new UsernamePasswordCredentials( |
| 123 |
|
username, password); |
| 124 |
3
|
client.getState().setCredentials( |
| 125 |
|
new AuthScope(host, port, AuthScope.ANY_REALM), |
| 126 |
|
defaultcreds); |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
@param |
| 134 |
|
|
| 135 |
|
@param |
| 136 |
|
|
| 137 |
|
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 138 |
3
|
protected void configurePreemptive(final XMLConfiguration config,... |
| 139 |
|
final HttpClient client) { |
| 140 |
3
|
if (config.getBoolean("preemtive", false)) { |
| 141 |
0
|
client.getParams().setAuthenticationPreemptive(true); |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
@param |
| 149 |
|
|
| 150 |
|
@param |
| 151 |
|
|
| 152 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 153 |
3
|
protected void configureProxies(final XMLConfiguration config,... |
| 154 |
|
final HttpClient client) { |
| 155 |
|
|
| 156 |
3
|
final String proxyInstance = "proxy"; |
| 157 |
3
|
final String username = config.getString(proxyInstance + "username", |
| 158 |
|
"admin"); |
| 159 |
3
|
final String password = config.getString(proxyInstance + "password", |
| 160 |
|
"admin1"); |
| 161 |
3
|
final String host = config.getString(proxyInstance + "server", |
| 162 |
|
"localhost"); |
| 163 |
3
|
final int port = config.getInt(proxyInstance + "port", 80); |
| 164 |
|
|
| 165 |
3
|
final Credentials defaultcreds = new UsernamePasswordCredentials( |
| 166 |
|
username, password); |
| 167 |
3
|
client.getState().setProxyCredentials( |
| 168 |
|
new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds); |
| 169 |
|
|
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
@param |
| 176 |
|
|
| 177 |
|
@param |
| 178 |
|
|
| 179 |
|
@throws |
| 180 |
|
|
| 181 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 182 |
3
|
protected void control(final XMLConfiguration config,... |
| 183 |
|
final HttpClient client) throws ConfigurationException { |
| 184 |
|
|
| 185 |
3
|
configurePreemptive(config, client); |
| 186 |
3
|
configureHosts(config, client); |
| 187 |
3
|
configureProxies(config, client); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
} |