users@grizzly.java.net

Confusion around GrizzlyWebServer, GrizzlyAdapter, and serving static resources

From: Jonathan Gold <jgold.bg_at_gmail.com>
Date: Tue, 10 Nov 2009 09:32:34 -0800

I'm trying to use GrizzlyWebServer to serve dynamic requests (serviced by my
sublcass of GrizzlyAdapter) from uri path '/dynamic' and static resources from
'/www'. I've tried various combinations of things as illustrated in the
tutorials and in the javadocs online, but am not having success.

What I'm finding:

    - If I do this:

        GrizzlyWebServer gws = new GrizzlyWebServer( port, docRoot );
      
      then I get a webserver that will serve the static files, but of course no
      dynamic ones since I haven't added the adapter.

    - If I do this:

        GrizzlyWebServer gws = new GrizzlyWebServer( port, docRoot );
        gws.addGrizzlyAdapter( adapter, new String[] { "/dynamic" } );

      then I can handle dynamic requests but static resources come back as not
      found (nor could I have their uri root be /www)
    
    - If I do this:
        
        GrizzlyWebServer gws = new GrizzlyWebServer( port );
        adapter.setResourcesContextPath( "/www" );
        adapter.setRootFolder( docRoot );
        gws.addGrizzlyAdapter( adapter, new String[] { "/dynamic" } );
      
      then I can serve dynamic requests but get a 404 for static files.
      Additionally, javac warns that setRootFolder() is deprecated, though the
      javadocs don't say so nor do they mention what I should use instead. I
      looked in the source and saw this:

        /**
         * Set the directory from where files will be serviced.
         *
         * NOTE: For backward compatibility, invoking that method will
         * clear all previous values added using {_at_link #addRootFolder}.
         *
         * @param rootFolder the directory from where files will be serviced.
         *
         * @deprecated - use {_at_link #addRootFolders}
         */
        public void setRootFolder(String rootFolder) {
            rootFolders.clear();
            addRootFolder(rootFolder);
        }
 
      It looks like the target of the @link tag is a typo. There is a method
      addRootFolder (singular), but for reasons I don't understand, it does not
      show up in the javadocs online.

Can someone can help me understand what's happening here? I'm using
grizzly-1.9.18e which I got from the dev site as the latest stable release.

jon