}
/**
- * 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,
.isClientSideInitialized(connector);
processedConnectors.add(connector);
- connector.beforeClientResponse(!initialized);
+ try {
+ connector.beforeClientResponse(!initialized);
+ } catch (RuntimeException e) {
+ manager.handleConnectorRelatedException(connector, e);
+ }
}
}
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,
return "MessagesInfo locale: " + getLocale();
}
});
- super.beforeClientResponse(initial);
if (fail) {
throw new RuntimeException("Failed on purpose");
+ } else {
+ return super.encodeState();
}
}
}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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));
+ }
+}