summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2014-03-24 15:44:19 +0200
committerJohannes Dahlström <johannesd@vaadin.com>2014-03-27 14:26:42 +0200
commitd4c8b5f404aad5a1f89bd44afa23aa732b21d4e4 (patch)
treee7616915ae9d139740f80589a202c5123469c9d9 /server
parent880bdbd52b1f92057a680928f2ca8898b6fc5145 (diff)
downloadvaadin-framework-d4c8b5f404aad5a1f89bd44afa23aa732b21d4e4.tar.gz
vaadin-framework-d4c8b5f404aad5a1f89bd44afa23aa732b21d4e4.zip
Use the ErrorHandler mechanism in ConnectorResourceHandler (#12269)
Change-Id: I9d608e942380bd53868b65eda180fe9c8477c138
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/ConnectorResourceHandler.java8
-rw-r--r--server/tests/src/com/vaadin/server/ConnectorResourceHandlerTest.java97
2 files changed, 105 insertions, 0 deletions
diff --git a/server/src/com/vaadin/server/ConnectorResourceHandler.java b/server/src/com/vaadin/server/ConnectorResourceHandler.java
index 3f3f41a179..e4315e9694 100644
--- a/server/src/com/vaadin/server/ConnectorResourceHandler.java
+++ b/server/src/com/vaadin/server/ConnectorResourceHandler.java
@@ -87,6 +87,14 @@ public class ConnectorResourceHandler implements RequestHandler {
+ connector.getConnectorId()
+ ") did not handle connector request for " + key);
}
+ } catch (Exception e) {
+ session.lock();
+ try {
+ session.getCommunicationManager()
+ .handleConnectorRelatedException(connector, e);
+ } finally {
+ session.unlock();
+ }
} finally {
CurrentInstance.restoreInstances(oldInstances);
}
diff --git a/server/tests/src/com/vaadin/server/ConnectorResourceHandlerTest.java b/server/tests/src/com/vaadin/server/ConnectorResourceHandlerTest.java
new file mode 100644
index 0000000000..828c35ced3
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/ConnectorResourceHandlerTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.server;
+
+import java.io.IOException;
+
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.UI;
+
+public class ConnectorResourceHandlerTest {
+
+ VaadinRequest request;
+ VaadinResponse response;
+ VaadinSession session;
+ UI ui;
+
+ @Before
+ public void setUp() {
+ IMocksControl control = EasyMock.createNiceControl();
+
+ request = control.createMock(VaadinRequest.class);
+ response = control.createMock(VaadinResponse.class);
+ VaadinService service = control.createMock(VaadinService.class);
+
+ EasyMock.expect(request.getPathInfo())
+ .andReturn("/APP/connector/0/1/2");
+
+ control.replay();
+
+ session = new MockVaadinSession(service);
+
+ ui = new UI() {
+ @Override
+ protected void init(VaadinRequest request) {
+ }
+ };
+ ui.doInit(request, 0, "");
+
+ session.lock();
+ try {
+ session.setCommunicationManager(new LegacyCommunicationManager(
+ session));
+ ui.setSession(session);
+ session.addUI(ui);
+ } finally {
+ session.unlock();
+ }
+ }
+
+ @Test
+ public void testErrorHandling() throws IOException {
+
+ ErrorHandler errorHandler = EasyMock.createMock(ErrorHandler.class);
+ errorHandler.error(EasyMock.anyObject(ErrorEvent.class));
+ EasyMock.replay(errorHandler);
+
+ Button button = new Button() {
+ @Override
+ public boolean handleConnectorRequest(VaadinRequest request,
+ VaadinResponse response, String path) {
+ throw new RuntimeException();
+ }
+ };
+ button.setErrorHandler(errorHandler);
+
+ session.lock();
+ try {
+ ui.setContent(button);
+ } finally {
+ session.unlock();
+ }
+
+ ConnectorResourceHandler handler = new ConnectorResourceHandler();
+ Assert.assertTrue(handler.handleRequest(session, request, response));
+
+ EasyMock.verify(errorHandler);
+ }
+}