]> source.dussan.org Git - vaadin-framework.git/commitdiff
#4569 - criticalNotification can only be used in UIDL requests
authorArtur Signell <artur.signell@itmill.com>
Mon, 24 May 2010 09:17:12 +0000 (09:17 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 24 May 2010 09:17:12 +0000 (09:17 +0000)
 * Errors are now logged even if criticalNotification should fail
 * CriticalNotification produces an HTML page for non-UIDL requests

svn changeset:13313/svn branch:6.3

src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java

index 249fe75938b2788ce326fdf799224a0d5c91ccde..77abc91b2fa70735096e40c9c4e925933a9a9711 100644 (file)
@@ -628,41 +628,81 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
             HttpServletResponse response, String caption, String message,
             String details, String url) throws IOException {
 
-        if (!isUIDLRequest(request)) {
-            throw new RuntimeException(
-                    "criticalNotification can only be used in UIDL requests");
-        }
+        if (isUIDLRequest(request)) {
 
-        if (caption != null) {
-            caption = "\"" + JsonPaintTarget.escapeJSON(caption) + "\"";
-        }
-        if (details != null) {
-            if (message == null) {
-                message = details;
-            } else {
-                message += "<br/><br/>" + details;
+            if (caption != null) {
+                caption = "\"" + JsonPaintTarget.escapeJSON(caption) + "\"";
+            }
+            if (details != null) {
+                if (message == null) {
+                    message = details;
+                } else {
+                    message += "<br/><br/>" + details;
+                }
             }
-        }
 
-        if (message != null) {
-            message = "\"" + JsonPaintTarget.escapeJSON(message) + "\"";
-        }
-        if (url != null) {
-            url = "\"" + JsonPaintTarget.escapeJSON(url) + "\"";
+            if (message != null) {
+                message = "\"" + JsonPaintTarget.escapeJSON(message) + "\"";
+            }
+            if (url != null) {
+                url = "\"" + JsonPaintTarget.escapeJSON(url) + "\"";
+            }
+
+            String output = "for(;;);[{\"changes\":[], \"meta\" : {"
+                    + "\"appError\": {" + "\"caption\":" + caption + ","
+                    + "\"message\" : " + message + "," + "\"url\" : " + url
+                    + "}}, \"resources\": {}, \"locales\":[]}]";
+            writeResponse(response, "application/json; charset=UTF-8", output);
+        } else {
+            // Create an HTML reponse with the error
+            String output = "";
+
+            if (url != null) {
+                output += "<a href=\"" + url + "\">";
+            }
+            if (caption != null) {
+                output += "<b>" + caption + "</b><br/>";
+            }
+            if (message != null) {
+                output += message;
+                output += "<br/><br/>";
+            }
+
+            if (details != null) {
+                output += details;
+                output += "<br/><br/>";
+            }
+            if (url != null) {
+                output += "</a>";
+            }
+            writeResponse(response, "text/html; charset=UTF-8", output);
+
         }
 
-        // Set the response type
-        response.setContentType("application/json; charset=UTF-8");
+    }
+
+    /**
+     * Writes the response in {@code output} using the contentType given in
+     * {@code contentType} to the provided {@link HttpServletResponse}
+     * 
+     * @param response
+     * @param contentType
+     * @param output
+     *            Output to write (UTF-8 encoded)
+     * @throws IOException
+     */
+    private void writeResponse(HttpServletResponse response,
+            String contentType, String output) throws IOException {
+        response.setContentType(contentType);
         final ServletOutputStream out = response.getOutputStream();
+        // Set the response type
         final PrintWriter outWriter = new PrintWriter(new BufferedWriter(
                 new OutputStreamWriter(out, "UTF-8")));
-        outWriter.print("for(;;);[{\"changes\":[], \"meta\" : {"
-                + "\"appError\": {" + "\"caption\":" + caption + ","
-                + "\"message\" : " + message + "," + "\"url\" : " + url
-                + "}}, \"resources\": {}, \"locales\":[]}]");
+        outWriter.print(output);
         outWriter.flush();
         outWriter.close();
         out.flush();
+
     }
 
     /**
index 0b84990508217a01cfbd006585c89de5e875a0f9..5709bc6a8de80bce9b3632d9485b49db8637e2ae 100644 (file)
@@ -258,13 +258,15 @@ public class GAEApplicationServlet extends ApplicationServlet {
             log.severe("DeadlineExceeded for " + session.getId());
             sendDeadlineExceededNotification(request, response);
         } catch (NotSerializableException e) {
+            log.severe("NotSerializableException: " + getStackTraceAsString(e));
+
             // TODO this notification is usually not shown - should we redirect
             // in some other way - can we?
             sendNotSerializableNotification(request, response);
-            log.severe("NotSerializableException: " + getStackTraceAsString(e));
         } catch (Exception e) {
-            sendCriticalErrorNotification(request, response);
             log.severe(e + ": " + getStackTraceAsString(e));
+
+            sendCriticalErrorNotification(request, response);
         } finally {
             // "Next, please!"
             if (locked) {