1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.rice.test.lifecycles; |
17 |
|
|
18 |
|
import java.net.BindException; |
19 |
|
import java.util.HashMap; |
20 |
|
|
21 |
|
import org.apache.log4j.Logger; |
22 |
|
import org.kuali.rice.core.api.config.property.Config; |
23 |
|
import org.kuali.rice.core.api.config.property.ConfigContext; |
24 |
|
import org.kuali.rice.core.api.lifecycle.Lifecycle; |
25 |
|
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
26 |
|
import org.kuali.rice.core.api.resourceloader.ResourceLoader; |
27 |
|
import org.kuali.rice.core.util.RiceUtilities; |
28 |
|
import org.kuali.rice.core.web.jetty.JettyServer; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@author |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 70 (70) |
Complexity: 24 |
Complexity Density: 0.57 |
|
35 |
|
public class JettyServerLifecycle implements Lifecycle { |
36 |
|
private static final Logger LOG = Logger.getLogger(JettyServerLifecycle.class); |
37 |
|
|
38 |
|
private static final HashMap<Integer, Config> WEBAPP_CONFIGS = new HashMap<Integer, Config>(); |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
0
|
public static Config getWebappConfig(int port) {... |
41 |
0
|
return WEBAPP_CONFIGS.get(port); |
42 |
|
} |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
47 |
|
public static enum ConfigMode { |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
NONE, |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
OVERRIDE, |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
MERGE |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
private boolean testMode = true; |
66 |
|
private boolean started; |
67 |
|
private ConfigMode configMode = ConfigMode.OVERRIDE; |
68 |
|
private boolean addWebappResourceLoaders = true; |
69 |
|
|
70 |
|
|
71 |
|
protected JettyServer jettyServer; |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
0
|
public JettyServerLifecycle() {... |
74 |
0
|
this(8080, null); |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0
|
public JettyServerLifecycle(int port) {... |
78 |
0
|
this(port, null, null); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0
|
public JettyServerLifecycle(int port, String contextName) {... |
82 |
0
|
this(port, contextName, null); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
85 |
0
|
public JettyServerLifecycle(int port, String contextName, String relativeWebappRoot) {... |
86 |
0
|
jettyServer = new JettyServer(port, contextName, relativeWebappRoot); |
87 |
0
|
jettyServer.setFailOnContextFailure(true); |
88 |
0
|
jettyServer.setTestMode(testMode); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0
|
public void setTestMode(boolean t) {... |
92 |
0
|
this.testMode = t; |
93 |
|
} |
94 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
0
|
public boolean isTestMode() {... |
96 |
0
|
return testMode; |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0
|
public ConfigMode getConfigMode() {... |
100 |
0
|
return this.configMode; |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
0
|
public void setConfigMode(ConfigMode configMode) {... |
104 |
0
|
this.configMode = configMode; |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0
|
public boolean isAddWebappResourceLoaders() {... |
108 |
0
|
return this.addWebappResourceLoaders; |
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0
|
public void setAddWebappResourceLoaders(boolean addWebappResourceLoaders) {... |
112 |
0
|
this.addWebappResourceLoaders = addWebappResourceLoaders; |
113 |
|
} |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
115 |
0
|
public boolean isStarted() {... |
116 |
0
|
return started; |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 8 |
Complexity Density: 0.38 |
|
119 |
0
|
public void start() throws Exception {... |
120 |
0
|
try { |
121 |
0
|
jettyServer.start(); |
122 |
|
|
123 |
|
} catch (RuntimeException re) { |
124 |
|
|
125 |
0
|
if (RiceUtilities.findExceptionInStack(re, BindException.class) != null) { |
126 |
0
|
LOG.error("JettyServerLifecycle encountered BindException on port: " + jettyServer.getPort() + "; check logs for test failures or and the config for duplicate port specifications."); |
127 |
|
} |
128 |
0
|
throw re; |
129 |
|
} |
130 |
|
|
131 |
0
|
ClassLoader webappClassLoader = jettyServer.getContext().getClassLoader(); |
132 |
0
|
if (addWebappResourceLoaders) { |
133 |
0
|
ResourceLoader rl = GlobalResourceLoader.getResourceLoader(webappClassLoader); |
134 |
0
|
if (rl == null) { |
135 |
0
|
throw new RuntimeException("Could not find resource loader for workflow test harness web app for: " + webappClassLoader); |
136 |
|
} |
137 |
0
|
GlobalResourceLoader.addResourceLoader(rl); |
138 |
|
} |
139 |
0
|
Config webappConfig = ConfigContext.getConfig(webappClassLoader); |
140 |
0
|
WEBAPP_CONFIGS.put(jettyServer.getPort(), webappConfig); |
141 |
0
|
if (ConfigMode.OVERRIDE == configMode) { |
142 |
|
|
143 |
0
|
ConfigContext.overrideConfig(Thread.currentThread().getContextClassLoader(), webappConfig); |
144 |
0
|
} else if (ConfigMode.MERGE == configMode) { |
145 |
0
|
Config curCtxConfig = ConfigContext.getCurrentContextConfig(); |
146 |
0
|
if (webappConfig != null) { |
147 |
0
|
curCtxConfig.putProperties(webappConfig.getProperties()); |
148 |
0
|
curCtxConfig.putObjects(webappConfig.getObjects()); |
149 |
|
} |
150 |
|
} |
151 |
|
|
152 |
0
|
started = true; |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
155 |
0
|
public void stop() throws Exception {... |
156 |
0
|
LOG.info("Shutting down jetty: " + jettyServer); |
157 |
0
|
try { |
158 |
0
|
if (jettyServer != null && jettyServer.isStarted()) { |
159 |
0
|
jettyServer.stop(); |
160 |
0
|
WEBAPP_CONFIGS.remove(jettyServer.getPort()); |
161 |
|
} |
162 |
|
} catch (Exception e) { |
163 |
0
|
LOG.error("Error shutting down Jetty " + jettyServer.getContextName() + " " + jettyServer.getRelativeWebappRoot(), e); |
164 |
|
} |
165 |
0
|
started = false; |
166 |
|
} |
167 |
|
} |