]> source.dussan.org Git - vaadin-framework.git/commitdiff
Pass ServletConfig to atmosphere init (#11716)
authorLeif Åstrand <leif@vaadin.com>
Thu, 25 Apr 2013 12:32:50 +0000 (15:32 +0300)
committerVaadin Code Review <review@vaadin.com>
Thu, 25 Apr 2013 17:52:17 +0000 (17:52 +0000)
Furthermore, the exception that might get thrown from there is passed up
through the call stack until it can be handled in a sensible way.

Change-Id: I4a741b5ad4d9216255932c2328b49e73e92df2f4

server/src/com/vaadin/server/VaadinPortlet.java
server/src/com/vaadin/server/VaadinPortletService.java
server/src/com/vaadin/server/VaadinService.java
server/src/com/vaadin/server/VaadinServlet.java
server/src/com/vaadin/server/VaadinServletService.java
server/src/com/vaadin/server/communication/PushRequestHandler.java
server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java
server/tests/src/com/vaadin/server/VaadinSessionTest.java
server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java

index 12c68e8673359ad385cfba8903b62106f4571c38..b383878f286aecb44fca142449834b70085a142f 100644 (file)
@@ -250,7 +250,11 @@ public class VaadinPortlet extends GenericPortlet implements Constants,
         }
 
         DeploymentConfiguration deploymentConfiguration = createDeploymentConfiguration(initParameters);
-        vaadinService = createPortletService(deploymentConfiguration);
+        try {
+            vaadinService = createPortletService(deploymentConfiguration);
+        } catch (ServiceException e) {
+            throw new PortletException("Could not initialized VaadinPortlet", e);
+        }
         // Sets current service even though there are no request and response
         vaadinService.setCurrentInstances(null, null);
 
@@ -269,8 +273,12 @@ public class VaadinPortlet extends GenericPortlet implements Constants,
     }
 
     protected VaadinPortletService createPortletService(
-            DeploymentConfiguration deploymentConfiguration) {
-        return new VaadinPortletService(this, deploymentConfiguration);
+            DeploymentConfiguration deploymentConfiguration)
+            throws ServiceException {
+        VaadinPortletService service = new VaadinPortletService(this,
+                deploymentConfiguration);
+        service.init();
+        return service;
     }
 
     /**
index 05ce8626c56a6478cfc827a1d8dbe58467e551e7..2eca07dd4a36af3621970c1fbfd837f564bc8462 100644 (file)
@@ -39,7 +39,8 @@ public class VaadinPortletService extends VaadinService {
     private final VaadinPortlet portlet;
 
     public VaadinPortletService(VaadinPortlet portlet,
-            DeploymentConfiguration deploymentConfiguration) {
+            DeploymentConfiguration deploymentConfiguration)
+            throws ServiceException {
         super(deploymentConfiguration);
         this.portlet = portlet;
 
@@ -55,7 +56,8 @@ public class VaadinPortletService extends VaadinService {
     }
 
     @Override
-    protected List<RequestHandler> createRequestHandlers() {
+    protected List<RequestHandler> createRequestHandlers()
+            throws ServiceException {
         List<RequestHandler> handlers = super.createRequestHandlers();
 
         handlers.add(new PortletUIInitHandler());
index 11060c6f733b75dd6d2168e2986fd6e0129c879d..a4520e77e2b239f53a300fa0fd22f61090dd9de9 100644 (file)
@@ -101,7 +101,7 @@ public abstract class VaadinService implements Serializable {
 
     private ClassLoader classLoader;
 
-    private final Iterable<RequestHandler> requestHandlers;
+    private Iterable<RequestHandler> requestHandlers;
 
     /**
      * Keeps track of whether a warning about missing push support has already
@@ -135,11 +135,20 @@ public abstract class VaadinService implements Serializable {
                                 + classLoaderName, e);
             }
         }
+    }
 
+    /**
+     * Initializes this service. The service should be initialized before it is
+     * used.
+     * 
+     * @since 7.1
+     * @throws ServiceException
+     *             if a problem occurs when creating the service
+     */
+    public void init() throws ServiceException {
         List<RequestHandler> handlers = createRequestHandlers();
         Collections.reverse(handlers);
         requestHandlers = Collections.unmodifiableCollection(handlers);
-
     }
 
     /**
@@ -150,8 +159,11 @@ public abstract class VaadinService implements Serializable {
      * predefined handler.
      * 
      * @return The list of request handlers used by this service.
+     * @throws ServiceException
+     *             if a problem occurs when creating the request handlers
      */
