// Handles AJAX UIDL requests
Root root = applicationManager.getApplicationRoot(
wrappedRequest, application);
+ if (root == null) {
+ throw new ServletException(ERROR_NO_WINDOW_FOUND);
+ }
applicationManager.handleUidlRequest(wrappedRequest,
wrappedResponse, servletWrapper, root);
return;
}
// TODO Should return 404 error here and not do anything more
- // Finds the root within the application
- Root root = applicationManager.getApplicationRoot(wrappedRequest,
- application);
- if (root == null) {
- throw new ServletException(ERROR_NO_WINDOW_FOUND);
- }
-
- // Send initial AJAX page that kickstarts a Vaadin application
- writeAjaxPage(request, response, root, application);
-
} catch (final SessionExpiredException e) {
// Session has expired, notify user
handleServiceSessionExpired(request, response);
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.servlet.ServletException;
+
import com.vaadin.Application;
import com.vaadin.Application.SystemMessages;
import com.vaadin.terminal.PaintException;
.getLogger(AbstractCommunicationManager.class.getName());
private static final RequestHandler APP_RESOURCE_HANDLER = new ApplicationResourceHandler();
+ private static final RequestHandler AJAX_PAGE_HANDLER = new AjaxPageHandler() {
+
+ @Override
+ protected void writeAjaxPage(WrappedRequest request,
+ WrappedResponse response, Root root) throws IOException {
+ {
+ WrappedHttpServletRequest wrappedServletRequest = (WrappedHttpServletRequest) request;
+ try {
+ wrappedServletRequest.getServlet().writeAjaxPage(
+ wrappedServletRequest.getHttpServletRequest(),
+ ((WrappedHttpServletResponse) response)
+ .getHttpServletResponse(), root,
+ root.getApplication());
+ } catch (ServletException e) {
+ logger.log(Level.WARNING, e.getLocalizedMessage(), e);
+ writeError(response, e);
+ }
+ }
+ }
+
+ };
/**
* TODO Document me!
*/
public AbstractCommunicationManager(Application application) {
this.application = application;
+ application.addRequestHandler(AJAX_PAGE_HANDLER);
application.addRequestHandler(APP_RESOURCE_HANDLER);
requireLocale(application.getLocale().toString());
}
int rootId = Integer.parseInt(rootIdString);
root = application.getRootById(rootId);
}
- if (root == null) {
- root = application.getRoot(request);
- }
}
Root.setCurrentRoot(root);
--- /dev/null
+package com.vaadin.terminal.gwt.server;
+
+import java.io.IOException;
+
+import com.vaadin.Application;
+import com.vaadin.terminal.RequestHandler;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.terminal.WrappedResponse;
+import com.vaadin.ui.Root;
+
+public abstract class AjaxPageHandler implements RequestHandler {
+
+ public boolean handleRequest(Application application,
+ WrappedRequest request, WrappedResponse response)
+ throws IOException {
+
+ // TODO Should all urls be handled here?
+ Root root = application.getRoot(request);
+
+ if (root == null) {
+ writeError(response, null);
+ return true;
+ }
+
+ writeAjaxPage(request, response, root);
+
+ return true;
+ }
+
+ protected abstract void writeAjaxPage(WrappedRequest request,
+ WrappedResponse response, Root root) throws IOException;
+
+ protected void writeError(WrappedResponse response, Throwable e)
+ throws IOException {
+ response.setStatus(500);
+ response.getWriter().println("Error");
+ }
+
+}
public String getContentType() {
return request.getContentType();
}
+
+ public AbstractApplicationServlet getServlet() {
+ return servlet;
+ }
}
\ No newline at end of file