1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.vaadin.terminal.gwt.server;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.vaadin.Application;
import com.vaadin.external.org.apache.commons.fileupload.FileItemIterator;
import com.vaadin.external.org.apache.commons.fileupload.FileUpload;
import com.vaadin.external.org.apache.commons.fileupload.FileUploadException;
import com.vaadin.external.org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.vaadin.terminal.DownloadStream;
import com.vaadin.ui.Window;
/**
* Application manager processes changes and paints for single application
* instance.
*
* @author IT Mill Ltd.
* @version
* @VERSION@
* @since 5.0
*/
@SuppressWarnings("serial")
public class CommunicationManager extends AbstractCommunicationManager {
private static class HttpServletRequestWrapper implements Request {
private final HttpServletRequest request;
public HttpServletRequestWrapper(HttpServletRequest request) {
this.request = request;
}
public Object getAttribute(String name) {
return request.getAttribute(name);
}
public int getContentLength() {
return request.getContentLength();
}
public InputStream getInputStream() throws IOException {
return request.getInputStream();
}
public String getParameter(String name) {
return request.getParameter(name);
}
public String getRequestID() {
return "RequestURL:" + request.getRequestURI();
}
public Session getSession() {
return new HttpSessionWrapper(request.getSession());
}
public Object getWrappedRequest() {
return request;
}
public boolean isRunningInPortlet() {
return false;
}
public void setAttribute(String name, Object o) {
request.setAttribute(name, o);
}
}
private static class HttpServletResponseWrapper implements Response {
private final HttpServletResponse response;
public HttpServletResponseWrapper(HttpServletResponse response) {
this.response = response;
}
public OutputStream getOutputStream() throws IOException {
return response.getOutputStream();
}
public Object getWrappedResponse() {
return response;
}
public void setContentType(String type) {
response.setContentType(type);
}
}
private static class HttpSessionWrapper implements Session {
private final HttpSession session;
public HttpSessionWrapper(HttpSession session) {
this.session = session;
}
public Object getAttribute(String name) {
return session.getAttribute(name);
}
public int getMaxInactiveInterval() {
return session.getMaxInactiveInterval();
}
public Object getWrappedSession() {
return session;
}
public boolean isNew() {
return session.isNew();
}
public void setAttribute(String name, Object o) {
session.setAttribute(name, o);
}
}
private static class AbstractApplicationServletWrapper implements Callback {
private final AbstractApplicationServlet servlet;
public AbstractApplicationServletWrapper(
AbstractApplicationServlet servlet) {
this.servlet = servlet;
}
public void criticalNotification(Request request, Response response,
String cap, String msg, String details, String outOfSyncURL)
throws IOException {
servlet.criticalNotification((HttpServletRequest) request
.getWrappedRequest(), (HttpServletResponse) response
.getWrappedResponse(), cap, msg, details, outOfSyncURL);
}
public String getRequestPathInfo(Request request) {
return servlet.getRequestPathInfo((HttpServletRequest) request
.getWrappedRequest());
}
public InputStream getThemeResourceAsStream(String themeName,
String resource) throws IOException {
return servlet.getServletContext().getResourceAsStream(
"/" + AbstractApplicationServlet.THEME_DIRECTORY_PATH
+ themeName + "/" + resource);
}
}
/**
* @deprecated use {@link #CommunicationManager(Application)} instead
* @param application
* @param applicationServlet
*/
@Deprecated
public CommunicationManager(Application application,
AbstractApplicationServlet applicationServlet) {
super(application);
}
/**
* TODO New constructor - document me!
*
* @param application
*/
public CommunicationManager(Application application) {
super(application);
}
@Override
protected FileUpload createFileUpload() {
return new ServletFileUpload();
}
@Override
protected FileItemIterator getItemIterator(FileUpload upload,
Request request) throws IOException, FileUploadException {
return ((ServletFileUpload) upload)
.getItemIterator((HttpServletRequest) request
.getWrappedRequest());
}
/**
* Handles file upload request submitted via Upload component.
*
* @param request
* @param response
* @throws IOException
* @throws FileUploadException
*/
public void handleFileUpload(HttpServletRequest request,
HttpServletResponse response) throws IOException,
FileUploadException {
doHandleFileUpload(new HttpServletRequestWrapper(request),
new HttpServletResponseWrapper(response));
}
/**
* Handles UIDL request
*
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
public void handleUidlRequest(HttpServletRequest request,
HttpServletResponse response,
AbstractApplicationServlet applicationServlet) throws IOException,
ServletException, InvalidUIDLSecurityKeyException {
doHandleUidlRequest(new HttpServletRequestWrapper(request),
new HttpServletResponseWrapper(response),
new AbstractApplicationServletWrapper(applicationServlet));
}
/**
* Gets the existing application or create a new one. Get a window within an
* application based on the requested URI.
*
* @param request
* the HTTP Request.
* @param application
* the Application to query for window.
* @param assumedWindow
* if the window has been already resolved once, this parameter
* must contain the window.
* @return Window mathing the given URI or null if not found.
* @throws ServletException
* if an exception has occurred that interferes with the
* servlet's normal operation.
*/
Window getApplicationWindow(HttpServletRequest request,
AbstractApplicationServlet applicationServlet,
Application application, Window assumedWindow)
throws ServletException {
return doGetApplicationWindow(new HttpServletRequestWrapper(request),
new AbstractApplicationServletWrapper(applicationServlet),
application, assumedWindow);
}
/**
* TODO Document me!
*
* @param window
* @param request
* @param response
* @param applicationServlet
* @return
*/
DownloadStream handleURI(Window window, HttpServletRequest request,
HttpServletResponse response,
AbstractApplicationServlet applicationServlet) {
return handleURI(window, new HttpServletRequestWrapper(request),
new HttpServletResponseWrapper(response),
new AbstractApplicationServletWrapper(applicationServlet));
}
}
|