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.io.InputStream; |
23 |
|
import java.util.logging.LogManager; |
24 |
|
|
25 |
|
import javax.servlet.ServletException; |
26 |
|
|
27 |
|
import org.apache.commons.io.IOUtils; |
28 |
|
import org.restlet.Application; |
29 |
|
import org.restlet.Context; |
30 |
|
import org.xwiki.component.manager.ComponentLookupException; |
31 |
|
import org.xwiki.component.manager.ComponentManager; |
32 |
|
import org.xwiki.rest.internal.Constants; |
33 |
|
|
34 |
|
import org.restlet.ext.servlet.ServerServlet; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@version |
51 |
|
|
|
|
| 84.4% |
Uncovered Elements: 5 (32) |
Complexity: 8 |
Complexity Density: 0.35 |
|
52 |
|
public class XWikiRestletServlet extends ServerServlet |
53 |
|
{ |
54 |
|
private static final String JAVA_LOGGING_PROPERTY_FILE = "java-logging.properties"; |
55 |
|
|
56 |
|
private static final long serialVersionUID = 9148448182654390153L; |
57 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
58 |
18 |
@Override... |
59 |
|
protected Application createApplication(Context context) |
60 |
|
{ |
61 |
18 |
Application application = super.createApplication(context); |
62 |
|
|
63 |
|
|
64 |
18 |
Context applicationContext = application.getContext(); |
65 |
|
|
66 |
|
|
67 |
18 |
ComponentManager componentManager = getComponentManager(context); |
68 |
18 |
applicationContext.getAttributes().put(Constants.XWIKI_COMPONENT_MANAGER, componentManager); |
69 |
|
|
70 |
|
|
71 |
18 |
if (application instanceof XWikiRestletJaxRsApplication) { |
72 |
18 |
XWikiRestletJaxRsApplication jaxrsApplication = (XWikiRestletJaxRsApplication) application; |
73 |
18 |
jaxrsApplication.setObjectFactory(new ComponentsObjectFactory(componentManager)); |
74 |
|
} else { |
75 |
0 |
log("The Restlet application is not an instance of XWikiRestletJaxRsApplication. Please check your web.xml"); |
76 |
|
} |
77 |
|
|
78 |
18 |
return application; |
79 |
|
} |
80 |
|
|
|
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
81 |
18 |
@Override... |
82 |
|
public void init() throws ServletException |
83 |
|
{ |
84 |
18 |
super.init(); |
85 |
|
|
86 |
18 |
try { |
87 |
|
|
88 |
18 |
InputStream is = |
89 |
|
getServletContext().getResourceAsStream(String.format("/WEB-INF/%s", JAVA_LOGGING_PROPERTY_FILE)); |
90 |
|
|
91 |
|
|
92 |
18 |
if (is == null) { |
93 |
18 |
is = getClass().getClassLoader().getResourceAsStream(JAVA_LOGGING_PROPERTY_FILE); |
94 |
|
} |
95 |
|
|
96 |
18 |
if (is != null) { |
97 |
18 |
try { |
98 |
18 |
LogManager.getLogManager().readConfiguration(is); |
99 |
|
} finally { |
100 |
18 |
IOUtils.closeQuietly(is); |
101 |
|
} |
102 |
|
} |
103 |
|
} catch (Exception e) { |
104 |
0 |
log("Unable to initialize Java logging framework. Using defaults", e); |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
@return |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
116 |
18 |
private ComponentManager getComponentManager(Context context)... |
117 |
|
{ |
118 |
18 |
ComponentManager result = |
119 |
|
(ComponentManager) getServletContext().getAttribute("org.xwiki.component.manager.ComponentManager"); |
120 |
18 |
try { |
121 |
18 |
result = result.getInstance(ComponentManager.class, "context"); |
122 |
|
} catch (ComponentLookupException e) { |
123 |
|
|
124 |
|
} |
125 |
18 |
return result; |
126 |
|
} |
127 |
|
} |