summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-04-25 15:32:50 +0300
committerVaadin Code Review <review@vaadin.com>2013-04-25 17:52:17 +0000
commitddf73a0fce1e943b3aacf7e0791504c841ce3800 (patch)
treeb00e6f10fc16d6e6114d2313e6f51414b3e1534e
parentf73da53c7d8d950952fb1a0c8469bca7ca5d9386 (diff)
downloadvaadin-framework-ddf73a0fce1e943b3aacf7e0791504c841ce3800.tar.gz
vaadin-framework-ddf73a0fce1e943b3aacf7e0791504c841ce3800.zip
Pass ServletConfig to atmosphere init (#11716)
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
-rw-r--r--server/src/com/vaadin/server/VaadinPortlet.java14
-rw-r--r--server/src/com/vaadin/server/VaadinPortletService.java6
-rw-r--r--server/src/com/vaadin/server/VaadinService.java18
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java14
-rw-r--r--server/src/com/vaadin/server/VaadinServletService.java6
-rw-r--r--server/src/com/vaadin/server/communication/PushRequestHandler.java9
-rw-r--r--server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java6
-rw-r--r--server/tests/src/com/vaadin/server/VaadinSessionTest.java3
-rw-r--r--server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java4
9 files changed, 61 insertions, 19 deletions
diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java
index 12c68e8673..b383878f28 100644
--- a/server/src/com/vaadin/server/VaadinPortlet.java
+++ b/server/src/com/vaadin/server/VaadinPortlet.java
@@ -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;
}
/**
diff --git a/server/src/com/vaadin/server/VaadinPortletService.java b/server/src/com/vaadin/server/VaadinPortletService.java
index 05ce8626c5..2eca07dd4a 100644
--- a/server/src/com/vaadin/server/VaadinPortletService.java
+++ b/server/src/com/vaadin/server/VaadinPortletService.java
@@ -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());
diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java
index 11060c6f73..a4520e77e2 100644
--- a/server/src/com/vaadin/server/VaadinService.java
+++ b/server/src/com/vaadin/server/VaadinService.java
@@ -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());
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index 9dc62808c7..1facf6e29a 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -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;
}
/**
diff --git a/server/src/com/vaadin/server/VaadinServletService.java b/server/src/com/vaadin/server/VaadinServletService.java
index 088bb6d640..e7df223f89 100644
--- a/server/src/com/vaadin/server/VaadinServletService.java
+++ b/server/src/com/vaadin/server/VaadinServletService.java
@@ -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());
diff --git a/server/src/com/vaadin/server/communication/PushRequestHandler.java b/server/src/com/vaadin/server/communication/PushRequestHandler.java
index f7cff43e84..3540078f85 100644
--- a/server/src/com/vaadin/server/communication/PushRequestHandler.java
+++ b/server/src/com/vaadin/server/communication/PushRequestHandler.java
@@ -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
diff --git a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java
index c7330001d3..2a83f5d5b2 100644
--- a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java
+++ b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java
@@ -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);
}
diff --git a/server/tests/src/com/vaadin/server/VaadinSessionTest.java b/server/tests/src/com/vaadin/server/VaadinSessionTest.java
index 3f83fde711..8f471afd46 100644
--- a/server/tests/src/com/vaadin/server/VaadinSessionTest.java
+++ b/server/tests/src/com/vaadin/server/VaadinSessionTest.java
@@ -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) {
diff --git a/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java b/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java
index 3ea114b488..bee932a29f 100644
--- a/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java
+++ b/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java
@@ -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));
}