1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Processes changes and paints for single application instance."""
17
18 import uuid
19
20 from warnings import warn
21
22 from muntjac.terminal.gwt.server.abstract_communication_manager import \
23 AbstractCommunicationManager, ICallback, IRequest, IResponse, \
24 InvalidUIDLSecurityKeyException, ISession
25
26 from muntjac.terminal.gwt.server.abstract_application_servlet import \
27 AbstractApplicationServlet
28
29
31 """Application manager processes changes and paints for single application
32 instance.
33
34 This class handles applications running as servlets.
35
36 @see: L{AbstractCommunicationManager}
37 @author: Vaadin Ltd.
38 @author: Richard Lincoln
39 @version: 1.1.2
40 """
41
42 - def __init__(self, application, applicationServlet=None):
43 """@deprecated: use L{CommunicationManager} instead
44 """
45 if applicationServlet is not None:
46 warn("deprecated", DeprecationWarning)
47
48 super(CommunicationManager, self).__init__(application)
49
50 self._pidToNameToStreamVariable = None
51 self._streamVariableToSeckey = None
52
53
55 """Handles file upload request submitted via Upload component.
56
57 @see: L{getStreamVariableTargetUrl}
58 @raise L{IOException}:
59 @raise L{InvalidUIDLSecurityKeyException}:
60 """
61
62
63 pathInfo = applicationServlet.getPathInfo(request)
64
65 startOfData = \
66 pathInfo.find(AbstractApplicationServlet.UPLOAD_URL_PREFIX) \
67 + len(AbstractApplicationServlet.UPLOAD_URL_PREFIX)
68 uppUri = pathInfo[startOfData:]
69 parts = uppUri.split('/', 3)
70 variableName = parts[1]
71 paintableId = parts[0]
72
73 streamVariable = self._pidToNameToStreamVariable.get(
74 paintableId).get(variableName)
75 secKey = self._streamVariableToSeckey.get(streamVariable)
76 if secKey == parts[2]:
77
78 source = self.getVariableOwner(paintableId)
79 contentType = applicationServlet.getContentType(request)
80 if 'boundary' in applicationServlet.getContentType(request):
81
82 self.doHandleSimpleMultipartFileUpload(
83 HttpServletRequestWrapper(request,
84 applicationServlet),
85 HttpServletResponseWrapper(response,
86 applicationServlet),
87 streamVariable,
88 variableName,
89 source,
90 contentType.split('boundary=')[1])
91 else:
92
93
94 self.doHandleXhrFilePost(
95 HttpServletRequestWrapper(request,
96 applicationServlet),
97 HttpServletResponseWrapper(response,
98 applicationServlet),
99 streamVariable,
100 variableName,
101 source,
102 applicationServlet.getContentType(request))
103 else:
104 raise InvalidUIDLSecurityKeyException, \
105 'Security key in upload post did not match!'
106
107
125
126
129 """Gets the existing application or creates a new one. Get a window
130 within an application based on the requested URI.
131
132 @param request:
133 the HTTP Request.
134 @param application:
135 the Application to query for window.
136 @param assumedWindow:
137 if the window has been already resolved once, this
138 parameter must contain the window.
139 @return: Window matching the given URI or null if not found.
140 @raise ServletException:
141 if an exception has occurred that interferes with the
142 servlet's normal operation.
143 """
144 return self.doGetApplicationWindow(
145 HttpServletRequestWrapper(request, applicationServlet),
146 AbstractApplicationServletWrapper(applicationServlet),
147 application,
148 assumedWindow)
149
150
151 - def handleURI(self, window, request, response, applicationServlet):
152 """Calls the Window URI handler for a request and returns the
153 L{DownloadStream} returned by the handler.
154
155 If the window is the main window of an application, the deprecated
156 L{Application.handleURI} is called first to handle
157 L{ApplicationResource}s and the window handler is only called if
158 it returns C{None}.
159
160 @see: L{AbstractCommunicationManager.handleURI}
161 """
162 return AbstractCommunicationManager.handleURI(self, window,
163 HttpServletRequestWrapper(request, applicationServlet),
164 HttpServletResponseWrapper(response, applicationServlet),
165 AbstractApplicationServletWrapper(applicationServlet))
166
167
177
178
180
181
182
183
184
185
186
187
188
189
190 paintableId = self.getPaintableId(owner)
191 key = paintableId + '/' + name
192
193 if self._pidToNameToStreamVariable is None:
194 self._pidToNameToStreamVariable = dict()
195
196 nameToStreamVariable = self._pidToNameToStreamVariable.get(paintableId)
197 if nameToStreamVariable is None:
198 nameToStreamVariable = dict()
199 self._pidToNameToStreamVariable[paintableId] = nameToStreamVariable
200 nameToStreamVariable[name] = value
201
202 if self._streamVariableToSeckey is None:
203 self._streamVariableToSeckey = dict()
204
205 seckey = self._streamVariableToSeckey.get(value)
206 if seckey is None:
207 seckey = str(uuid.uuid4())
208 self._streamVariableToSeckey[value] = seckey
209
210 return ('app://' + AbstractApplicationServlet.UPLOAD_URL_PREFIX
211 + key + '/' + seckey)
212
213
215 nameToStreamVar = self._pidToNameToStreamVariable.get(
216 self.getPaintableId(owner))
217 if 'name' in nameToStreamVar:
218 del nameToStreamVar['name']
219 if len(nameToStreamVar) == 0:
220 if self.getPaintableId(owner) in self._pidToNameToStreamVariable:
221 del self._pidToNameToStreamVariable[self.getPaintableId(owner)]
222
223
225 """Concrete wrapper class for L{HttpServletRequest}.
226
227 @see: L{IRequest}
228 """
229
230 - def __init__(self, request, applicationServlet):
231 self._request = request
232 self.servlet = applicationServlet
233
234
236 return self.servlet.getParameter(self._request, name, default)
237
238
240 return self.servlet.getContentLength(self._request)
241
242
245
246
248 return self.servlet.getParameter(self._request, name, None)
249
250
252 return 'RequestURL:' + self.servlet.getRequestUri(self._request)
253
254
258
259
262
263
266
267
270
271
274
275
277 """Concrete wrapper class for L{HttpServletResponse}.
278
279 @see: L{IResponse}
280 """
281
282 - def __init__(self, response, applicationServlet):
283 self._response = response
284 self.servlet = applicationServlet
285
286
289
290
292 return self._response
293
294
297
298
299 - def setContentType(self, typ):
300 self.servlet.setHeader(self._response, 'Content-Type', typ)
301
302
304 """Concrete wrapper class for L{HttpSession}.
305
306 @see: L{ISession}
307 """
308
309 - def __init__(self, session, applicationServlet):
310 self._session = session
311 self.servlet = applicationServlet
312
313
316
317
319 """maximum time interval, in seconds, between client accesses"""
320 return self.servlet.getMaxInactiveInterval(self._session)
321
322
325
326
329
330
333
334
337
338
340
342 self.servlet = servlet
343
344
350
351
354
355
360