Re: Q: how to get jigadm to recognize new resource?

On Fri, 13 Nov 1998, Jeff Van Epps wrote:

> Okay, it looks like it's time to try customizing the source.
> 
> I want to create a directory node with this behavior:
> 
> - if child file exists, return it just like normal
> - if not, return instead contents of a different URL
> 
> Example: directory called "bands". If "bands/119" exists (it'll be an HTML
> file), return it. If not, invoke "/music/query.cgi?band=119".
> 
> [query.cgi is actually a servlet I've already got working (.cgi is
> misnomer)]
> 
> I wasn't sure where to start. I thought of different possibilities:
> 
> - extend DirectoryResource
> - create a new Frame
> - subclass RedirecterFrame
> 
> In the end I chose to subclass HttpDirectoryResource:
> 
> ============
> package org.w3c.jigsaw.resources ;
> 
> import java.util.*;
> import java.io.*;
> import java.net.*;
> import org.w3c.tools.resources.LookupResult;
> import org.w3c.tools.resources.LookupState;
> import org.w3c.tools.resources.ProtocolException;
> import org.w3c.www.http.*;
> import org.w3c.jigsaw.http.*;
> 
> public class BandResource extends HttpDirectoryResource
> {
>     // Don't have any attributes, so the code which deals with the
>     // attribute registry is omitted.
> 
> 
>     public boolean lookup( LookupState ls, LookupResult lr )
>         throws ProtocolException
>     {
>         Request     req;
>         Reply       reply;
>         String      band;
>         String      newurl;
> 
>         if ( super.lookup( ls, lr ) )
>         {
>             return true;
>         }
>         req = (Request) ls.getRequest();
>         if ( req == null || ! req.getMethod().equals( "GET" ) )
>         {
>             return false;
>         }
>         reply = req.makeReply( HTTP.TEMPORARY_REDIRECT );
>         band = ls.getRemainingPath();
>         band = ( band == null ) ? "null" : band;
>         newurl = getServer().getURL() + "/music/query.cgi?band=" + band;
>         System.out.println( "redir to " + newurl );
>         try
>         {
>             reply.setLocation( new URL( newurl ) );
>         } catch( Exception e )
>         {
>             e.printStackTrace();
>         }
>         reply.setContent( "Try " + newurl );
>         lr.setReply( reply );
>         return true;
>     }
> }
> ============
> 
> This compiled, but it doesn't show up in jigadm as a choice for resource
> type.
> Hunting around in the source, there appear to be property files which need
> to
> be edited to include the new class (I must have missed this in the
> documentation
> on how to compile and install a resource - I still can't find it). I looked
> for HttpDirectoryResource, and found it in two ResourceHelper.p files, so I
> added BandResource right after it in both. But jigadm now refuses to show me
> ANY resource helper, always throwing an exception claiming that there was a
> configuration error, no editor for whatever resource I selected.

In Jigsaw/Jigsaw/config, you have jigadm.zip
In this zip you have the
org.w3c.tools.resources.ContainerResource/helpers/org.w3c.jigadm.editors.ResourcesHelper.p
file
Add your resource there, in the list. But it is not mandatory to do that,
you can directly type the class of your resource in the textfield over the
pull down menu.

> 
> Beyond that, I would appreciate any comments on whether this is the correct
> approach to solve the problem.


Well, for that problem, I would have created a Filter, this filter
attached to the HTTP frame would have filtered out 404 not found answers
(so it is an mainly an outgoing filter). If the result is a 404, then
transform the reply to be a redirect to the query page. Put the filter on
the right directory as it will affect the subdirectories.
Regards,

      /\          - Yves Lafon - World Wide Web Consortium - 
  /\ /  \        Architecture Domain - Jigsaw Activity Leader
 /  \    \/\    
/    \   /  \   http://www.w3.org/People/Lafon - ylafon@w3.org    

Received on Monday, 16 November 1998 01:28:14 UTC