]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use the ErrorHandler mechanism in ConnectorResourceHandler (#12269)
authorJohannes Dahlström <johannesd@vaadin.com>
Mon, 24 Mar 2014 13:44:19 +0000 (15:44 +0200)
committerJohannes Dahlström <johannesd@vaadin.com>
Thu, 27 Mar 2014 12:26:42 +0000 (14:26 +0200)
Change-Id: I9d608e942380bd53868b65eda180fe9c8477c138

server/src/com/vaadin/server/ConnectorResourceHandler.java
server/tests/src/com/vaadin/server/ConnectorResourceHandlerTest.java [new file with mode: 0644]

index 3f3f41a179af4e538295bec02a2c18d289b3cf50..e4315e9694c95493ae5be111200709c8767c0cc0 100644 (file)
@@ -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 (file)
index 0000000..828c35c
--- /dev/null
@@ -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);
+    }
+}