1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.web; |
35 |
|
|
36 |
|
import java.io.IOException; |
37 |
|
import javax.servlet.Servlet; |
38 |
|
import javax.servlet.ServletConfig; |
39 |
|
import javax.servlet.ServletException; |
40 |
|
import javax.servlet.ServletRequest; |
41 |
|
import javax.servlet.ServletResponse; |
42 |
|
import javax.servlet.http.HttpServlet; |
43 |
|
|
44 |
|
import info.magnolia.module.ModuleManager; |
45 |
|
import info.magnolia.module.blossom.support.CustomServletConfig; |
46 |
|
import info.magnolia.objectfactory.Components; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@since |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 12 |
Complexity Density: 0.43 |
|
59 |
|
public class InstallationAwareServletProxy extends HttpServlet { |
60 |
|
|
61 |
|
private static final String SERVLET_CLASS_PARAMETER = "servletClass"; |
62 |
|
|
63 |
|
private Servlet targetServlet; |
64 |
|
private boolean initialized = false; |
65 |
|
private final Object monitor = new Object(); |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
67 |
0 |
@Override... |
68 |
|
public void init(ServletConfig config) throws ServletException { |
69 |
0 |
super.init(config); |
70 |
0 |
synchronized (monitor) { |
71 |
0 |
if (canInitialize()) { |
72 |
0 |
targetServlet = initTargetServlet(); |
73 |
0 |
initialized = true; |
74 |
|
} |
75 |
|
} |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
78 |
0 |
@Override... |
79 |
|
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { |
80 |
0 |
synchronized (monitor) { |
81 |
0 |
if (!initialized) { |
82 |
|
|
83 |
|
|
84 |
0 |
if (canInitialize()) { |
85 |
0 |
targetServlet = initTargetServlet(); |
86 |
0 |
initialized = true; |
87 |
|
} else { |
88 |
0 |
return; |
89 |
|
} |
90 |
|
} |
91 |
|
} |
92 |
0 |
targetServlet.service(req, res); |
93 |
|
} |
94 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
95 |
0 |
@Override... |
96 |
|
public void destroy() { |
97 |
0 |
synchronized (monitor) { |
98 |
0 |
if (!initialized) { |
99 |
0 |
return; |
100 |
|
} |
101 |
|
} |
102 |
0 |
targetServlet.destroy(); |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.36 |
|
105 |
0 |
protected Servlet initTargetServlet() throws ServletException {... |
106 |
0 |
ServletConfig config = getServletConfig(); |
107 |
0 |
Servlet servlet; |
108 |
0 |
try { |
109 |
0 |
servlet = (Servlet) Class.forName(config.getInitParameter(SERVLET_CLASS_PARAMETER)).newInstance(); |
110 |
|
} catch (ClassNotFoundException e) { |
111 |
0 |
throw new ServletException(e); |
112 |
|
} catch (InstantiationException e) { |
113 |
0 |
throw new ServletException(e); |
114 |
|
} catch (IllegalAccessException e) { |
115 |
0 |
throw new ServletException(e); |
116 |
|
} |
117 |
0 |
CustomServletConfig customServletConfig = new CustomServletConfig(config); |
118 |
0 |
customServletConfig.removeInitParameter(SERVLET_CLASS_PARAMETER); |
119 |
0 |
servlet.init(customServletConfig); |
120 |
0 |
return servlet; |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
0 |
protected boolean canInitialize() {... |
124 |
|
|
125 |
0 |
return !Components.getComponent(ModuleManager.class).getStatus().needsUpdateOrInstall(); |
126 |
|
} |
127 |
|
} |