[Yanel-dev] ViewableV2 and exists()

Cedric Staub cedric.staub at wyona.com
Fri Aug 20 09:33:25 CEST 2010


Hello out there

I recently had a problem where I had a ViewableV2 resource whose
exists() function returned false, but Yanel didn't show a 404 error page
but incorrectly returned the view of the resource anyway.

I tracked the problem down to the following file:
src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java

What I believe is happening is the following:
1. Yanel checks if the resource exists (line 489). If the resource does
not exists, we don't do a 404 yet (it is commented out). If I understood
correctly, the reason for this is that if the resource if Versionable or
Workflowable it might still return data.
2. Then we check if the resource is Versionable or Workflowable. If it
is Versionable the request goes through, if it is Workflowable we check
the exists function again, if it is none of the two the request goes
through.

So if a resource is Viewable, but neither Versionable nor Workflowable,
the request can go through even if the resource does not exist. This
looks like a bug to me ;-).

Now, in my opinion, the request should never go through if exists()
returns false; but as I understand there are buggy ViewableV2 resources
out there and we don't want to break them. My suggested solution can be
found in the path attached to this email.

It WorkForMe(TM), but if the patch breaks your resources or molests your
dog then please do tell. Feedback is welcome.

Cheers
Cedric
-------------- next part --------------
Index: src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	(revision 52540)
+++ src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	(working copy)
@@ -534,6 +534,12 @@
                             }
                         } else {
                             view = ((ViewableV2) res).getView(viewId);
+                            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;
+                            }
                         }
                     } catch (org.wyona.yarep.core.NoSuchNodeException e) {
                         String message = e.getMessage();


More information about the Yanel-development mailing list