]> source.dussan.org Git - vaadin-framework.git/commitdiff
opening the servlet implementation for customized communication ( e.g. jsonp, websockets)
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 19 Jan 2011 14:48:57 +0000 (14:48 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 19 Jan 2011 14:48:57 +0000 (14:48 +0000)
 * WebApplicationContext implementation can now be overridden in servlets via getApplicationContext method. Deprecated createCommunicationManager method as it is now obsolete (introduced earlier in 6.5 branch, dontpush is the only known user).
 * opened getApplicationUrl for special implementations

svn changeset:16950/svn branch:6.5

src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java
src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java

index 9379766130b164d83b8618a019cab95348680f14..bf3ba8f759ea42f1554daf9424ee7b992b1662be 100644 (file)
@@ -432,8 +432,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
              * Get or create a WebApplicationContext and an ApplicationManager
              * for the session
              */
-            WebApplicationContext webApplicationContext = WebApplicationContext
-                    .getApplicationContext(request.getSession());
+            WebApplicationContext webApplicationContext = getApplicationContext(request
+                    .getSession());
             CommunicationManager applicationManager = webApplicationContext
                     .getApplicationManager(application, this);
 
@@ -934,8 +934,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
             throws ServletException, MalformedURLException {
         Application newApplication = getNewApplication(request);
 
-        final WebApplicationContext context = WebApplicationContext
-                .getApplicationContext(request.getSession());
+        final WebApplicationContext context = getApplicationContext(request
+                .getSession());
         context.addApplication(newApplication);
 
         return newApplication;
@@ -2008,7 +2008,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      *             if the application is denied access to the persistent data
      *             store represented by the given URL.
      */
-    URL getApplicationUrl(HttpServletRequest request)
+    protected URL getApplicationUrl(HttpServletRequest request)
             throws MalformedURLException {
         final URL reqURL = new URL(
                 (request.isSecure() ? "https://" : "http://")
@@ -2066,8 +2066,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
             throw new SessionExpiredException();
         }
 
-        WebApplicationContext context = WebApplicationContext
-                .getApplicationContext(session);
+        WebApplicationContext context = getApplicationContext(session);
 
         // Gets application list for the session.
         final Collection<Application> applications = context.getApplications();
@@ -2088,8 +2087,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                 }
                 // Application has stopped, so remove it before creating a new
                 // application
-                WebApplicationContext.getApplicationContext(session)
-                        .removeApplication(sessionApplication);
+                getApplicationContext(session).removeApplication(
+                        sessionApplication);
                 break;
             }
         }
@@ -2121,8 +2120,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
         final HttpSession session = request.getSession();
         if (session != null) {
-            WebApplicationContext.getApplicationContext(session)
-                    .removeApplication(application);
+            getApplicationContext(session).removeApplication(application);
         }
 
         response.sendRedirect(response.encodeRedirectURL(logoutUrl));
@@ -2214,12 +2212,30 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
         application.close();
         if (session != null) {
-            WebApplicationContext context = WebApplicationContext
-                    .getApplicationContext(session);
+            WebApplicationContext context = getApplicationContext(session);
             context.removeApplication(application);
         }
     }
 
+    /**
+     * 
+     * Gets the application context from an HttpSession. If no context is
+     * currently stored in a session a new context is created and stored in the
+     * session.
+     * 
+     * @param session
+     *            the HTTP session.
+     * @return the application context for HttpSession.
+     */
+    protected WebApplicationContext getApplicationContext(HttpSession session) {
+        /*
+         * TODO the ApplicationContext.getApplicationContext() should be removed
+         * and logic moved here. Now overriding context type is possible, but
+         * the whole creation logic should be here. MT 1101
+         */
+        return WebApplicationContext.getApplicationContext(session);
+    }
+
     /**
      * Implementation of ParameterHandler.ErrorEvent interface.
      */
@@ -2307,12 +2323,18 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Override this method if you need to use a specialized communicaiton
      * mananger implementation.
      * 
-     * TODO figure out the right place for CM instantiation, must be
-     * overridieable
+     * @deprecated Instead of overriding this method, override
+     *             {@link WebApplicationContext} implementation via
+     *             {@link AbstractApplicationServlet#getApplicationContext(HttpSession)}
+     *             method and in that customized implementation return your
+     *             CommunicationManager in
+     *             {@link WebApplicationContext#getApplicationManager(Application, AbstractApplicationServlet)}
+     *             method.
      * 
      * @param application
      * @return
      */
+    @Deprecated
     public CommunicationManager createCommunicationManager(
             Application application) {
         return new CommunicationManager(application);
index 5e660ab82cc6fdc0b67e8292a7040ca838337ded..10f0b94ddae7c03b1e17243d6cf750393728cccb 100644 (file)
@@ -48,7 +48,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet {
     }
 
     @Override
-    URL getApplicationUrl(HttpServletRequest request)
+    protected URL getApplicationUrl(HttpServletRequest request)
             throws MalformedURLException {
         URL url = super.getApplicationUrl(request);
 
index 5f8e59e0567210260d04735ccfb87f004df43bd3..86dbd910d5e7803615b4942dd2115568540788d3 100644 (file)
@@ -320,7 +320,7 @@ public class GAEApplicationServlet extends ApplicationServlet {
             }
         }
         // will create new context if the above did not
-        return WebApplicationContext.getApplicationContext(session);
+        return getApplicationContext(session);
 
     }