summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-09-06 13:22:29 +0300
committerLeif Åstrand <leif@vaadin.com>2012-09-06 13:22:46 +0300
commitfa6e2d6295aed4a6dfa8f63147abcfdb8f671e85 (patch)
treea5cba412ce12d8335fc1e7642d33645e1a125684 /server
parentcad90f99099b545b93ac5654c08ec74e36bc2b01 (diff)
downloadvaadin-framework-fa6e2d6295aed4a6dfa8f63147abcfdb8f671e85.tar.gz
vaadin-framework-fa6e2d6295aed4a6dfa8f63147abcfdb8f671e85.zip
Move ErrorListener implementation out of VaadinSession (#9402)
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/Application.java2
-rw-r--r--server/src/com/vaadin/server/DefaultErrorListener.java60
-rw-r--r--server/src/com/vaadin/server/VaadinSession.java55
3 files changed, 63 insertions, 54 deletions
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
@@ -563,53 +559,6 @@ public class VaadinSession implements Terminal.ErrorListener,
}
/**
- * <p>
- * Invoked by the terminal on any exception that occurs in application and
- * is thrown by the <code>setVariable</code> to the terminal. The default
- * implementation sets the exceptions as <code>ComponentErrors</code> to the
- * component that initiated the exception and prints stack trace to standard
- * error stream.
- * </p>
- * <p>
- * You can safely override this method in your application in order to
- * direct the errors to some other destination (for example log).
- * </p>
- *
- * @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.
*
* @return the current error handler