summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2015-06-14 15:46:14 +0300
committerTeppo Kurki <teppo.kurki@vaadin.com>2015-06-17 12:33:23 +0000
commit024a2ab52e1ab5ac039c78f86c9c6fbf3a70f131 (patch)
tree1a84a06735896a4061e5f7e4cf9d5cae9773997b
parentf8aacf7c53d2e758e431588f44185b583fad8cb6 (diff)
downloadvaadin-framework-024a2ab52e1ab5ac039c78f86c9c6fbf3a70f131.tar.gz
vaadin-framework-024a2ab52e1ab5ac039c78f86c9c6fbf3a70f131.zip
Send beforeClientResponse exceptions to an error handler (#14214)
Change-Id: Ib0cd9a402bbef0c7adb65bd8298a71b5521edd7c
-rw-r--r--server/src/com/vaadin/server/LegacyCommunicationManager.java10
-rw-r--r--server/src/com/vaadin/server/communication/UidlWriter.java6
-rw-r--r--uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java7
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java61
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java35
5 files changed, 110 insertions, 9 deletions
diff --git a/server/src/com/vaadin/server/LegacyCommunicationManager.java b/server/src/com/vaadin/server/LegacyCommunicationManager.java
index fda5ad444f..e982cdf10a 100644
--- a/server/src/com/vaadin/server/LegacyCommunicationManager.java
+++ b/server/src/com/vaadin/server/LegacyCommunicationManager.java
@@ -388,17 +388,15 @@ public class LegacyCommunicationManager implements Serializable {
}
/**
- * Handles an exception that occurred when processing RPC calls or a file
- * upload.
+ * Handles an exception related to a connector by invoking the appropriate
+ * error handler.
*
* @deprecated As of 7.1. See #11411.
*
- * @param ui
- * The UI where the exception occured
* @param throwable
- * The exception
+ * the exception to handle
* @param connector
- * The Rpc target
+ * the connector that the exception is related to
*/
@Deprecated
public void handleConnectorRelatedException(ClientConnector connector,
diff --git a/server/src/com/vaadin/server/communication/UidlWriter.java b/server/src/com/vaadin/server/communication/UidlWriter.java
index 00a65d3877..a4797e49aa 100644
--- a/server/src/com/vaadin/server/communication/UidlWriter.java
+++ b/server/src/com/vaadin/server/communication/UidlWriter.java
@@ -109,7 +109,11 @@ public class UidlWriter implements Serializable {
.isClientSideInitialized(connector);
processedConnectors.add(connector);
- connector.beforeClientResponse(!initialized);
+ try {
+ connector.beforeClientResponse(!initialized);
+ } catch (RuntimeException e) {
+ manager.handleConnectorRelatedException(connector, e);
+ }
}
}
diff --git a/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java b/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java
index 00547aa2d2..9912e660ef 100644
--- a/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java
+++ b/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java
@@ -14,13 +14,15 @@ import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.NativeSelect;
+import elemental.json.JsonObject;
+
public class SystemMessages extends AbstractTestUI {
public class MyButton extends Button {
private boolean fail = false;
@Override
- public void beforeClientResponse(boolean initial) {
+ public JsonObject encodeState() {
// Set the error message to contain the current locale.
VaadinService.getCurrentRequest().setAttribute(
ApplicationRunnerServlet.CUSTOM_SYSTEM_MESSAGES_PROPERTY,
@@ -30,9 +32,10 @@ public class SystemMessages extends AbstractTestUI {
return "MessagesInfo locale: " + getLocale();
}
});
- super.beforeClientResponse(initial);
if (fail) {
throw new RuntimeException("Failed on purpose");
+ } else {
+ return super.encodeState();
}
}
}
diff --git a/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java
new file mode 100644
index 0000000000..23be0f62b4
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2000-2014 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.tests.components.abstractcomponent;
+
+import com.vaadin.server.ErrorHandler;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+
+public class ResponseWritingErrorHandling extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ ErrorHandler errorHandler = new ErrorHandler() {
+ @Override
+ public void error(com.vaadin.server.ErrorEvent event) {
+ String message = event.getThrowable().getMessage();
+ log(message);
+ }
+ };
+
+ Button button = new Button("Throw in beforeClientResponse") {
+ private boolean throwInBeforeClientResponse = false;
+ {
+ addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ throwInBeforeClientResponse = true;
+ // Make sure beforeClientResponse is called
+ markAsDirty();
+ }
+ });
+ }
+
+ @Override
+ public void beforeClientResponse(boolean initial) {
+ if (throwInBeforeClientResponse) {
+ throwInBeforeClientResponse = false;
+ throw new RuntimeException("Button.beforeClientResponse");
+ }
+ }
+ };
+ button.setErrorHandler(errorHandler);
+
+ addComponent(button);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java
new file mode 100644
index 0000000000..7b939a5627
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2014 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.tests.components.abstractcomponent;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ResponseWritingErrorHandlingTest extends SingleBrowserTest {
+
+ @Test
+ public void testExceptionInBeforeClientResponse() {
+ openTestURL();
+
+ $(ButtonElement.class).first().click();
+
+ Assert.assertEquals("Message should be logged by error handler",
+ "1. Button.beforeClientResponse", getLogRow(0));
+ }
+}