1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.container.invoker; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
|
21 |
|
import javax.portlet.ActionRequest; |
22 |
|
import javax.portlet.ActionResponse; |
23 |
|
import javax.portlet.PortletException; |
24 |
|
import javax.portlet.PortletRequest; |
25 |
|
import javax.portlet.PortletResponse; |
26 |
|
import javax.portlet.RenderRequest; |
27 |
|
import javax.portlet.RenderResponse; |
28 |
|
import javax.portlet.UnavailableException; |
29 |
|
import javax.servlet.ServletConfig; |
30 |
|
import javax.servlet.ServletContext; |
31 |
|
import javax.servlet.ServletRequest; |
32 |
|
|
33 |
|
import org.apache.commons.logging.Log; |
34 |
|
import org.apache.commons.logging.LogFactory; |
35 |
|
import org.apache.jetspeed.PortalReservedParameters; |
36 |
|
import org.apache.jetspeed.container.ContainerConstants; |
37 |
|
import org.apache.jetspeed.container.PortletRequestContext; |
38 |
|
import org.apache.jetspeed.factory.PortletFactory; |
39 |
|
import org.apache.jetspeed.factory.PortletInstance; |
40 |
|
import org.apache.jetspeed.om.common.portlet.PortletApplication; |
41 |
|
import org.apache.jetspeed.request.RequestContext; |
42 |
|
import org.apache.pluto.om.portlet.PortletDefinition; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
public class LocalPortletInvoker implements JetspeedPortletInvoker |
60 |
|
{ |
61 |
0 |
private final static Log log = LogFactory.getLog(LocalPortletInvoker.class); |
62 |
|
|
63 |
|
protected PortletFactory portletFactory; |
64 |
|
protected ServletContext jetspeedContext; |
65 |
|
protected ServletConfig jetspeedConfig; |
66 |
|
protected PortletDefinition portletDefinition; |
67 |
0 |
protected boolean activated = false; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig) |
73 |
|
{ |
74 |
0 |
this.portletFactory = portletFactory; |
75 |
0 |
this.jetspeedConfig = servletConfig; |
76 |
0 |
jetspeedContext = servletConfig.getServletContext(); |
77 |
0 |
this.portletDefinition = portletDefinition; |
78 |
0 |
activated = true; |
79 |
0 |
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
public void passivate() |
85 |
|
{ |
86 |
0 |
activated = false; |
87 |
0 |
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
public boolean isActivated() |
93 |
|
{ |
94 |
0 |
return activated; |
95 |
|
} |
96 |
|
|
97 |
|
public LocalPortletInvoker() |
98 |
0 |
{ |
99 |
0 |
activated = false; |
100 |
0 |
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
public void action(ActionRequest request, ActionResponse response) |
106 |
|
throws PortletException, IOException |
107 |
|
{ |
108 |
0 |
invoke(request, response, ContainerConstants.METHOD_ACTION); |
109 |
0 |
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
public void render(RenderRequest request, RenderResponse response) |
115 |
|
throws PortletException, IOException |
116 |
|
{ |
117 |
0 |
invoke(request, response, ContainerConstants.METHOD_RENDER); |
118 |
0 |
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
public void load(PortletRequest request, RenderResponse response) |
124 |
|
throws PortletException |
125 |
|
{ |
126 |
|
try |
127 |
|
{ |
128 |
0 |
invoke(request, response, ContainerConstants.METHOD_NOOP); |
129 |
|
} |
130 |
0 |
catch (IOException e) |
131 |
|
{ |
132 |
0 |
log.error("LocalPortletInvokerImpl.load() - Error while dispatching portlet.", e); |
133 |
0 |
throw new PortletException(e); |
134 |
0 |
} |
135 |
0 |
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse, Integer method) |
150 |
|
throws PortletException, IOException |
151 |
|
{ |
152 |
0 |
ClassLoader paClassLoader = portletFactory |
153 |
|
.getPortletApplicationClassLoader((PortletApplication) portletDefinition |
154 |
|
.getPortletApplicationDefinition()); |
155 |
0 |
PortletInstance portletInstance = portletFactory.getPortletInstance(jetspeedContext, portletDefinition); |
156 |
|
|
157 |
0 |
if (method == ContainerConstants.METHOD_NOOP) |
158 |
|
{ |
159 |
0 |
return; |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
0 |
ServletRequest servletRequest = ((javax.servlet.http.HttpServletRequestWrapper) portletRequest).getRequest(); |
164 |
|
|
165 |
0 |
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); |
166 |
|
try |
167 |
|
{ |
168 |
0 |
PortletRequestContext.createContext(portletDefinition, portletInstance, portletRequest, portletResponse); |
169 |
|
|
170 |
0 |
servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig()); |
171 |
0 |
servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest); |
172 |
0 |
servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse); |
173 |
0 |
RequestContext requestContext = (RequestContext) servletRequest |
174 |
|
.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); |
175 |
0 |
servletRequest |
176 |
|
.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath()); |
177 |
|
|
178 |
0 |
Thread.currentThread().setContextClassLoader(paClassLoader); |
179 |
|
|
180 |
0 |
if (method == ContainerConstants.METHOD_ACTION) |
181 |
|
{ |
182 |
0 |
ActionRequest actionRequest = (ActionRequest) portletRequest; |
183 |
0 |
ActionResponse actionResponse = (ActionResponse) portletResponse; |
184 |
|
|
185 |
0 |
portletInstance.processAction(actionRequest, actionResponse); |
186 |
0 |
} |
187 |
0 |
else if (method == ContainerConstants.METHOD_RENDER) |
188 |
|
{ |
189 |
0 |
RenderRequest renderRequest = (RenderRequest) portletRequest; |
190 |
0 |
RenderResponse renderResponse = (RenderResponse) portletResponse; |
191 |
0 |
renderResponse.setContentType(requestContext.getMimeType()); |
192 |
0 |
portletInstance.render(renderRequest, renderResponse); |
193 |
|
} |
194 |
|
} |
195 |
0 |
catch (Throwable t) |
196 |
|
{ |
197 |
0 |
if ( t instanceof UnavailableException ) |
198 |
|
{ |
199 |
|
|
200 |
|
try |
201 |
|
{ |
202 |
0 |
portletInstance.destroy(); |
203 |
|
} |
204 |
0 |
catch (Throwable ignore) |
205 |
|
{ |
206 |
|
|
207 |
0 |
} |
208 |
|
} |
209 |
0 |
if ( t instanceof PortletException ) |
210 |
|
{ |
211 |
0 |
throw (PortletException)t; |
212 |
|
} |
213 |
0 |
if ( t instanceof IOException ) |
214 |
|
{ |
215 |
0 |
throw (IOException)t; |
216 |
|
} |
217 |
|
else |
218 |
|
{ |
219 |
0 |
throw new PortletException(t); |
220 |
|
} |
221 |
|
} |
222 |
|
finally |
223 |
|
{ |
224 |
0 |
PortletRequestContext.clearContext(); |
225 |
0 |
servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG); |
226 |
0 |
servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST); |
227 |
0 |
servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE); |
228 |
0 |
servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT); |
229 |
|
|
230 |
0 |
Thread.currentThread().setContextClassLoader(oldLoader); |
231 |
0 |
} |
232 |
0 |
} |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig, String servletMappingName) |
238 |
|
{ |
239 |
0 |
activate(portletFactory, portletDefinition, servletConfig); |
240 |
0 |
} |
241 |
|
|
242 |
|
} |