Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369216

Summary: relativeResourceBase for the Default Servlet cannot be used in Jetty 7.6
Product: [RT] Jetty Reporter: Grumpy LittleTed <grumpylittleted>
Component: buildAssignee: Jesse McConnell <jesse.mcconnell>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: gregw, jetty-inbox
Version: unspecified   
Target Milestone: 7.5.x   
Hardware: All   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Grumpy LittleTed CLA 2012-01-20 07:43:31 EST
Build Identifier: 7.6

The init code for the DefaultServlet contains these lines
 if (resourceCache!=null)
            {
                if (max_cache_size!=-1 || max_cached_file_size!= -2 || max_cached_files!=-2)
                    LOG.debug("ignoring resource cache configuration, using resourceCache attribute");
                //                if (_relativeResourceBase!=null || _resourceBase!=null) //CHANGED - REMOVE FOR FIX
                //    throw new UnavailableException("resourceCache specified with resource bases"); //CHANGED - REMOVE FOR FIX
                _cache=(ResourceCache)_servletContext.getAttribute(resourceCache);

                LOG.debug("Cache {}={}",resourceCache,_cache);
            }

But the default webdefault.xml means that resourceCache will not be null so if relativeResourceBase has been specified as an init parameter the exception will always be thrown. If the lines I have marked as //CHANGED are removed the code works like the Default Servlet in Jetty 6 - caching works fine according to my tests. 

I should add that I'm not sure why the " if (_relativeResourceBase!=null || _resourceBase!=null) " guard was added.

I'm marking this as a Major severity since it prevents any site using this feature cannot be migrated from Jetty 6.

Reproducible: Always

Steps to Reproduce:
1. Add a relativeResourceBase to a web.xml
2. Watch the exception always being thrown!
Comment 1 Greg Wilkins CLA 2012-01-22 21:11:36 EST
Grumpy Ted,

The relativeResourceBase feature was intended to be used when using the default server as an extra servlet in a webapp (eg to serve a subdirectory) and not when modifying the default servlet defined in webdefault.xml

However, the shared resource cache mechanism need not be turned on by default either.  I'll turn that feature off in the default webdefault.xml
Comment 2 Greg Wilkins CLA 2012-01-22 22:41:20 EST
webdefault change committed
Comment 3 Grumpy LittleTed CLA 2012-01-23 06:30:33 EST
Thanks for a prompt response/fix.

If caching is being turned off when relativeResourceBase is used this will affect performance. So if we want to continue to use caching and the Default Servlet and constrain serving static files to a specific subdirectory how should we do this?

For example if the URL is /a/b/c.html and the real path is /x/y/z/a/b/c.html we could previously have used relativeResourceBase to rebase. So is there a simpler/better way to do this. Primarily I am concerned about not accidentally serving files from other subdirectories through some future change to the configuration which opens up more directories than intended.