diff options
author | Jonatan Kronqvist <jonatan.kronqvist@itmill.com> | 2010-10-12 05:07:33 +0000 |
---|---|---|
committer | Jonatan Kronqvist <jonatan.kronqvist@itmill.com> | 2010-10-12 05:07:33 +0000 |
commit | 7e5911687972a2cd0c316b94340810b055ddb106 (patch) | |
tree | c703593af29221d766c669dc598482965708a311 /src/com | |
parent | 01fe9dbc7d502e91130bbdaf4d7ca138c597abd4 (diff) | |
download | vaadin-framework-7e5911687972a2cd0c316b94340810b055ddb106.tar.gz vaadin-framework-7e5911687972a2cd0c316b94340810b055ddb106.zip |
This is the implementation of the server-side logging feature
- Changed some loglevels according to review
- Don't log unecessary stacktraces in portlets
- printStackTrace:s replaced with JUL logging
- System.out and System.errs replaced with JUL logging
svn changeset:15493/svn branch:6.5
Diffstat (limited to 'src/com')
17 files changed, 201 insertions, 128 deletions
diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java index 14837fa0f9..9650146f53 100644 --- a/src/com/vaadin/Application.java +++ b/src/com/vaadin/Application.java @@ -17,6 +17,8 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Locale; import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.service.ApplicationContext; import com.vaadin.terminal.ApplicationResource; @@ -90,6 +92,9 @@ import com.vaadin.ui.Window; public abstract class Application implements URIHandler, Terminal.ErrorListener, Serializable { + private final static Logger logger = Logger.getLogger(Application.class + .getName()); + /** * Id use for the next window that is opened. Access to this must be * synchronized. @@ -1186,9 +1191,8 @@ public abstract class Application implements URIHandler, final Throwable t = event.getThrowable(); if (t instanceof SocketException) { // Most likely client browser closed socket - System.err - .println("Warning: SocketException in CommunicationManager." - + " Most likely client (browser) closed socket."); + logger.warning("SocketException in CommunicationManager." + + " Most likely client (browser) closed socket."); return; } @@ -1215,7 +1219,7 @@ public abstract class Application implements URIHandler, } // also print the error on console - t.printStackTrace(); + logger.log(Level.SEVERE, "Terminal error:", t); } /** diff --git a/src/com/vaadin/data/util/MethodProperty.java b/src/com/vaadin/data/util/MethodProperty.java index 394343aaf6..081833e361 100644 --- a/src/com/vaadin/data/util/MethodProperty.java +++ b/src/com/vaadin/data/util/MethodProperty.java @@ -9,6 +9,8 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.LinkedList; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.data.Property; import com.vaadin.util.SerializerHelper; @@ -49,6 +51,8 @@ import com.vaadin.util.SerializerHelper; public class MethodProperty<T> implements Property, Property.ValueChangeNotifier, Property.ReadOnlyStatusChangeNotifier { + private static final Logger logger = Logger.getLogger(MethodProperty.class + .getName()); /** * The object that includes the property the MethodProperty is bound to. */ @@ -146,11 +150,9 @@ public class MethodProperty<T> implements Property, getMethod = null; } } catch (SecurityException e) { - System.err.println("Internal deserialization error"); - e.printStackTrace(); + logger.log(Level.SEVERE, "Internal deserialization error", e); } catch (NoSuchMethodException e) { - System.err.println("Internal deserialization error"); - e.printStackTrace(); + logger.log(Level.SEVERE, "Internal deserialization error", e); } }; diff --git a/src/com/vaadin/event/ListenerMethod.java b/src/com/vaadin/event/ListenerMethod.java index b294dbf86d..8c7aa93f81 100644 --- a/src/com/vaadin/event/ListenerMethod.java +++ b/src/com/vaadin/event/ListenerMethod.java @@ -11,6 +11,8 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.EventListener; import java.util.EventObject; +import java.util.logging.Level; +import java.util.logging.Logger; /** * <p> @@ -41,6 +43,9 @@ import java.util.EventObject; @SuppressWarnings("serial") public class ListenerMethod implements EventListener, Serializable { + private static final Logger logger = Logger.getLogger(ListenerMethod.class + .getName()); + /** * Type of the event that should trigger this listener. Also the subclasses * of this class are accepted to trigger the listener. @@ -50,7 +55,7 @@ public class ListenerMethod implements EventListener, Serializable { /** * The object containing the trigger method. */ - private Object object; + private final Object object; /** * The trigger method to call when an event passing the given criteria @@ -79,10 +84,9 @@ public class ListenerMethod implements EventListener, Serializable { out.writeObject(name); out.writeObject(paramTypes); } catch (NotSerializableException e) { - System.err - .println("Fatal error in serialization of the application: Class " - + object.getClass().getName() - + " must implement serialization."); + logger.severe("Fatal error in serialization of the application: Class " + + object.getClass().getName() + + " must implement serialization."); throw e; } @@ -99,8 +103,7 @@ public class ListenerMethod implements EventListener, Serializable { // inner classes method = findHighestMethod(object.getClass(), name, paramTypes); } catch (SecurityException e) { - System.err.println("Internal deserialization error"); - e.printStackTrace(); + logger.log(Level.SEVERE, "Internal deserialization error", e); } }; diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index f6a88d9100..407b0dae77 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -21,6 +21,8 @@ import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; @@ -66,6 +68,9 @@ import com.vaadin.ui.Window; public abstract class AbstractApplicationPortlet extends GenericPortlet implements Constants { + private static final Logger logger = Logger + .getLogger(AbstractApplicationPortlet.class.getName()); + /** * This portlet parameter is used to add styles to the main element. E.g * "height:500px" generates a style="height:500px" to the main element. @@ -118,7 +123,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet * Print an information/warning message about running with xsrf * protection disabled */ - System.err.println(WARNING_XSRF_PROTECTION_DISABLED); + logger.warning(WARNING_XSRF_PROTECTION_DISABLED); } } @@ -138,7 +143,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet if (!productionMode) { /* Print an information/warning message about running in debug mode */ // TODO Maybe we need a different message for portlets? - System.err.println(NOT_PRODUCTION_MODE_INFO); + logger.warning(NOT_PRODUCTION_MODE_INFO); } } @@ -446,14 +451,11 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet } catch (final SessionExpiredException e) { // TODO Figure out a better way to deal with // SessionExpiredExceptions - System.err.println("Session has expired"); - e.printStackTrace(System.err); + logger.finest("A user session has expired"); } catch (final GeneralSecurityException e) { // TODO Figure out a better way to deal with // GeneralSecurityExceptions - System.err - .println("General security exception, should never happen"); - e.printStackTrace(System.err); + logger.finest("General security exception, the security key was probably incorrect."); } catch (final Throwable e) { handleServiceException(request, response, application, e); } finally { @@ -476,7 +478,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet private void handleUnknownRequest(PortletRequest request, PortletResponse response) { - System.err.println("Unknown request type"); + logger.warning("Unknown request type"); } /** @@ -657,7 +659,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet os.write(buffer, 0, bytes); } } else { - System.err.println("Requested resource [" + resourceID + logger.warning("Requested resource [" + resourceID + "] could not be found"); response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_NOT_FOUND)); @@ -912,7 +914,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet appClass += getApplicationClass().getSimpleName(); } catch (ClassNotFoundException e) { appClass += "unknown"; - e.printStackTrace(); + logger.log(Level.SEVERE, "Could not find application class", e); } String themeClass = "v-theme-" + themeName.replaceAll("[^a-zA-Z0-9]", ""); diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index aedfb2a204..5fe94266eb 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -23,6 +23,8 @@ import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.servlet.ServletContext; import javax.servlet.ServletException; @@ -63,6 +65,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements // TODO Move some (all?) of the constants to a separate interface (shared // with portlet) + private static final Logger logger = Logger + .getLogger(AbstractApplicationServlet.class.getName()); + /** * The version number of this release. For example "6.2.0". Always in the * format "major.minor.revision[.build]". The build part is optional. All of @@ -225,7 +230,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * Print an information/warning message about running with xsrf * protection disabled */ - System.err.println(WARNING_XSRF_PROTECTION_DISABLED); + logger.warning(WARNING_XSRF_PROTECTION_DISABLED); } } @@ -244,7 +249,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements if (!productionMode) { /* Print an information/warning message about running in debug mode */ - System.err.println(NOT_PRODUCTION_MODE_INFO); + logger.warning(NOT_PRODUCTION_MODE_INFO); } } @@ -258,7 +263,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } catch (NumberFormatException nfe) { // Default is 1h resourceCacheTime = 3600; - System.err.println(WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC); + logger.warning(WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC); } } @@ -816,7 +821,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements resultPath = url.getFile(); } catch (final Exception e) { // FIXME: Handle exception - e.printStackTrace(); + logger.log(Level.WARNING, "Could not find resource path " + + path, e); } } return resultPath; @@ -1197,11 +1203,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements if (resourceUrl == null) { // cannot serve requested file - System.err - .println("Requested resource [" - + filename - + "] not found from filesystem or through class loader." - + " Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder."); + logger.severe("Requested resource [" + + filename + + "] not found from filesystem or through class loader." + + " Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder."); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } @@ -1222,7 +1227,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } } catch (Exception e) { // Failed to find out last modified timestamp. Continue without it. - e.printStackTrace(); + logger.log( + Level.FINEST, + "Failed to find out last modified timestamp. Continuing without it.", + e); } // Set type mime type if we can determine it based on the filename @@ -1653,7 +1661,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements try { return getApplicationClass().getSimpleName(); } catch (ClassNotFoundException e) { - e.printStackTrace(); + logger.log(Level.FINER, "getApplicationCSSClassName failed", e); return "unknown"; } } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index b9d6bf99fa..cbaa4b2676 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -35,6 +35,8 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.portlet.PortletRequest; import javax.portlet.PortletResponse; @@ -85,6 +87,9 @@ import com.vaadin.ui.Window; public abstract class AbstractCommunicationManager implements Paintable.RepaintRequestListener, Serializable { + private static final Logger logger = Logger + .getLogger(AbstractCommunicationManager.class.getName()); + /** * Generic interface of a (HTTP or Portlet) request to the application. * @@ -742,9 +747,8 @@ public abstract class AbstractCommunicationManager implements if (window == null) { // This should not happen, no windows exists but // application is still open. - System.err - .println("Warning, could not get window for application with request ID " - + request.getRequestID()); + logger.severe("Warning, could not get window for application with request ID " + + request.getRequestID()); return; } } else { @@ -768,7 +772,8 @@ public abstract class AbstractCommunicationManager implements // FIXME: Handle exception // Not critical, but something is still wrong; print // stacktrace - e2.printStackTrace(); + logger.log(Level.WARNING, + "getSystemMessages() failed - continuing", e2); } if (ci != null) { String msg = ci.getOutOfSyncMessage(); @@ -1036,14 +1041,18 @@ public abstract class AbstractCommunicationManager implements "getSystemMessages", (Class[]) null); ci = (Application.SystemMessages) m.invoke(null, (Object[]) null); - } catch (NoSuchMethodException e1) { - e1.printStackTrace(); + } catch (NoSuchMethodException e) { + logger.log(Level.WARNING, + "getSystemMessages() failed - continuing", e); } catch (IllegalArgumentException e) { - e.printStackTrace(); + logger.log(Level.WARNING, + "getSystemMessages() failed - continuing", e); } catch (IllegalAccessException e) { - e.printStackTrace(); + logger.log(Level.WARNING, + "getSystemMessages() failed - continuing", e); } catch (InvocationTargetException e) { - e.printStackTrace(); + logger.log(Level.WARNING, + "getSystemMessages() failed - continuing", e); } // meta instruction for client to enable auto-forward to @@ -1091,7 +1100,8 @@ public abstract class AbstractCommunicationManager implements is = callback.getThemeResourceAsStream(themeName, resource); } catch (final Exception e) { // FIXME: Handle exception - e.printStackTrace(); + logger.log(Level.FINER, + "Failed to get theme resource stream.", e); } if (is != null) { @@ -1110,16 +1120,15 @@ public abstract class AbstractCommunicationManager implements r.close(); } catch (final java.io.IOException e) { // FIXME: Handle exception - System.err.println("Resource transfer failed: " - + request.getRequestID() + ". (" - + e.getMessage() + ")"); + logger.log(Level.SEVERE, "Resource transfer failed: " + + request.getRequestID() + ".", e); } outWriter.print("\"" + JsonPaintTarget.escapeJSON(layout.toString()) + "\""); } else { // FIXME: Handle exception - System.err.println("CustomLayout not found: " + resource); + logger.severe("CustomLayout not found: " + resource); } } outWriter.print("}"); @@ -1315,7 +1324,7 @@ public abstract class AbstractCommunicationManager implements + variable[VAR_PID]; success = false; } - System.err.println(msg); + logger.warning(msg); continue; } } @@ -1608,9 +1617,8 @@ public abstract class AbstractCommunicationManager implements DateFormat dateFormat = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, l); if (!(dateFormat instanceof SimpleDateFormat)) { - System.err - .println("Unable to get default date pattern for locale " - + l.toString()); + logger.warning("Unable to get default date pattern for locale " + + l.toString()); dateFormat = new SimpleDateFormat(); } final String df = ((SimpleDateFormat) dateFormat).toPattern(); @@ -2098,7 +2106,7 @@ public abstract class AbstractCommunicationManager implements } } - private HashMap<Class<? extends Paintable>, Integer> typeToKey = new HashMap<Class<? extends Paintable>, Integer>(); + private final HashMap<Class<? extends Paintable>, Integer> typeToKey = new HashMap<Class<? extends Paintable>, Integer>(); private int nextTypeKey = 0; String getTagForType(Class<? extends Paintable> class1) { @@ -2118,7 +2126,7 @@ public abstract class AbstractCommunicationManager implements */ class OpenWindowCache implements Serializable { - private Set<Object> res = new HashSet<Object>(); + private final Set<Object> res = new HashSet<Object>(); /** * diff --git a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java index 1baad53dad..0504e02787 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java @@ -12,6 +12,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; @@ -27,6 +29,9 @@ import com.vaadin.terminal.ApplicationResource; public abstract class AbstractWebApplicationContext implements ApplicationContext, HttpSessionBindingListener, Serializable { + private static final Logger logger = Logger + .getLogger(AbstractWebApplicationContext.class.getName()); + protected Collection<TransactionListener> listeners = Collections .synchronizedList(new LinkedList<TransactionListener>()); @@ -128,8 +133,8 @@ public abstract class AbstractWebApplicationContext implements // remove same application here. Possible if you got e.g. session // lifetime 1 min but socket write may take longer than 1 min. // FIXME: Handle exception - System.err.println("Could not remove application, leaking memory."); - e.printStackTrace(); + logger.log(Level.SEVERE, + "Could not remove application, leaking memory.", e); } } diff --git a/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java b/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java index d598b3714f..410fba0ea0 100644 --- a/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java +++ b/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java @@ -6,6 +6,8 @@ package com.vaadin.terminal.gwt.server; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -17,12 +19,15 @@ import com.vaadin.Application; @SuppressWarnings("serial") public class ApplicationRunnerServlet extends AbstractApplicationServlet { + private static final Logger logger = Logger + .getLogger(ApplicationRunnerServlet.class.getName()); + /** * The name of the application class currently used. Only valid within one * request. */ private String[] defaultPackages; - private ThreadLocal<HttpServletRequest> request = new ThreadLocal<HttpServletRequest>(); + private final ThreadLocal<HttpServletRequest> request = new ThreadLocal<HttpServletRequest>(); @Override public void init(ServletConfig servletConfig) throws ServletException { @@ -171,7 +176,10 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { // Ignore as this is expected for many packages } catch (Exception e2) { // TODO: handle exception - e2.printStackTrace(); + logger.log( + Level.FINER, + "Failed to find application class in the default package.", + e2); } if (appClass != null) { return appClass; diff --git a/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java b/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java index 0fce2bdc6a..fd51d66d7c 100644 --- a/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java +++ b/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java @@ -13,6 +13,8 @@ import java.util.List; import java.util.Map; import java.util.Stack; import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.terminal.Sizeable; import com.vaadin.ui.AbstractOrderedLayout; @@ -33,6 +35,9 @@ import com.vaadin.ui.Window; @SuppressWarnings({ "serial", "deprecation" }) public class ComponentSizeValidator implements Serializable { + private final static Logger logger = Logger + .getLogger(ComponentSizeValidator.class.getName()); + private final static int LAYERS_SHOWN = 4; /** @@ -130,7 +135,8 @@ public class ComponentSizeValidator implements Serializable { return parentCanDefineHeight(component); } catch (Exception e) { - e.printStackTrace(); + logger.log(Level.FINER, + "An exception occurred while validating sizes.", e); return true; } } @@ -149,19 +155,20 @@ public class ComponentSizeValidator implements Serializable { return parentCanDefineWidth(component); } catch (Exception e) { - e.printStackTrace(); + logger.log(Level.FINER, + "An exception occurred while validating sizes.", e); return true; } } public static class InvalidLayout implements Serializable { - private Component component; + private final Component component; - private boolean invalidHeight; - private boolean invalidWidth; + private final boolean invalidHeight; + private final boolean invalidWidth; - private Vector<InvalidLayout> subErrors = new Vector<InvalidLayout>(); + private final Vector<InvalidLayout> subErrors = new Vector<InvalidLayout>(); public InvalidLayout(Component component, boolean height, boolean width) { this.component = component; @@ -668,7 +675,8 @@ public class ComponentSizeValidator implements Serializable { return; } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); + logger.log(Level.FINER, + "An exception occurred while validating sizes.", e); } } diff --git a/src/com/vaadin/terminal/gwt/server/Constants.java b/src/com/vaadin/terminal/gwt/server/Constants.java index 2d4135ebf7..b23a9c1284 100644 --- a/src/com/vaadin/terminal/gwt/server/Constants.java +++ b/src/com/vaadin/terminal/gwt/server/Constants.java @@ -11,19 +11,19 @@ package com.vaadin.terminal.gwt.server; */ public interface Constants { - static final String NOT_PRODUCTION_MODE_INFO = "" + static final String NOT_PRODUCTION_MODE_INFO = "\n" + "=================================================================\n" + "Vaadin is running in DEBUG MODE.\nAdd productionMode=true to web.xml " + "to disable debug features.\nTo show debug window, add ?debug to " + "your application URL.\n" + "================================================================="; - static final String WARNING_XSRF_PROTECTION_DISABLED = "" + static final String WARNING_XSRF_PROTECTION_DISABLED = "\n" + "===========================================================\n" + "WARNING: Cross-site request forgery protection is disabled!\n" + "==========================================================="; - static final String WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC = "" + static final String WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC = "\n" + "===========================================================\n" + "WARNING: resourceCacheTime has been set to a non integer value " + "in web.xml. The default of 1h will be used.\n" diff --git a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java index a91018ffde..61e1fcad11 100644 --- a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java +++ b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.server; import java.io.PrintWriter; import java.util.Map; +import java.util.logging.Logger; import com.vaadin.event.Transferable; import com.vaadin.event.TransferableImpl; @@ -22,6 +23,9 @@ import com.vaadin.ui.Component; public class DragAndDropService implements VariableOwner { + private static final Logger logger = Logger + .getLogger(DragAndDropService.class.getName()); + private int lastVisitId; private boolean lastVisitAccepted = false; @@ -41,7 +45,7 @@ public class DragAndDropService implements VariableOwner { // Validate drop handler owner if (!(owner instanceof DropTarget)) { - System.err.println("DropHandler owner " + owner + logger.severe("DropHandler owner " + owner + " must implement DropTarget"); return; } @@ -72,9 +76,8 @@ public class DragAndDropService implements VariableOwner { DropHandler dropHandler = (dropTarget).getDropHandler(); if (dropHandler == null) { // No dropHandler returned so no drop can be performed. - System.err - .println("DropTarget.getDropHandler() returned null for owner: " - + dropTarget); + logger.fine("DropTarget.getDropHandler() returned null for owner: " + + dropTarget); return; } diff --git a/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java index 754cc50d13..47067e5b8d 100644 --- a/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java @@ -9,11 +9,10 @@ import java.io.IOException; import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletException; @@ -256,13 +255,14 @@ public class GAEApplicationServlet extends ApplicationServlet { log.severe("DeadlineExceeded for " + session.getId()); sendDeadlineExceededNotification(request, response); } catch (NotSerializableException e) { - log.severe("NotSerializableException: " + getStackTraceAsString(e)); + log.log(Level.SEVERE, "Not serializable!", e); // TODO this notification is usually not shown - should we redirect // in some other way - can we? sendNotSerializableNotification(request, response); } catch (Exception e) { - log.severe(e + ": " + getStackTraceAsString(e)); + log.log(Level.SEVERE, + "An exception occurred while servicing request.", e); sendCriticalErrorNotification(request, response); } finally { @@ -308,13 +308,15 @@ public class GAEApplicationServlet extends ApplicationServlet { session.setAttribute(WebApplicationContext.class.getName(), applicationContext); } catch (IOException e) { - log.warning("Could not de-serialize ApplicationContext for " - + session.getId() + " A new one will be created. " - + getStackTraceAsString(e)); + log.log(Level.WARNING, + "Could not de-serialize ApplicationContext for " + + session.getId() + + " A new one will be created. ", e); } catch (ClassNotFoundException e) { - log.warning("Could not de-serialize ApplicationContext for " - + session.getId() + " A new one will be created. " - + getStackTraceAsString(e)); + log.log(Level.WARNING, + "Could not de-serialize ApplicationContext for " + + session.getId() + + " A new one will be created. ", e); } } // will create new context if the above did not @@ -395,15 +397,7 @@ public class GAEApplicationServlet extends ApplicationServlet { } } } catch (Exception e) { - log.warning("Exception while cleaning: " + getStackTraceAsString(e)); + log.log(Level.WARNING, "Exception while cleaning.", e); } } - - private String getStackTraceAsString(Throwable t) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - return sw.toString(); - } - } diff --git a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java index b50fc0a8a1..27b9ea4ae9 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java +++ b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java @@ -20,6 +20,8 @@ import java.util.Map; import java.util.Set; import java.util.Stack; import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.Application; import com.vaadin.terminal.ApplicationResource; @@ -51,6 +53,9 @@ import com.vaadin.ui.CustomLayout; @SuppressWarnings("serial") public class JsonPaintTarget implements PaintTarget { + private static final Logger logger = Logger.getLogger(JsonPaintTarget.class + .getName()); + /* Document type declarations */ private final static String UIDL_ARG_NAME = "name"; @@ -67,7 +72,7 @@ public class JsonPaintTarget implements PaintTarget { private int changes = 0; - private Set<Object> usedResources = new HashSet<Object>(); + private final Set<Object> usedResources = new HashSet<Object>(); private boolean customLayoutArgumentsOpen = false; @@ -77,11 +82,11 @@ public class JsonPaintTarget implements PaintTarget { private boolean cacheEnabled = false; - private Collection<Paintable> paintedComponents = new HashSet<Paintable>(); + private final Collection<Paintable> paintedComponents = new HashSet<Paintable>(); private Collection<Paintable> identifiersCreatedDueRefPaint; - private Collection<Class<? extends Paintable>> usedPaintableTypes = new LinkedList<Class<? extends Paintable>>(); + private final Collection<Class<? extends Paintable>> usedPaintableTypes = new LinkedList<Class<? extends Paintable>>(); /** * Creates a new XMLPrintWriter, without automatic line flushing. @@ -1022,11 +1027,10 @@ public class JsonPaintTarget implements PaintTarget { && Paintable.class.isAssignableFrom(superclass)) { class1 = (Class<? extends Paintable>) superclass; } else { - System.out - .append("Warning: no superclass of " - + paintable.getClass().getName() - + " has a @ClientWidget" - + " annotation. Component will not be mapped correctly on client side."); + logger.warning("No superclass of " + + paintable.getClass().getName() + + " has a @ClientWidget" + + " annotation. Component will not be mapped correctly on client side."); break; } } @@ -1077,20 +1081,23 @@ public class JsonPaintTarget implements PaintTarget { // TODO could optize to quit at the end attribute } } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + logger.log( + Level.SEVERE, + "An error occurred while finding widget mapping.", + e1); } finally { try { bufferedReader.close(); } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + logger.log(Level.SEVERE, "Could not close reader.", + e1); } } } catch (Throwable e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); + logger.log(Level.SEVERE, + "An error occurred while finding widget mapping.", + e2); } return false; diff --git a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java index 1b3585cb80..01f2f0b589 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java +++ b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java @@ -10,6 +10,8 @@ import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; @@ -47,6 +49,9 @@ import com.vaadin.ui.Window; @SuppressWarnings("serial") public class PortletApplicationContext2 extends AbstractWebApplicationContext { + private static final Logger logger = Logger + .getLogger(PortletApplicationContext2.class.getName()); + protected Map<Application, Set<PortletListener>> portletListeners = new HashMap<Application, Set<PortletListener>>(); protected transient PortletSession session; @@ -56,11 +61,11 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext { private PortletResponse response; - private Map<String, QName> eventActionDestinationMap = new HashMap<String, QName>(); - private Map<String, Serializable> eventActionValueMap = new HashMap<String, Serializable>(); + private final Map<String, QName> eventActionDestinationMap = new HashMap<String, QName>(); + private final Map<String, Serializable> eventActionValueMap = new HashMap<String, Serializable>(); - private Map<String, String> sharedParameterActionNameMap = new HashMap<String, String>(); - private Map<String, String> sharedParameterActionValueMap = new HashMap<String, String>(); + private final Map<String, String> sharedParameterActionNameMap = new HashMap<String, String>(); + private final Map<String, String> sharedParameterActionValueMap = new HashMap<String, String>(); public File getBaseDirectory() { String resultPath = session.getPortletContext().getRealPath("/"); @@ -72,7 +77,11 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext { return new File(url.getFile()); } catch (final Exception e) { // FIXME: Handle exception - e.printStackTrace(); + logger.log( + Level.FINE, + "Cannot access base directory, possible security issue " + + "with Application Server or Servlet Container", + e); } } return null; diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java b/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java index 890c299cc4..abdf7bd551 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java @@ -196,7 +196,8 @@ public class ClassPathExplorer { } catch (MalformedURLException e) { // should never happen as based on an existing URL, // only changing end of file name/path part - e.printStackTrace(); + logger.log(Level.SEVERE, + "This should never happen!", e); } } } @@ -340,11 +341,9 @@ public class ClassPathExplorer { } } } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.log(Level.FINEST, "Failed to inspect JAR file", e); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.log(Level.FINEST, "Failed to inspect JAR file", e); } return false; @@ -547,7 +546,7 @@ public class ClassPathExplorer { } catch (LinkageError e) { // NOP } catch (Exception e) { - e.printStackTrace(); + logger.log(Level.FINEST, "Could not add class: " + fullclassName, e); } } @@ -582,10 +581,10 @@ public class ClassPathExplorer { try { return new URL("file://" + directory.getCanonicalPath()); } catch (MalformedURLException e) { - e.printStackTrace(); + logger.log(Level.FINEST, "Ignoring exception", e); // ignore: continue to the next classpath entry } catch (IOException e) { - e.printStackTrace(); + logger.log(Level.FINEST, "Ignoring exception", e); // ignore: continue to the next classpath entry } } diff --git a/src/com/vaadin/tools/WidgetsetCompiler.java b/src/com/vaadin/tools/WidgetsetCompiler.java index ab5e4ad9d3..9fe97ba12a 100644 --- a/src/com/vaadin/tools/WidgetsetCompiler.java +++ b/src/com/vaadin/tools/WidgetsetCompiler.java @@ -4,6 +4,8 @@ package com.vaadin.tools; import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.terminal.gwt.widgetsetutils.WidgetSetBuilder; @@ -31,6 +33,9 @@ import com.vaadin.terminal.gwt.widgetsetutils.WidgetSetBuilder; */ public class WidgetsetCompiler { + private static final Logger logger = Logger + .getLogger(WidgetsetCompiler.class.getName()); + /** * @param args * same arguments as for com.google.gwt.dev.Compiler @@ -67,7 +72,8 @@ public class WidgetsetCompiler { String[].class); method.invoke(null, new Object[] { args }); } catch (Throwable thr) { - thr.printStackTrace(); + logger.log(Level.SEVERE, + "Widgetset compilation failed", thr); } } }; @@ -76,7 +82,7 @@ public class WidgetsetCompiler { runThread.join(); System.out.println("Widgetset compilation finished"); } catch (Throwable thr) { - thr.printStackTrace(); + logger.log(Level.SEVERE, "Widgetset compilation failed", thr); } } } diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 9c077bc34e..86c5df41b0 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -17,6 +17,8 @@ import java.util.LinkedList; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.data.Container; import com.vaadin.data.Item; @@ -73,6 +75,9 @@ public class Table extends AbstractSelect implements Action.Container, Container.Ordered, Container.Sortable, ItemClickSource, DragSource, DropTarget { + private static final Logger logger = Logger + .getLogger(Table.class.getName()); + /** * Modes that Table support as drag sourse. */ @@ -2002,7 +2007,8 @@ public class Table extends AbstractSelect implements Action.Container, .get("lastToBeRendered")).intValue(); } catch (Exception e) { // FIXME: Handle exception - e.printStackTrace(); + logger.log(Level.FINER, + "Could not parse the first and/or last rows.", e); } // respect suggested rows only if table is not otherwise updated @@ -2066,7 +2072,8 @@ public class Table extends AbstractSelect implements Action.Container, } } catch (final Exception e) { // FIXME: Handle exception - e.printStackTrace(); + logger.log(Level.FINER, + "Could not determine column collapsing state", e); } clientNeedsContentRefresh = true; } @@ -2084,8 +2091,8 @@ public class Table extends AbstractSelect implements Action.Container, setColumnOrder(idsTemp); } catch (final Exception e) { // FIXME: Handle exception - e.printStackTrace(); - + logger.log(Level.FINER, + "Could not determine column reordering state", e); } clientNeedsContentRefresh = true; } @@ -3820,7 +3827,7 @@ public class Table extends AbstractSelect implements Action.Container, } // The property id of the column which header was pressed - private Object columnPropertyId; + private final Object columnPropertyId; public HeaderClickEvent(Component source, Object propertyId, MouseEventDetails details) { @@ -3860,7 +3867,7 @@ public class Table extends AbstractSelect implements Action.Container, } // The property id of the column which header was pressed - private Object columnPropertyId; + private final Object columnPropertyId; /** * Constructor |