wyona/yanel — Issue #15: Configurable Strict exists() checking (ViewableV2)
Author: michaelwechner
Created: 2012-02-21 12:24:38+00:00
State: open

This patch introduces a new setting (viewable.strict-exists) to web.xml, which
allows one to turn on strict exists() checking of ViewableV2 resources. Up to
now, if a ViewableV2 resource's exist() function returned false, the request
was still completed. This is because some resources don't implement exists()
properly. But in some situations this is undesireable: so this patch makes it
configurable ;-).

Index: src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	(revision 52644)
+++ src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	(working copy)
@@ -130,6 +130,7 @@
private YanelHTMLUI yanelUI;

private boolean logAccessEnabled = false;
+ private boolean strictExistsChecking = false;

public static final String DEFAULT_ENCODING = "UTF-8";

@@ -178,6 +179,15 @@

// TODO: Make this value configurable also per realm or per individual user!
logAccessEnabled = new Boolean(config.getInitParameter("log-access")).booleanValue();
+ // INFO: This enables strict exists() checking, which means that if a resource's exists()
+ // function returns false, we ALWAYS return a 404 not found error. This is configurable
+ // because some resources are buggy and do not implement exists() correctly.
+ try {
+ strictExistsChecking = new Boolean(config.getInitParameter("viewable.strict-exists")).booleanValue();
+ } catch(Exception e) {
+ log.error(e, e);
+ strictExistsChecking = false;
+ }

if (yanelInstance.isSchedulerEnabled()) {
log.warn("Startup scheduler ...");
@@ -489,8 +499,16 @@
if (!((ViewableV2) res).exists()) {
log.warn("No such ViewableV2 resource: " + res.getPath());
log.warn("TODO: It seems like many ViewableV2 resources are not implementing exists() properly!");
- //do404(request, response, doc, res.getPath());
- //return;
+ if(strictExistsChecking) {
+ // INFO: Many ViewableV2 resource are not implementing exists() correctly,
+ // hence the reason that this is configurable. The "correct" way would be to
+ // always product a 404, but alas, we don't want to break backwards-compatibility.
+ log.warn("Strict exists() checking is enabled, responding with 404 not found.");
+ do404(request, response, doc, res.getPath());
+ return;
+ } else {
+ log.warn("Strict exists() checking is disabled, continuing to process request.");
+ }
}

size = ((ViewableV2) res).getSize();
Index: src/webapp/WEB-INF/web.xml
===================================================================
--- src/webapp/WEB-INF/web.xml	(revision 52644)
+++ src/webapp/WEB-INF/web.xml	(working copy)
@@ -60,6 +60,16 @@

+
+
+ viewable.strict-exists
+ false
+
+

static-content-cache-expires