1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.engine; |
18 |
|
|
19 |
|
import java.text.DateFormat; |
20 |
|
import java.util.Date; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import javax.servlet.ServletConfig; |
24 |
|
|
25 |
|
import org.apache.commons.configuration.Configuration; |
26 |
|
import org.apache.commons.logging.Log; |
27 |
|
import org.apache.commons.logging.LogFactory; |
28 |
|
import org.apache.jetspeed.JetspeedPortalContext; |
29 |
|
import org.apache.jetspeed.PortalContext; |
30 |
|
import org.apache.jetspeed.PortalReservedParameters; |
31 |
|
import org.apache.jetspeed.administration.PortalConfiguration; |
32 |
|
import org.apache.jetspeed.administration.PortalConfigurationImpl; |
33 |
|
import org.apache.jetspeed.components.ComponentManager; |
34 |
|
import org.apache.jetspeed.exception.JetspeedException; |
35 |
|
import org.apache.jetspeed.pipeline.Pipeline; |
36 |
|
import org.apache.jetspeed.request.RequestContext; |
37 |
|
import org.apache.jetspeed.request.RequestContextComponent; |
38 |
|
import org.apache.jetspeed.statistics.PortalStatistics; |
39 |
|
import org.apache.ojb.broker.util.ClassHelper; |
40 |
|
import org.apache.pluto.PortletContainer; |
41 |
|
import org.apache.pluto.PortletContainerException; |
42 |
|
import org.apache.pluto.factory.Factory; |
43 |
|
import org.apache.pluto.services.ContainerService; |
44 |
|
import org.apache.pluto.services.factory.FactoryManagerService; |
45 |
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
public class JetspeedEngine implements Engine |
61 |
|
{ |
62 |
|
private final PortalContext context; |
63 |
|
private final ServletConfig config; |
64 |
|
private final ComponentManager componentManager; |
65 |
|
private Map pipelineMapper ; |
66 |
|
private PortalStatistics statistics; |
67 |
|
|
68 |
0 |
protected static final Log log = LogFactory.getLog(JetspeedEngine.class); |
69 |
|
protected String defaultPipelineName; |
70 |
|
|
71 |
|
public JetspeedEngine(Configuration configuration, String applicationRoot, ServletConfig config, ComponentManager componentManager ) |
72 |
|
{ |
73 |
0 |
this(new PortalConfigurationImpl(configuration), applicationRoot, config, componentManager); |
74 |
0 |
} |
75 |
|
|
76 |
|
public JetspeedEngine(PortalConfiguration configuration, String applicationRoot, ServletConfig config, ComponentManager componentManager ) |
77 |
0 |
{ |
78 |
0 |
this.componentManager = componentManager; |
79 |
0 |
this.context = new JetspeedPortalContext(class="keyword">this, configuration, applicationRoot); |
80 |
0 |
this.config = config; |
81 |
0 |
context.setApplicationRoot(applicationRoot); |
82 |
0 |
context.setConfiguration(configuration); |
83 |
|
|
84 |
0 |
defaultPipelineName = configuration.getString(PIPELINE_DEFAULT, "jetspeed-pipeline"); |
85 |
0 |
configuration.setString(JetspeedEngineConstants.APPLICATION_ROOT_KEY, applicationRoot); |
86 |
|
|
87 |
|
|
88 |
0 |
componentManager.addComponent("Engine", this); |
89 |
0 |
componentManager.addComponent("PortalContext", context); |
90 |
0 |
componentManager.addComponent("PortalConfiguration", configuration); |
91 |
0 |
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
public void start() throws JetspeedException |
109 |
|
{ |
110 |
0 |
DateFormat format = DateFormat.getInstance(); |
111 |
0 |
Date startTime = new Date(); |
112 |
|
try |
113 |
|
{ |
114 |
0 |
log.info("Starting Jetspeed Engine ("+getClass().getName()+") at "+format.format(startTime)); |
115 |
|
|
116 |
|
|
117 |
0 |
ClassLoader ploader2 = this.getClass().getClassLoader(); |
118 |
|
|
119 |
0 |
ClassHelper.setClassLoader(ploader2); |
120 |
|
|
121 |
|
|
122 |
0 |
componentManager.start(); |
123 |
0 |
pipelineMapper = (Map)componentManager.getComponent("pipeline-map"); |
124 |
|
try |
125 |
|
{ |
126 |
0 |
statistics = (PortalStatistics)componentManager.getComponent("PortalStatistics"); |
127 |
|
} |
128 |
0 |
catch (Exception e) |
129 |
|
{ |
130 |
|
|
131 |
|
|
132 |
0 |
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
} |
140 |
0 |
catch (Throwable e) |
141 |
|
{ |
142 |
0 |
e.printStackTrace(); |
143 |
0 |
log.error(e.toString()); |
144 |
0 |
throw new JetspeedException("Jetspeed Initialization exception!", e); |
145 |
|
} |
146 |
|
finally |
147 |
|
{ |
148 |
0 |
Date endTime = new Date(); |
149 |
0 |
long elapsedTime = (endTime.getTime() - startTime.getTime()) / 1000; |
150 |
0 |
log.info("Finished starting Jetspeed Engine ("+getClass().getName()+") at "+format.format(endTime) |
151 |
|
+". Elapsed time: "+elapsedTime+" seconds."); |
152 |
0 |
} |
153 |
0 |
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
public ServletConfig getServletConfig() |
162 |
|
{ |
163 |
0 |
return this.config; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
public void shutdown() throws JetspeedException |
169 |
|
{ |
170 |
|
|
171 |
|
try |
172 |
|
{ |
173 |
0 |
PortletContainer container = (PortletContainer) componentManager |
174 |
|
.getComponent(PortletContainer.class); |
175 |
0 |
if (container != null) |
176 |
|
{ |
177 |
0 |
container.shutdown(); |
178 |
|
} |
179 |
|
|
180 |
0 |
componentManager.stop(); |
181 |
|
} |
182 |
0 |
catch (PortletContainerException e) |
183 |
|
{ |
184 |
0 |
throw new JetspeedException(e); |
185 |
0 |
} |
186 |
0 |
System.gc(); |
187 |
0 |
} |
188 |
|
|
189 |
|
public void service( RequestContext context ) throws JetspeedException |
190 |
|
{ |
191 |
0 |
long start = System.currentTimeMillis(); |
192 |
0 |
String targetPipeline = context |
193 |
|
.getRequestParameter(PortalReservedParameters.PIPELINE); |
194 |
0 |
if (null == targetPipeline) |
195 |
|
{ |
196 |
0 |
targetPipeline = (String)context.getAttribute(PortalReservedParameters.PIPELINE); |
197 |
0 |
if (null == targetPipeline) |
198 |
|
{ |
199 |
0 |
String pipelineKey = context.getRequest().getServletPath(); |
200 |
0 |
if (null != pipelineKey) |
201 |
|
{ |
202 |
0 |
if (pipelineKey.equals("/portal")) |
203 |
0 |
targetPipeline = this.defaultPipelineName; |
204 |
|
else |
205 |
0 |
targetPipeline = (String)pipelineMapper.get(pipelineKey); |
206 |
|
|
207 |
|
} |
208 |
|
else |
209 |
|
{ |
210 |
0 |
targetPipeline = this.defaultPipelineName; |
211 |
|
} |
212 |
|
} |
213 |
|
} |
214 |
0 |
Pipeline pipeline = null; |
215 |
0 |
if (targetPipeline != null) |
216 |
|
{ |
217 |
0 |
Pipeline specificPipeline = getPipeline(targetPipeline); |
218 |
0 |
if (specclass="keyword">ificPipeline != null) |
219 |
|
{ |
220 |
0 |
pipeline = specificPipeline; |
221 |
|
} |
222 |
0 |
} |
223 |
|
else |
224 |
0 |
pipeline = getPipeline(); |
225 |
|
|
226 |
0 |
context.setPipeline(pipeline); |
227 |
0 |
pipeline.invoke(context); |
228 |
|
|
229 |
0 |
long end = System.currentTimeMillis(); |
230 |
0 |
if (statistics != null) |
231 |
0 |
statistics.logPageAccess(context, PortalStatistics.HTTP_OK, end - start); |
232 |
0 |
} |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
public PortalContext getContext() |
240 |
|
{ |
241 |
0 |
return this.context; |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
public String getRealPath( String path ) |
250 |
|
{ |
251 |
0 |
String result = ""; |
252 |
0 |
String base = context.getApplicationRoot(); |
253 |
0 |
if (base.endsWith(java.io.File.separator)) |
254 |
|
{ |
255 |
0 |
if (path.startsWith("/")) |
256 |
|
{ |
257 |
0 |
result = base.concat(path.substring(1)); |
258 |
0 |
return result; |
259 |
|
} |
260 |
|
} |
261 |
|
else |
262 |
|
{ |
263 |
0 |
if (!path.startsWith("/")) |
264 |
|
{ |
265 |
0 |
result = base.concat("/").concat(path); |
266 |
0 |
return result; |
267 |
|
} |
268 |
|
} |
269 |
0 |
return base.concat(path); |
270 |
|
} |
271 |
|
|
272 |
|
public Pipeline getPipeline( String pipelineName ) |
273 |
|
{ |
274 |
0 |
return (Pipeline) componentManager.getComponent(pipelineName); |
275 |
|
} |
276 |
|
|
277 |
|
public Pipeline getPipeline() |
278 |
|
{ |
279 |
0 |
return getPipeline(defaultPipelineName); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
public RequestContext getCurrentRequestContext() |
286 |
|
{ |
287 |
0 |
RequestContextComponent contextComponent = (RequestContextComponent) getComponentManager() |
288 |
|
.getComponent(RequestContextComponent.class); |
289 |
0 |
return contextComponent.getRequestContext(); |
290 |
|
} |
291 |
|
|
292 |
|
public ComponentManager getComponentManager() |
293 |
|
{ |
294 |
0 |
return this.componentManager; |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
public Factory getFactory( Class theClass ) |
306 |
|
{ |
307 |
0 |
return (Factory) getComponentManager().getComponent(theClass); |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
public ContainerService getContainerService( Class service ) |
319 |
|
{ |
320 |
0 |
if(service.equals(FactoryManagerService.class)) |
321 |
|
{ |
322 |
0 |
return this; |
323 |
|
} |
324 |
|
|
325 |
|
try |
326 |
|
{ |
327 |
0 |
return (ContainerService) getComponentManager().getComponent(service); |
328 |
|
} |
329 |
0 |
catch (NoSuchBeanDefinitionException e) |
330 |
|
{ |
331 |
0 |
log.warn("No ContainerService defined for "+service.getName()); |
332 |
0 |
return null; |
333 |
|
} |
334 |
|
} |
335 |
|
|
336 |
|
} |