| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package net.sf.arestc.core.services; |
| 20 |
|
|
| 21 |
|
import java.net.MalformedURLException; |
| 22 |
|
import java.net.URL; |
| 23 |
|
import java.util.Collection; |
| 24 |
|
import java.util.EnumMap; |
| 25 |
|
import java.util.HashSet; |
| 26 |
|
import java.util.Iterator; |
| 27 |
|
import java.util.Map; |
| 28 |
|
|
| 29 |
|
import org.apache.commons.collections.CollectionUtils; |
| 30 |
|
import org.apache.commons.configuration.ConfigurationException; |
| 31 |
|
import org.apache.commons.httpclient.Credentials; |
| 32 |
|
import org.apache.log4j.Logger; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@author |
| 39 |
|
|
|
|
|
| 96.1% |
Uncovered Elements: 2 (51) |
Complexity: 17 |
Complexity Density: 0.52 |
|
| 40 |
|
public class BaseService implements RESTService { |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
private static final Logger LOGGER = Logger.getLogger(BaseService.class |
| 44 |
|
.getName()); |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
private final String name; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
private final EnumMap<ServiceParameterTypes, Collection<String>> serviceParameters; |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
private final ServiceConnectionData connectionData; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
private final ServiceAuthenticationData authenticationData; |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
private final ServiceConnectorData connectorData; |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
@param |
| 65 |
|
@param |
| 66 |
|
@param |
| 67 |
|
@param |
| 68 |
|
@param |
| 69 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 70 |
280
|
public BaseService(final String name,... |
| 71 |
|
final EnumMap<ServiceParameterTypes, Collection<String>> inParams, |
| 72 |
|
final ServiceConnectionData connectionData, |
| 73 |
|
final ServiceAuthenticationData authenticationData, |
| 74 |
|
final ServiceConnectorData connectorData) { |
| 75 |
280
|
this.name = name; |
| 76 |
|
|
| 77 |
280
|
serviceParameters = inParams; |
| 78 |
280
|
this.connectionData = connectionData; |
| 79 |
280
|
this.authenticationData = authenticationData; |
| 80 |
280
|
this.connectorData = connectorData; |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
@see |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 90 |
1
|
public Object addParameter(final String key,... |
| 91 |
|
final ServiceParameterTypes value) { |
| 92 |
1
|
return serviceParameters.get(value).add(key); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
@return |
| 99 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 100 |
23
|
public Credentials getAdminCredentials() {... |
| 101 |
23
|
return authenticationData.getAdminCredentials(); |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
@return |
| 108 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 109 |
66
|
public String getAuthenticatingUser() {... |
| 110 |
66
|
return authenticationData.getAuthenticatingUser(); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
@see |
| 117 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 118 |
2
|
public String getContentType() {... |
| 119 |
2
|
return connectorData.getContentType(); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
@see |
| 126 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
3
|
public String getContextPath() {... |
| 128 |
3
|
return connectionData.getContextPath(); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
@see |
| 135 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 136 |
40
|
public HTTPMethods getMethod() {... |
| 137 |
40
|
return connectionData.getMethod(); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
@see |
| 144 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 145 |
269
|
public String getName() {... |
| 146 |
269
|
return name; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
@see |
| 153 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 154 |
5
|
public EnumMap<ServiceParameterTypes, Collection<String>> getParameters() {... |
| 155 |
5
|
return serviceParameters; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
@return |
| 162 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 163 |
10
|
public ReturnedTypes getReturnedType() {... |
| 164 |
10
|
return connectorData.getReturnedType(); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
@see |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 174 |
30
|
public URL getServiceURL(final Map<String, Object> params)... |
| 175 |
|
throws ConfigurationException { |
| 176 |
|
|
| 177 |
30
|
URL ret = null; |
| 178 |
30
|
try { |
| 179 |
30
|
String path = connectionData.getRealPath(); |
| 180 |
30
|
final Collection<String> urlParameters = serviceParameters |
| 181 |
|
.get(ServiceParameterTypes.URL); |
| 182 |
30
|
final Iterator<String> nameIter = CollectionUtils.intersection( |
| 183 |
|
params.keySet(), urlParameters).iterator(); |
| 184 |
75
|
while (nameIter.hasNext()) { |
| 185 |
45
|
final String name = nameIter.next(); |
| 186 |
45
|
path = path.replaceAll("\\{" + name + "\\}", |
| 187 |
|
(String) params.get(name)); |
| 188 |
|
} |
| 189 |
30
|
ret = new URL(path); |
| 190 |
|
} catch (final MalformedURLException e) { |
| 191 |
0
|
LOGGER.error("Malformed service url:", e); |
| 192 |
0
|
throw new ConfigurationException(e); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
30
|
return ret; |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
@see |
| 200 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 201 |
16
|
public Collection<String> getUnionOfParameters() {... |
| 202 |
16
|
Collection<String> union = new HashSet<String>(); |
| 203 |
16
|
for (final ServiceParameterTypes type : ServiceParameterTypes.values()) { |
| 204 |
48
|
if (null != serviceParameters.get(type)) { |
| 205 |
36
|
union = CollectionUtils.union(union, |
| 206 |
|
serviceParameters.get(type)); |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
16
|
return union; |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
@see |
| 216 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 217 |
14
|
public Collection<String> getURLParameters() {... |
| 218 |
14
|
return serviceParameters.get(ServiceParameterTypes.URL); |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
@see |
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 228 |
31
|
public boolean isAuthenticationRequired() {... |
| 229 |
31
|
return authenticationData.isAuthenticationRequired(); |
| 230 |
|
} |
| 231 |
|
|
| 232 |
|
} |