-    protected List<RequestHandler> createRequestHandlers() {
+    protected List<RequestHandler> createRequestHandlers()
+            throws ServiceException {
         ArrayList<RequestHandler> handlers = new ArrayList<RequestHandler>();
         handlers.add(new SessionRequestHandler());
         handlers.add(new PublishedFileHandler());
index 9dc62808c7e4b0286e3e61338a3c71639b95a3b8..1facf6e29af56f7bd633d544c20ab795ec677bc0 100644 (file)
@@ -84,7 +84,11 @@ public class VaadinServlet extends HttpServlet implements Constants {
         }
 
         DeploymentConfiguration deploymentConfiguration = createDeploymentConfiguration(initParameters);
-        servletService = createServletService(deploymentConfiguration);
+        try {
+            servletService = createServletService(deploymentConfiguration);
+        } catch (ServiceException e) {
+            throw new ServletException("Could not initialize VaadinServlet", e);
+        }
         // Sets current service even though there are no request and response
         servletService.setCurrentInstances(null, null);
 
@@ -142,8 +146,12 @@ public class VaadinServlet extends HttpServlet implements Constants {
     }
 
     protected VaadinServletService createServletService(
-            DeploymentConfiguration deploymentConfiguration) {
-        return new VaadinServletService(this, deploymentConfiguration);
+            DeploymentConfiguration deploymentConfiguration)
+            throws ServiceException {
+        VaadinServletService service = new VaadinServletService(this,
+                deploymentConfiguration);
+        service.init();
+        return service;
     }
 
     /**
index 088bb6d64074d87a62d823fcbf26d4e33b8d8f36..e7df223f8980afc17e522f431f274fb71b43a643 100644 (file)
@@ -50,7 +50,8 @@ public class VaadinServletService extends VaadinService {
     private boolean pushWarningLogged = false;
 
     public VaadinServletService(VaadinServlet servlet,
-            DeploymentConfiguration deploymentConfiguration) {
+            DeploymentConfiguration deploymentConfiguration)
+            throws ServiceException {
         super(deploymentConfiguration);
         this.servlet = servlet;
 
@@ -82,7 +83,8 @@ public class VaadinServletService extends VaadinService {
     }
 
     @Override
-    protected List<RequestHandler> createRequestHandlers() {
+    protected List<RequestHandler> createRequestHandlers()
+            throws ServiceException {
         List<RequestHandler> handlers = super.createRequestHandlers();
         handlers.add(0, new ServletBootstrapHandler());
         handlers.add(new ServletUIInitHandler());
index f7cff43e846c71502c3e55913e2b88badc1a20e8..3540078f85c519df9bab7db3d799f85c99557fdb 100644 (file)
@@ -26,6 +26,7 @@ import org.atmosphere.cpr.AtmosphereRequest;
 import org.atmosphere.cpr.AtmosphereResponse;
 
 import com.vaadin.server.RequestHandler;
+import com.vaadin.server.ServiceException;
 import com.vaadin.server.ServletPortletHelper;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinResponse;
@@ -47,7 +48,7 @@ public class PushRequestHandler implements RequestHandler {
     private AtmosphereFramework atmosphere;
     private PushHandler pushHandler;
 
-    public PushRequestHandler(VaadinServletService service) {
+    public PushRequestHandler(VaadinServletService service) throws ServiceException {
 
         atmosphere = new AtmosphereFramework();
 
@@ -64,7 +65,11 @@ public class PushRequestHandler implements RequestHandler {
         // message stream into individual messages when using certain transports
         atmosphere.interceptor(new TrackMessageSizeInterceptor());
 
-        atmosphere.init();
+        try {
+            atmosphere.init(service.getServlet().getServletConfig());
+        } catch (ServletException e) {
+            throw new ServiceException("Could not read atmosphere settings", e);
+        }
     }
 
     @Override
index c7330001d3057c8b48dc3d135e9fd5512a8312be..2a83f5d5b2aaa4cbe3e2a99da9330dd1dbca0198 100644 (file)
@@ -28,9 +28,11 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase
         // Workaround to avoid calling init and creating servlet config
         Field f = VaadinServlet.class.getDeclaredField("servletService");
         f.setAccessible(true);
-        f.set(servlet, new VaadinServletService(servlet,
+        VaadinServletService service = new VaadinServletService(servlet,
                 new DefaultDeploymentConfiguration(servlet.getClass(),
-                        new Properties())));
+                        new Properties()));
+        service.init();
+        f.set(servlet, service);
 
     }
 
index 3f83fde711e099ab64221242d4e82c95a7d9bf78..8f471afd46ece7bc479a8b0641d624daaf797c1d 100644 (file)
@@ -45,7 +45,7 @@ public class VaadinSessionTest {
     private UI ui;
 
     @Before
-    public void setup() {
+    public void setup() throws Exception {
         mockServlet = new VaadinServlet() {
             @Override
             public String getServletName() {
@@ -55,6 +55,7 @@ public class VaadinSessionTest {
 
         mockService = new VaadinServletService(mockServlet,
                 new MockDeploymentConfiguration());
+        mockService.init();
 
         mockHttpSession = EasyMock.createMock(HttpSession.class);
         mockWrappedSession = new WrappedHttpSession(mockHttpSession) {
index 3ea114b488567429d37808baf5bc3c7164fcbe96..bee932a29fcbfefe9d6134f1800d8b0009bc94df 100644 (file)
@@ -76,10 +76,12 @@ public class TestStreamVariableMapping extends TestCase {
                 variableName));
     }
 
-    private LegacyCommunicationManager createCommunicationManager() {
+    private LegacyCommunicationManager createCommunicationManager()
+            throws Exception {
         VaadinServletService vss = new VaadinServletService(
                 EasyMock.createMock(VaadinServlet.class),
                 new MockDeploymentConfiguration());
+        vss.init();
         return new LegacyCommunicationManager(
                 new AlwaysLockedVaadinSession(vss));
     }