From: Leif Åstrand Date: Thu, 6 Sep 2012 10:22:29 +0000 (+0300) Subject: Move ErrorListener implementation out of VaadinSession (#9402) X-Git-Tag: 7.0.0.beta1~169 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fa6e2d6295aed4a6dfa8f63147abcfdb8f671e85;p=vaadin-framework.git Move ErrorListener implementation out of VaadinSession (#9402) --- diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index ff9e84dc67..121e156da8 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -281,7 +281,7 @@ public abstract class Application extends AbstractUIProvider implements @Override public void terminalError(ErrorEvent event) { - VaadinSession.getCurrent().terminalError(event); + VaadinSession.getCurrent().getErrorHandler().terminalError(event); } public VaadinSession getContext() { diff --git a/server/src/com/vaadin/server/DefaultErrorListener.java b/server/src/com/vaadin/server/DefaultErrorListener.java new file mode 100644 index 0000000000..46f96272fd --- /dev/null +++ b/server/src/com/vaadin/server/DefaultErrorListener.java @@ -0,0 +1,60 @@ +/* + * Copyright 2011 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.net.SocketException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.vaadin.server.Terminal.ErrorEvent; +import com.vaadin.ui.AbstractComponent; + +public class DefaultErrorListener implements Terminal.ErrorListener { + @Override + public void terminalError(ErrorEvent event) { + final Throwable t = event.getThrowable(); + if (t instanceof SocketException) { + // Most likely client browser closed socket + getLogger() + .info("SocketException in CommunicationManager." + + " Most likely client (browser) closed socket."); + return; + } + + // Finds the original source of the error/exception + Object owner = null; + if (event instanceof VariableOwner.ErrorEvent) { + owner = ((VariableOwner.ErrorEvent) event).getVariableOwner(); + } else if (event instanceof ChangeVariablesErrorEvent) { + owner = ((ChangeVariablesErrorEvent) event).getComponent(); + } + + // Shows the error in AbstractComponent + if (owner instanceof AbstractComponent) { + ((AbstractComponent) owner) + .setComponentError(AbstractErrorMessage + .getErrorMessageForException(t)); + } + + // also print the error on console + getLogger().log(Level.SEVERE, "Terminal error:", t); + } + + private Logger getLogger() { + return Logger.getLogger(DefaultErrorListener.class.getName()); + } +} \ No newline at end of file diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index 50cc7a01be..c95dc9ac22 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -19,7 +19,6 @@ package com.vaadin.server; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Method; -import java.net.SocketException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -31,7 +30,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; import javax.portlet.PortletSession; @@ -45,7 +43,6 @@ import com.vaadin.data.util.converter.DefaultConverterFactory; import com.vaadin.event.EventRouter; import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.shared.ui.ui.UIConstants; -import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.AbstractField; import com.vaadin.ui.Table; import com.vaadin.ui.UI; @@ -67,8 +64,7 @@ import com.vaadin.util.ReflectTools; * @since 7.0.0 */ @SuppressWarnings("serial") -public class VaadinSession implements Terminal.ErrorListener, - HttpSessionBindingListener, Serializable { +public class VaadinSession implements HttpSessionBindingListener, Serializable { /** * The name of the parameter that is by default used in e.g. web.xml to @@ -176,7 +172,7 @@ public class VaadinSession implements Terminal.ErrorListener, * Session wide error handler which is used by default if an error is left * unhandled. */ - private Terminal.ErrorListener errorHandler = this; + private Terminal.ErrorListener errorHandler = new DefaultErrorListener(); /** * The converter factory that is used to provide default converters for the @@ -562,53 +558,6 @@ public class VaadinSession implements Terminal.ErrorListener, this.logoutURL = logoutURL; } - /** - *

- * Invoked by the terminal on any exception that occurs in application and - * is thrown by the setVariable to the terminal. The default - * implementation sets the exceptions as ComponentErrors to the - * component that initiated the exception and prints stack trace to standard - * error stream. - *

- *

- * You can safely override this method in your application in order to - * direct the errors to some other destination (for example log). - *

- * - * @param event - * the change event. - * @see com.vaadin.server.Terminal.ErrorListener#terminalError(com.vaadin.server.Terminal.ErrorEvent) - */ - @Override - @Deprecated - public void terminalError(Terminal.ErrorEvent event) { - final Throwable t = event.getThrowable(); - if (t instanceof SocketException) { - // Most likely client browser closed socket - getLogger().info( - "SocketException in CommunicationManager." - + " Most likely client (browser) closed socket."); - return; - } - - // Finds the original source of the error/exception - Object owner = null; - if (event instanceof VariableOwner.ErrorEvent) { - owner = ((VariableOwner.ErrorEvent) event).getVariableOwner(); - } else if (event instanceof ChangeVariablesErrorEvent) { - owner = ((ChangeVariablesErrorEvent) event).getComponent(); - } - - // Shows the error in AbstractComponent - if (owner instanceof AbstractComponent) { - ((AbstractComponent) owner).setComponentError(AbstractErrorMessage - .getErrorMessageForException(t)); - } - - // also print the error on console - getLogger().log(Level.SEVERE, "Terminal error:", t); - } - /** * Gets the session's error handler. *