1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.pipeline.valve.impl; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.io.PrintWriter; |
21 |
|
import java.util.Stack; |
22 |
|
|
23 |
|
import javax.servlet.RequestDispatcher; |
24 |
|
import javax.servlet.ServletException; |
25 |
|
import javax.servlet.http.HttpServletRequest; |
26 |
|
|
27 |
|
import org.apache.commons.logging.Log; |
28 |
|
import org.apache.commons.logging.LogFactory; |
29 |
|
import org.apache.jetspeed.pipeline.PipelineException; |
30 |
|
import org.apache.jetspeed.pipeline.valve.AbstractValve; |
31 |
|
import org.apache.jetspeed.pipeline.valve.LayoutValve; |
32 |
|
import org.apache.jetspeed.pipeline.valve.ValveContext; |
33 |
|
import org.apache.jetspeed.request.RequestContext; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
0 |
public class VerySimpleLayoutValveImpl extends AbstractValve implements LayoutValve |
49 |
|
{ |
50 |
0 |
private static final Log log = LogFactory.getLog(VerySimpleLayoutValveImpl.class); |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public void invoke(RequestContext request, ValveContext context) throws PipelineException |
56 |
|
{ |
57 |
|
try |
58 |
|
{ |
59 |
0 |
log.info("Invoking the VerySimpleLayoutValve..."); |
60 |
0 |
HttpServletRequest httpRequest = request.getRequest(); |
61 |
0 |
RequestDispatcher rd = httpRequest.getRequestDispatcher("/pages/SimpleLayoutHeader.jsp"); |
62 |
0 |
rd.include(httpRequest, request.getResponse()); |
63 |
|
|
64 |
0 |
Stack renderStack = (Stack) httpRequest.getAttribute(CleanupValveImpl.RENDER_STACK_ATTR); |
65 |
0 |
if (renderStack == null) |
66 |
|
{ |
67 |
0 |
renderStack = new Stack(); |
68 |
0 |
httpRequest.setAttribute(CleanupValveImpl.RENDER_STACK_ATTR, renderStack); |
69 |
|
} |
70 |
0 |
renderStack.push("/pages/SimpleLayoutFooter.jsp"); |
71 |
|
|
72 |
|
} |
73 |
0 |
catch (Exception e) |
74 |
|
{ |
75 |
|
try |
76 |
|
{ |
77 |
0 |
log.error("VerySimpleLayout: Unable to include layout header. Layout not processed", e); |
78 |
0 |
PrintWriter pw = request.getResponse().getWriter(); |
79 |
0 |
pw.write("VerySimpleLayoutFailed failed to include servlet resources. (details below) <br/>"); |
80 |
0 |
pw.write("Exception: " + e.getClass().getName() + " <br/>"); |
81 |
0 |
pw.write("Message: " + e.getMessage() + " <br/>"); |
82 |
0 |
writeStackTrace(e.getStackTrace(), pw); |
83 |
|
|
84 |
0 |
if (e instanceof ServletException && ((ServletException) e).getRootCause() != null) |
85 |
|
{ |
86 |
0 |
Throwable rootCause = ((ServletException) e).getRootCause(); |
87 |
0 |
pw.write("Root Cause: " + rootCause.getClass().getName() + " <br/>"); |
88 |
0 |
pw.write("Message: " + rootCause.getMessage() + " <br/>"); |
89 |
0 |
writeStackTrace(rootCause.getStackTrace(), pw); |
90 |
|
} |
91 |
|
} |
92 |
0 |
catch (IOException e1) |
93 |
|
{ |
94 |
|
|
95 |
0 |
} |
96 |
|
|
97 |
|
} |
98 |
|
finally |
99 |
|
{ |
100 |
0 |
context.invokeNext(request); |
101 |
0 |
} |
102 |
|
|
103 |
0 |
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
public String toString() |
109 |
|
{ |
110 |
0 |
return "VerySimpleLayoutValveImpl"; |
111 |
|
} |
112 |
|
|
113 |
|
protected static final void writeStackTrace(StackTraceElement[] traceArray, PrintWriter pw) |
114 |
|
{ |
115 |
0 |
pw.write("<p>Stack Trace: </p>"); |
116 |
0 |
for (int i = 0; i < traceArray.length; i++) |
117 |
|
{ |
118 |
0 |
pw.write(" " + traceArray[i].toString() + "<br />"); |
119 |
|
} |
120 |
0 |
} |
121 |
|
|
122 |
|
} |