From e8d94982e41a6495b64fd1fd573db26351f2c0c4 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Thu, 28 Apr 2011 18:01:48 +0000 Subject: [PATCH] * Console: Try to prevent cascaded IllegalStateExceptions in .jsp code; add logging for original error --- apps/routerconsole/jsp/flags.jsp | 31 +++++++++++++++----------- apps/routerconsole/jsp/viewhistory.jsp | 9 +++++++- apps/routerconsole/jsp/viewtheme.jsp | 9 +++++++- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/apps/routerconsole/jsp/flags.jsp b/apps/routerconsole/jsp/flags.jsp index 153b4c2f27..7148782e31 100644 --- a/apps/routerconsole/jsp/flags.jsp +++ b/apps/routerconsole/jsp/flags.jsp @@ -11,7 +11,6 @@ * flags.jsp?c=de => icons/flags/de.png * with headers set so the browser caches. */ -boolean rendered = false; String c = request.getParameter("c"); if (c != null && c.length() > 0) { java.io.OutputStream cout = response.getOutputStream(); @@ -38,17 +37,23 @@ if (c != null && c.length() > 0) { response.setContentType("image/png"); try { net.i2p.util.FileUtil.readFile(file, base, cout); - rendered = true; - } catch (java.io.IOException ioe) {} - if (rendered) - cout.close(); + } catch (java.io.IOException ioe) { + // prevent 'Committed' IllegalStateException from Jetty + if (!response.isCommitted()) { + response.sendError(403, ioe.toString()); + } else { + net.i2p.I2PAppContext.getGlobalContext().logManager().getLog(getClass()).error("Error serving flags/" + c + ".png", ioe); + // Jetty doesn't log this + throw ioe; + } + } +} else { + /* + * Send a 403 instead of a 404, because the server sends error.jsp + * for 404 errors, complete with the summary bar, which would be + * a huge load for a page full of flags if the user didn't have the + * flags directory for some reason. + */ + response.sendError(403, "No flag specified"); } -/* - * Send a 403 instead of a 404, because the server sends error.jsp - * for 404 errors, complete with the summary bar, which would be - * a huge load for a page full of flags if the user didn't have the - * flags directory for some reason. - */ -if (!rendered) - response.sendError(403, "Flag not found"); %> \ No newline at end of file diff --git a/apps/routerconsole/jsp/viewhistory.jsp b/apps/routerconsole/jsp/viewhistory.jsp index 14ee0bbffa..aa3ce4d545 100644 --- a/apps/routerconsole/jsp/viewhistory.jsp +++ b/apps/routerconsole/jsp/viewhistory.jsp @@ -11,6 +11,13 @@ String base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsoluteP try { net.i2p.util.FileUtil.readFile("history.txt", base, response.getOutputStream()); } catch (java.io.IOException ioe) { - response.sendError(403, ioe.toString()); + // prevent 'Committed' IllegalStateException from Jetty + if (!response.isCommitted()) { + response.sendError(403, ioe.toString()); + } else { + net.i2p.I2PAppContext.getGlobalContext().logManager().getLog(getClass()).error("Error serving history.txt", ioe); + // Jetty doesn't log this + throw ioe; + } } %> \ No newline at end of file diff --git a/apps/routerconsole/jsp/viewtheme.jsp b/apps/routerconsole/jsp/viewtheme.jsp index 814705e142..ce1a6fe380 100644 --- a/apps/routerconsole/jsp/viewtheme.jsp +++ b/apps/routerconsole/jsp/viewtheme.jsp @@ -63,6 +63,13 @@ if (length > 0) try { net.i2p.util.FileUtil.readFile(uri, base, response.getOutputStream()); } catch (java.io.IOException ioe) { - response.sendError(403, ioe.toString()); + // prevent 'Committed' IllegalStateException from Jetty + if (!response.isCommitted()) { + response.sendError(403, ioe.toString()); + } else { + net.i2p.I2PAppContext.getGlobalContext().logManager().getLog(getClass()).error("Error serving " + uri, ioe); + // Jetty doesn't log this + throw ioe; + } } %> \ No newline at end of file -- GitLab