1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.activeinstalls.internal.client.data; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
import javax.servlet.ServletContext; |
29 |
|
|
30 |
|
import org.apache.commons.lang.StringUtils; |
31 |
|
import org.apache.commons.lang.exception.ExceptionUtils; |
32 |
|
import org.slf4j.Logger; |
33 |
|
import org.xwiki.activeinstalls.internal.client.PingDataProvider; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
import org.xwiki.environment.Environment; |
36 |
|
import org.xwiki.environment.internal.ServletEnvironment; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@Named("servlet") |
46 |
|
@Singleton |
|
|
| 90.5% |
Uncovered Elements: 2 (21) |
Complexity: 4 |
Complexity Density: 0.24 |
|
47 |
|
public class ServletContainerPingDataProvider implements PingDataProvider |
48 |
|
{ |
49 |
|
private static final String SERVLET_INFO_VERSION_SEPARATOR = "/"; |
50 |
|
|
51 |
|
private static final String SERVLET_INFO_OPTIONALSEPARATOR = "("; |
52 |
|
|
53 |
|
private static final String PROPERTY_SERVLET_CONTAINER_NAME = "servletContainerName"; |
54 |
|
|
55 |
|
private static final String PROPERTY_SERVLET_CONTAINER_VERSION = "servletContainerVersion"; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@Inject |
61 |
|
private Environment environment; |
62 |
|
|
63 |
|
@Inject |
64 |
|
private Logger logger; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
66 |
2 |
@Override... |
67 |
|
public Map<String, Object> provideMapping() |
68 |
|
{ |
69 |
2 |
Map<String, Object> map = new HashMap<>(); |
70 |
2 |
map.put("type", "string"); |
71 |
2 |
map.put("index", "not_analyzed"); |
72 |
|
|
73 |
2 |
Map<String, Object> propertiesMap = new HashMap<>(); |
74 |
2 |
propertiesMap.put(PROPERTY_SERVLET_CONTAINER_NAME, map); |
75 |
2 |
propertiesMap.put(PROPERTY_SERVLET_CONTAINER_VERSION, map); |
76 |
|
|
77 |
2 |
return propertiesMap; |
78 |
|
} |
79 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
80 |
2 |
@Override... |
81 |
|
public Map<String, Object> provideData() |
82 |
|
{ |
83 |
2 |
Map<String, Object> jsonMap = new HashMap<>(); |
84 |
2 |
if (this.environment instanceof ServletEnvironment) { |
85 |
2 |
ServletEnvironment servletEnvironment = (ServletEnvironment) this.environment; |
86 |
2 |
try { |
87 |
2 |
ServletContext servletContext = servletEnvironment.getServletContext(); |
88 |
|
|
89 |
2 |
String serverInfo = servletContext.getServerInfo(); |
90 |
2 |
jsonMap.put(PROPERTY_SERVLET_CONTAINER_NAME, |
91 |
|
StringUtils.trim(StringUtils.substringBefore(serverInfo, SERVLET_INFO_VERSION_SEPARATOR))); |
92 |
2 |
jsonMap.put(PROPERTY_SERVLET_CONTAINER_VERSION, StringUtils.trim(StringUtils.substringBefore( |
93 |
|
StringUtils.substringAfter(serverInfo, SERVLET_INFO_VERSION_SEPARATOR), |
94 |
|
SERVLET_INFO_OPTIONALSEPARATOR))); |
95 |
|
} catch (Throwable e) { |
96 |
|
|
97 |
|
|
98 |
0 |
this.logger.warn("Failed to compute Servlet container information. " |
99 |
|
+ "This information has not been added to the Active Installs ping data. Reason [{}]", |
100 |
|
ExceptionUtils.getRootCauseMessage(e) |
101 |
|
); |
102 |
|
} |
103 |
|
} |
104 |
2 |
return jsonMap; |
105 |
|
} |
106 |
|
} |