1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.List; |
24 |
|
import java.util.logging.Level; |
25 |
|
|
26 |
|
import javax.servlet.http.HttpServletRequest; |
27 |
|
|
28 |
|
import org.restlet.Request; |
29 |
|
import org.restlet.Response; |
30 |
|
import org.restlet.ext.servlet.ServletUtils; |
31 |
|
import org.restlet.routing.Filter; |
32 |
|
import org.xwiki.component.manager.ComponentLifecycleException; |
33 |
|
import org.xwiki.component.manager.ComponentManager; |
34 |
|
import org.xwiki.context.Execution; |
35 |
|
import org.xwiki.context.ExecutionContext; |
36 |
|
import org.xwiki.rest.XWikiRestComponent; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
|
|
|
| 81.5% |
Uncovered Elements: 5 (27) |
Complexity: 9 |
Complexity Density: 0.53 |
|
47 |
|
public class XWikiSetupCleanupFilter extends Filter |
48 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
49 |
1709 |
@Override... |
50 |
|
protected int beforeHandle(Request request, Response response) |
51 |
|
{ |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
1709 |
getContext().getAttributes().put(Constants.HTTP_REQUEST, getHttpRequest(request)); |
61 |
|
|
62 |
1709 |
return Filter.CONTINUE; |
63 |
|
} |
64 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
65 |
1709 |
@Override... |
66 |
|
protected void afterHandle(Request request, Response response) |
67 |
|
{ |
68 |
|
|
69 |
|
|
70 |
1709 |
ComponentManager componentManager = |
71 |
|
(ComponentManager) getApplication().getContext().getAttributes().get(Constants.XWIKI_COMPONENT_MANAGER); |
72 |
1709 |
for (XWikiRestComponent component : getReleasableComponents(componentManager)) { |
73 |
1562 |
try { |
74 |
1562 |
componentManager.release(component); |
75 |
|
} catch (ComponentLifecycleException e) { |
76 |
0 |
getLogger().log(Level.WARNING, "Unable to release component [{0}]. ({1})", |
77 |
|
new Object[] {component.getClass().getName(), e.getMessage()}); |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
1709 |
if (response.getEntity() != null) { |
83 |
1709 |
if (!response.getEntity().isAvailable()) { |
84 |
327 |
response.setEntity(null); |
85 |
|
} |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
@return |
92 |
|
|
93 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
94 |
1709 |
private List<XWikiRestComponent> getReleasableComponents(ComponentManager componentManager)... |
95 |
|
{ |
96 |
1709 |
try { |
97 |
1709 |
ExecutionContext executionContext = componentManager.<Execution> getInstance(Execution.class).getContext(); |
98 |
1709 |
@SuppressWarnings("unchecked") |
99 |
|
List<XWikiRestComponent> releasableComponents = |
100 |
|
(List<XWikiRestComponent>) executionContext.getProperty(Constants.RELEASABLE_COMPONENT_REFERENCES); |
101 |
1709 |
return releasableComponents != null ? releasableComponents : Collections.<XWikiRestComponent> emptyList(); |
102 |
|
} catch (Exception e) { |
103 |
0 |
getLogger().log(Level.WARNING, "Failed to retrieve the list of releasable components.", e); |
104 |
0 |
return Collections.emptyList(); |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
@return |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
1709 |
protected static HttpServletRequest getHttpRequest(Request req)... |
117 |
|
{ |
118 |
1709 |
return ServletUtils.getRequest(req); |
119 |
|
} |
120 |
|
|
121 |
|
} |