From 2623b9c01ca4e99929218f63a63bff7220322610 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 24 May 2010 09:17:12 +0000 Subject: [PATCH] #4569 - criticalNotification can only be used in UIDL requests * 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 --- .../server/AbstractApplicationServlet.java | 88 ++++++++++++++----- .../gwt/server/GAEApplicationServlet.java | 6 +- 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 249fe75938..77abc91b2f 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -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 += "

" + details; + if (caption != null) { + caption = "\"" + JsonPaintTarget.escapeJSON(caption) + "\""; + } + if (details != null) { + if (message == null) { + message = details; + } else { + message += "

" + 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 += ""; + } + if (caption != null) { + output += "" + caption + "
"; + } + if (message != null) { + output += message; + output += "

"; + } + + if (details != null) { + output += details; + output += "

"; + } + if (url != null) { + output += "
"; + } + 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(); + } /** diff --git a/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java index 0b84990508..5709bc6a8d 100644 --- a/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/GAEApplicationServlet.java @@ -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) { -- 2.39.5