]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move servlet wrapper to AbstractApplicationServlet
authorLeif Åstrand <leif@vaadin.com>
Tue, 8 Nov 2011 14:06:01 +0000 (16:06 +0200)
committerLeif Åstrand <leif@vaadin.com>
Tue, 8 Nov 2011 14:06:01 +0000 (16:06 +0200)
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/CommunicationManager.java

index 865d173f4dd5be133d7c7b829f3dc10c1ef7424d..2bed6f4cb81d9d5c14047224601ffde9acf72a63 100644 (file)
@@ -41,7 +41,10 @@ import com.vaadin.terminal.ParameterHandler;
 import com.vaadin.terminal.Terminal;
 import com.vaadin.terminal.ThemeResource;
 import com.vaadin.terminal.URIHandler;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.terminal.WrappedResponse;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.server.AbstractCommunicationManager.Callback;
 import com.vaadin.ui.Root;
 
 /**
@@ -62,6 +65,40 @@ import com.vaadin.ui.Root;
 public abstract class AbstractApplicationServlet extends HttpServlet implements
         Constants {
 
+    private static class AbstractApplicationServletWrapper implements Callback {
+
+        private final AbstractApplicationServlet servlet;
+
+        public AbstractApplicationServletWrapper(
+                AbstractApplicationServlet servlet) {
+            this.servlet = servlet;
+        }
+
+        public void criticalNotification(WrappedRequest request,
+                WrappedResponse response, String cap, String msg,
+                String details, String outOfSyncURL) throws IOException {
+            servlet.criticalNotification(((WrappedHttpServletRequest) request)
+                    .getHttpServletRequest(),
+                    ((WrappedHttpServletResponse) response)
+                            .getHttpServletResponse(), cap, msg, details,
+                    outOfSyncURL);
+        }
+
+        public String getRequestPathInfo(WrappedRequest request) {
+            return servlet
+                    .getRequestPathInfo(((WrappedHttpServletRequest) request)
+                            .getHttpServletRequest());
+        }
+
+        public InputStream getThemeResourceAsStream(String themeName,
+                String resource) throws IOException {
+            return servlet.getServletContext().getResourceAsStream(
+                    "/" + AbstractApplicationServlet.THEME_DIRECTORY_PATH
+                            + themeName + "/" + resource);
+        }
+
+    }
+
     // TODO Move some (all?) of the constants to a separate interface (shared
     // with portlet)
 
@@ -399,6 +436,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     @Override
     protected void service(HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
+        AbstractApplicationServletWrapper servletWrapper = new AbstractApplicationServletWrapper(
+                this);
 
         RequestType requestType = getRequestType(request);
         if (!ensureCookiesEnabled(requestType, request, response)) {
@@ -483,9 +522,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
             } else if (requestType == RequestType.UIDL) {
                 // Handles AJAX UIDL requests
                 Root root = applicationManager.getApplicationRoot(request,
-                        this, application, null);
+                        this, servletWrapper, application, null);
                 applicationManager.handleUidlRequest(request, response, this,
-                        root);
+                        servletWrapper, root);
                 return;
             }
 
@@ -504,7 +543,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
             // Finds the root within the application
             Root root = getApplicationRoot(request, applicationManager,
-                    application);
+                    servletWrapper, application);
             if (root == null) {
                 throw new ServletException(ERROR_NO_WINDOW_FOUND);
             }
@@ -2121,14 +2160,15 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      *            the HTTP Request.
      * @param application
      *            the Application to query for root.
+     * @param servletWrapper
      * @return Root matching the given URI or null if not found.
      * @throws ServletException
      *             if an exception has occurred that interferes with the
      *             servlet's normal operation.
      */
     protected Root getApplicationRoot(HttpServletRequest request,
-            CommunicationManager applicationManager, Application application)
-            throws ServletException {
+            CommunicationManager applicationManager, Callback servletWrapper,
+            Application application) throws ServletException {
         //
         // // Finds the window where the request is handled
         Root assumedRoot = null;
@@ -2156,7 +2196,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         // }
         //
         return applicationManager.getApplicationRoot(request, this,
-                application, assumedRoot);
+                servletWrapper, application, assumedRoot);
     }
 
     /**
index c7eb62e8f246771ab6dd85629f199fd1cb4d8e9a..02bd4ea8e3f93f6e59666444098ffa184a8c9df6 100644 (file)
@@ -5,7 +5,6 @@
 package com.vaadin.terminal.gwt.server;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -18,8 +17,6 @@ import com.vaadin.Application;
 import com.vaadin.terminal.Paintable;
 import com.vaadin.terminal.StreamVariable;
 import com.vaadin.terminal.VariableOwner;
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.terminal.WrappedResponse;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.Root;
 
@@ -39,40 +36,6 @@ import com.vaadin.ui.Root;
 @SuppressWarnings("serial")
 public class CommunicationManager extends AbstractCommunicationManager {
 
-    private static class AbstractApplicationServletWrapper implements Callback {
-
-        private final AbstractApplicationServlet servlet;
-
-        public AbstractApplicationServletWrapper(
-                AbstractApplicationServlet servlet) {
-            this.servlet = servlet;
-        }
-
-        public void criticalNotification(WrappedRequest request,
-                WrappedResponse response, String cap, String msg,
-                String details, String outOfSyncURL) throws IOException {
-            servlet.criticalNotification(((WrappedHttpServletRequest) request)
-                    .getHttpServletRequest(),
-                    ((WrappedHttpServletResponse) response)
-                            .getHttpServletResponse(), cap, msg, details,
-                    outOfSyncURL);
-        }
-
-        public String getRequestPathInfo(WrappedRequest request) {
-            return servlet
-                    .getRequestPathInfo(((WrappedHttpServletRequest) request)
-                            .getHttpServletRequest());
-        }
-
-        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
@@ -159,6 +122,7 @@ public class CommunicationManager extends AbstractCommunicationManager {
      * @param request
      * @param response
      * @param applicationServlet
+     * @param callback
      * @param window
      *            target window of the UIDL request, can be null if window not
      *            found
@@ -167,12 +131,12 @@ public class CommunicationManager extends AbstractCommunicationManager {
      */
     public void handleUidlRequest(HttpServletRequest request,
             HttpServletResponse response,
-            AbstractApplicationServlet applicationServlet, Root root)
-            throws IOException, ServletException,
+            AbstractApplicationServlet applicationServlet, Callback callback,
+            Root root) throws IOException, ServletException,
             InvalidUIDLSecurityKeyException {
         doHandleUidlRequest(new WrappedHttpServletRequest(request,
                 applicationServlet), new WrappedHttpServletResponse(response),
-                new AbstractApplicationServletWrapper(applicationServlet), root);
+                callback, root);
     }
 
     /**
@@ -186,17 +150,17 @@ public class CommunicationManager extends AbstractCommunicationManager {
      * @param assumedRoot
      *            if the window has been already resolved once, this parameter
      *            must contain the window.
+     * @param callback
      * @return Window matching the given URI or null if not found.
      * @throws ServletException
      *             if an exception has occurred that interferes with the
      *             servlet's normal operation.
      */
     Root getApplicationRoot(HttpServletRequest request,
-            AbstractApplicationServlet applicationServlet,
+            AbstractApplicationServlet applicationServlet, Callback callback,
             Application application, Root assumedRoot) throws ServletException {
         return doGetApplicationWindow(new WrappedHttpServletRequest(request,
-                applicationServlet), new AbstractApplicationServletWrapper(
-                applicationServlet), application, assumedRoot);
+                applicationServlet), callback, application, assumedRoot);
     }
 
     @Override