Re: w3c.jigsaw.filters.CounterFilter problems

Pasquale Di Feo writes:
 > Anselm Baird_Smith wrote:
 > I have restarted the server, but the counter still to 0 (never
 > incremented).
 > 
 > The counter is incremented only if I access direct to 
 > 
 > 	http://127.0.0.1/Overview.html
 > 
 > I have isert a System.out.println into ingoingFilter("OK") method, and
 > into
 > console the message not is displayed when I access to
 > 
 > 	http://127.0.0.1/
 > 

Ok, I finally found the problem, which is due to the new filtering
model. The problem is that lookup (the one that collect filters to be
executed before handling the request) doesn't know about the index, so
any filters set on the index are not call.

Two solutions:

a) Set the filter on the root resource, you can then access the
   counter's value through the piece of state set by the counter
   filter in the request:

   Integer iv = (Integer) request.getState(CounterFilter.STATE_COUNT);
   if ( iv != null )
       int count = iv.intValue();

b) Apply the included patch to the DirectoryResource. This patch fixes
   the way DirectoryResource lookup the index (if any), and also
   contains some cleanupo that should have been done a long time ago.

Anselm.

=== cvs -d /afs/w3.org/CVS-Repository diff -u DirectoryResource.java

Index: DirectoryResource.java
===================================================================
RCS file: /afs/w3.org/CVS-Repository/WWW/Jigsaw/src/classes/w3c/jigsaw/resources/DirectoryResource.java,v
retrieving revision 1.21
diff -u -r1.21 DirectoryResource.java
--- DirectoryResource.java	1996/10/01 18:46:48	1.21
+++ DirectoryResource.java	1996/10/22 07:05:46
@@ -629,15 +629,8 @@
 	throws HTTPException
     {
 	// Give a chance to our super-class to run its own lookup scheme:
-	if ( super.lookup(ls, lr) )
-	    return true;
-	// Perform our own lookup on the next component:
-	String       name     = ls.getNextComponent() ;
-	HTTPResource resource = lookup(name) ;
-	// Check that directory lookups end with a slash:
-	if ((! ls.hasMoreComponents()) 
-	    && ( resource instanceof DirectoryResource ) ) {
-	    if ( ! ls.isDirectory() && ! ls.isInternal()) {
+	if ( super.lookup(ls, lr) ) {
+	    if ( ! ls.isDirectory() && ! ls.isInternal() ) {
 		// The directory lookup URL doesn't end with a slash:
 		Request request = ls.getRequest() ;
 		if ( request == null ) {
@@ -645,12 +638,12 @@
 		    return true;
 		}
 		// Emit an appropriate relocation or error
-		String url = resource.getURL() ;
+		String url = getURL() ;
 		String msg = "Invalid requested URL: the directory resource "
 		    + " you are trying to reach is available only through "
 		    + " its full URL: <a href=\""
 		    + url + "\">" + url + "</a>.";
-		if ( ((DirectoryResource) resource).getRelocateFlag() ) {
+		if ( getRelocateFlag() ) {
 		    // Emit an error (with reloc if allowed)
 		    Reply reloc = request.makeReply(HTTP.MOVED_TEMPORARILY);
 		    reloc.setContent(msg) ;
@@ -665,9 +658,19 @@
 		    lr.setReply(error);
 		    return true;
 		}
-	    }
-	} 
-	// Lookup succeeded normally, continue:
+	    } else {
+		String index = getIndex();
+		if ( index != null ) {
+		    HTTPResource rindex = lookup(index) ;
+		    if ( rindex != null ) 
+			return rindex.lookup(ls, lr);
+		}
+	    } 
+	    return true;
+	}
+	// Perform our own lookup on the next component:
+	String       name     = ls.getNextComponent() ;
+	HTTPResource resource = lookup(name) ;
 	lr.setTarget(resource);
 	return (resource != null ) ? resource.lookup(ls, lr) : false;
     }
@@ -810,35 +813,6 @@
 	HTTPResource resource = lookup(child);
 	if ( resource != null )
 	    resource.delete();
-    }
-
-    /**
-     * Perform requests on a directory.
-     * If an index has been given , this method delegates the actual handling
-     * of the request to it.
-     * @param request The request to handle.
-     */
-
-    public Reply perform(Request request, HTTPFilter filters[]) 
-	throws HTTPException, ClientException
-    {
-	String index = getIndex() ;
-	if ( index != null ) {
-	    HTTPResource rindex = lookup(index) ;
-	    if ( rindex == null ) {
-		Reply error = request.makeReply(HTTP.NOT_FOUND) ;
-		error.setContent("The index ["
-				 + index
-				 + "] for this directory doesn't exist."
-				 + " The server is misconfigured.");
-		throw new HTTPException(error);
-	    }
-	    // Get the original reply, add a content location header:
-	    Reply reply = rindex.perform(request, filters);
-	    reply.setContentLocation(rindex.getURL());
-	    return reply;
-	}
-	return super.perform(request, filters) ;
     }
 
     /**

Received on Tuesday, 22 October 1996 03:15:44 UTC