]> source.dussan.org Git - vaadin-framework.git/commitdiff
This is the implementation of the server-side logging feature
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Tue, 12 Oct 2010 05:07:33 +0000 (05:07 +0000)
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Tue, 12 Oct 2010 05:07:33 +0000 (05:07 +0000)
 - 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

17 files changed:
src/com/vaadin/Application.java
src/com/vaadin/data/util/MethodProperty.java
src/com/vaadin/event/ListenerMethod.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java
src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java
src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java
src/com/vaadin/terminal/gwt/server/Constants.java
src/com/vaadin/terminal/gwt/server/DragAndDropService.java
src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java
src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java
src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java
src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java
src/com/vaadin/tools/WidgetsetCompiler.java
src/com/vaadin/ui/Table.java

index 14837fa0f9553e28202b48ae4dd967eaa4499cdd..9650146f531871b0b8dab5f17c48a7717fc89cd1 100644 (file)
@@ -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);
     }
 
     /**
index 394343aaf6c2dc219ceab949d25a2006c2a7a6a6..081833e3612652eacec3168b30b482779af0e8a7 100644 (file)
@@ -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);
         }
     };
 
index b294dbf86d5e7614e6f438ea94e4783c48384e51..8c7aa93f81dc8674e8b039cda25a8bbad0676d40 100644 (file)
@@ -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);
         }
     };
 
index f6a88d91006916117b455e99c150c7cc22c00e8b..407b0dae774de7e36e6db32cd4033538d019de37 100644 (file)
@@ -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]", "");
index aedfb2a204ba6c9756607cb9dc739734be478569..5fe94266eb7373179d210399a41283af7e069563 100644 (file)
@@ -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";
         }
     }
index b9d6bf99fabd77ca15e90af50f0c326bbd00d889..cbaa4b267654b7fffe967d089fb0edd186ced355 100644 (file)
@@ -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>();
 
         /**
          * 
index 1baad53dad3cf640aea7503614a1e9c5fa82ea9d..0504e02787b0e38a1baf5fcf106d2e1531f26064 100644 (file)
@@ -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);
         }
     }
 
index d598b3714f2f6000bd8ab4eab90479de1e6a91bf..410fba0ea064d13e6796a263c6ccc542a5d777b4 100644 (file)
@@ -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;
index 0fce2bdc6affc895303944917b22a322c1b3bed9..fd51d66d7c9ef04bb1b2f30e50ae95559a9d9185 100644 (file)
@@ -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);
             }
 
         }
index 2d4135ebf79bc01e14358a885aa74cf14414693e..b23a9c1284fcec5143d750abff71220ac6ce7002 100644 (file)
@@ -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"
index a91018ffdeb5c62945067ec68d229a021277f24b..61e1fcad111003cd1455d49567cb12fd8b6846e9 100644 (file)
@@ -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;
         }
 
index 754cc50d13b6454e069b5b12a980b10134af805d..47067e5b8dc7b084c8b994da8fa88a7c16049c48 100644 (file)
@@ -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();
-    }
-
 }
index b50fc0a8a186cb578824511b6109430becf7dfa8..27b9ea4ae989ad25bb14ab7db54a019efb8150ae 100644 (file)
@@ -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;
index 1b3585cb80d75dbc94fd3c915dd2b0f2d59bcbdc..01f2f0b589cbe334ed811f098e49a6b1853f81c1 100644 (file)
@@ -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;
index 890c299cc4543f03fb4703f9615454005e634c2e..abdf7bd5516ad8c30a6b7d2a8c3e0efbd296750c 100644 (file)
@@ -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
                 }
             }
index ab5e4ad9d344035ef117b1e0390950732391f594..9fe97ba12aa2cb24ff51054917c57bbb2e1a43f8 100644 (file)
@@ -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);
         }
     }
 }
index 9c077bc34ede548a18f752b653bfa116c7a1eaff..86c5df41b066507e0cd2ca0a4f130448dce0ac2a 100644 (file)
@@ -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