if (requestType == RequestType.STATIC_FILE) {
serveStaticResources(request, response);
return;
}
Application application = null;
boolean transactionStarted = false;
boolean requestStarted = false;
try {
// If a duplicate "close application" URL is received for an
// application that is not open, redirect to the application's main
// page.
// This is needed as e.g. Spring Security remembers the last
// URL from the application, which is the logout URL, and repeats
// it.
// We can tell apart a real onunload request from a repeated one
// based on the real one having content (at least the UIDL security
// key).
if (requestType == RequestType.UIDL
&& request.getParameterMap().containsKey(
ApplicationConnection.PARAM_UNLOADBURST)
&& request.getContentLength() < 1
&& getExistingApplication(request, false) == null) {
redirectToApplication(request, response);
return;
}
// Find out which application this request is related to
application = findApplicationInstance(request, requestType);
if (application == null) {
return;
}
/*
* Get or create a WebApplicationContext and an ApplicationManager
* for the session
*/
WebApplicationContext webApplicationContext = WebApplicationContext
.getApplicationContext(request.getSession());
CommunicationManager applicationManager = webApplicationContext
.getApplicationManager(application, this);
/* Update browser information from the request */
updateBrowserProperties(webApplicationContext.getBrowser(), request);
/*
* Call application requestStart before Application.init() is called
* (bypasses the limitation in TransactionListener)
*/
if (application instanceof HttpServletRequestListener) {
((HttpServletRequestListener) application).onRequestStart(
request, response);
requestStarted = true;
}
// Start the newly created application
startApplication(request, application, webApplicationContext);
/*
* Transaction starts. Call transaction listeners. Transaction end
* is called in the finally block below.
*/
webApplicationContext.startTransaction(application, request);
transactionStarted = true;
/* Handle the request */
if (requestType == RequestType.FILE_UPLOAD) {
applicationManager.handleFileUpload(request, response);
return;
} else if (requestType == RequestType.UIDL) {
// Handles AJAX UIDL requests
Window window = applicationManager.getApplicationWindow(
request, this, application, null);
applicationManager.handleUidlRequest(request, response, this,
window);
return;
}
// Removes application if it has stopped (mayby by thread or
// transactionlistener)
if (!application.isRunning()) {
endApplication(request, response, application);
return;
}
// Finds the window within the application
Window window = getApplicationWindow(request, applicationManager,
application);
if (window == null) {
throw new ServletException(ERROR_NO_WINDOW_FOUND);
}
// Sets terminal type for the window, if not already set
if (window.getTerminal() == null) {
window.setTerminal(webApplicationContext.getBrowser());
}
// Handle parameters
final Map parameters = request.getParameterMap();
if (window != null && parameters != null) {
window.handleParameters(parameters);
}
/*
* Call the URI handlers and if this turns out to be a download
* request, send the file to the client
*/
if (handleURI(applicationManager, window, request, response)) {
return;
}
// Send initial AJAX page that kickstarts a Vaadin application
writeAjaxPage(request, response, window, application);
} catch (final SessionExpiredException e) {
// Session has expired, notify user
handleServiceSessionExpired(request, response);
} catch (final GeneralSecurityException e) {
handleServiceSecurityException(request, response);
} catch (final Throwable e) {
handleServiceException(request, response, application, e);
} finally {
// Notifies transaction end
try {
if (transactionStarted) {
((WebApplicationContext) application.getContext())
.endTransaction(application, request);
}
} finally {