]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed #1673
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 30 May 2008 17:52:52 +0000 (17:52 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 30 May 2008 17:52:52 +0000 (17:52 +0000)
svn changeset:4720/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java
src/com/itmill/toolkit/tests/tickets/Ticket1673.java [new file with mode: 0644]

index bcaedf111bf15a3561d41b9a0133dd7c12bf7e7d..36d7550b72983b24059e541e8e526533abc1969a 100644 (file)
@@ -12,6 +12,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -33,6 +34,7 @@ import javax.servlet.http.HttpSession;
 import org.xml.sax.SAXException;
 
 import com.itmill.toolkit.Application;
+import com.itmill.toolkit.Application.SystemMessages;
 import com.itmill.toolkit.external.org.apache.commons.fileupload.servlet.ServletFileUpload;
 import com.itmill.toolkit.service.FileTypeResolver;
 import com.itmill.toolkit.terminal.DownloadStream;
@@ -502,16 +504,7 @@ public class ApplicationServlet extends HttpServlet {
 
         } catch (final SessionExpired e) {
             // Session has expired, notify user
-            Application.SystemMessages ci = Application.getSystemMessages();
-            try {
-                Method m = applicationClass
-                        .getMethod("getSystemMessages", null);
-                ci = (Application.SystemMessages) m.invoke(null, null);
-            } catch (Exception e2) {
-                // Not critical, but something is still wrong; print stacktrace
-                e2.printStackTrace();
-            }
-
+            Application.SystemMessages ci = getSystemMessages();
             if (!UIDLrequest) {
                 // 'plain' http req - e.g. browser reload;
                 // just go ahead redirect the browser
@@ -527,16 +520,7 @@ public class ApplicationServlet extends HttpServlet {
             e.printStackTrace();
             // if this was an UIDL request, response UIDL back to client
             if (UIDLrequest) {
-                Application.SystemMessages ci = Application.getSystemMessages();
-                try {
-                    Method m = applicationClass.getMethod("getSystemMessages",
-                            null);
-                    ci = (Application.SystemMessages) m.invoke(null, null);
-                } catch (Exception e2) {
-                    // Not critical, but something is still wrong; print
-                    // stacktrace
-                    e2.printStackTrace();
-                }
+                Application.SystemMessages ci = getSystemMessages();
                 criticalNotification(request, response, ci
                         .getInternalErrorCaption(), ci
                         .getInternalErrorMessage(), ci.getInternalErrorURL());
@@ -553,6 +537,39 @@ public class ApplicationServlet extends HttpServlet {
         }
     }
 
+    /** Get system messages from the current application class */
+    private SystemMessages getSystemMessages() {
+        try {
+            Class appCls = applicationClass;
+            if (isApplicationRunnerServlet) {
+                appCls = getClass().getClassLoader().loadClass(
+                        applicationRunnerClassname);
+            }
+            Method m = appCls.getMethod("getSystemMessages", null);
+            return (Application.SystemMessages) m.invoke(null, null);
+        } catch (ClassNotFoundException e) {
+            // This should never happen
+            e.printStackTrace();
+        } catch (SecurityException e) {
+            e.printStackTrace();
+            System.out
+                    .print("Error: getSystemMessage() should be static public");
+        } catch (NoSuchMethodException e) {
+            // This is completely ok and should be silently ignored
+        } catch (IllegalArgumentException e) {
+            // This should never happen
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+            System.out
+                    .print("Error: getSystemMessage() should be static public");
+        } catch (InvocationTargetException e) {
+            // This should never happen
+            e.printStackTrace();
+        }
+        return Application.getSystemMessages();
+    }
+
     /**
      * Serve resources in ITMILL directory if requested.
      * 
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1673.java b/src/com/itmill/toolkit/tests/tickets/Ticket1673.java
new file mode 100644 (file)
index 0000000..320412d
--- /dev/null
@@ -0,0 +1,27 @@
+package com.itmill.toolkit.tests.tickets;\r
+\r
+import com.itmill.toolkit.Application;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.Window;\r
+\r
+public class Ticket1673 extends com.itmill.toolkit.Application {\r
+\r
+    public void init() {\r
+\r
+        final Window main = new Window("#1673");\r
+        setMainWindow(main);\r
+\r
+        main.addComponent(new Button("close", this, "close"));\r
+\r
+    }\r
+\r
+    public static Application.SystemMessages getSystemMessages() {\r
+        Application.CustomizedSystemMessages msgs = new Application.CustomizedSystemMessages();\r
+\r
+        msgs.setSessionExpiredURL("http://www.itmill.com/");\r
+        msgs.setSessionExpiredCaption("Foo");\r
+        msgs.setSessionExpiredMessage("Bar");\r
+\r
+        return msgs;\r
+    }\r
+}\r