Bug 274251 Dispatch to welcome files which are servlets with no matching static resource
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@240 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
c170801600
commit
64eb0863b1
|
@ -1,5 +1,6 @@
|
|||
jetty-7.0.0.M3-SNAPSHOT
|
||||
+ fixed race with expired async listeners
|
||||
+ 274251 Allow dispatch to welcome files that are servlets (configurable)
|
||||
|
||||
jetty-7.0.0.M2 18 May 2009
|
||||
+ JETTY-937 Work around Sun JVM bugs
|
||||
|
|
|
@ -324,6 +324,18 @@ public class PathMap extends HashMap implements Externalizable
|
|||
return LazyList.getList(getLazyMatches(path));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
/** Return whether the path matches any entries in the PathMap,
|
||||
* excluding the default entry
|
||||
* @param path Path to match
|
||||
* @return Whether the PathMap contains any entries that match this
|
||||
*/
|
||||
public boolean containsMatch(String path)
|
||||
{
|
||||
Entry match = getMatch(path);
|
||||
return match!=null && !match.equals(_default);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
public synchronized Object remove(Object pathSpec)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
|
|
|
@ -72,6 +72,13 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
|
|||
* dirAllowed If true, directory listings are returned if no
|
||||
* welcome file is found. Else 403 Forbidden.
|
||||
*
|
||||
* welcomeServlets If true, attempt to dispatch to welcome files
|
||||
* that are servlets, but only after no matching static
|
||||
* resources could be found.
|
||||
*
|
||||
* This must be false if you want directory listings,
|
||||
* but have index.jsp in your welcome file list.
|
||||
*
|
||||
* redirectWelcome If true, welcome files are redirected rather than
|
||||
* forwarded to.
|
||||
*
|
||||
|
@ -119,6 +126,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
|
||||
private boolean _acceptRanges=true;
|
||||
private boolean _dirAllowed=true;
|
||||
private boolean _welcomeServlets=false;
|
||||
private boolean _redirectWelcome=false;
|
||||
private boolean _gzip=true;
|
||||
|
||||
|
@ -152,6 +160,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
|
||||
_acceptRanges=getInitBoolean("acceptRanges",_acceptRanges);
|
||||
_dirAllowed=getInitBoolean("dirAllowed",_dirAllowed);
|
||||
_welcomeServlets=getInitBoolean("welcomeServlets", _welcomeServlets);
|
||||
_redirectWelcome=getInitBoolean("redirectWelcome",_redirectWelcome);
|
||||
_gzip=getInitBoolean("gzip",_gzip);
|
||||
|
||||
|
@ -521,7 +530,8 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
/**
|
||||
* Finds a matching welcome file for the supplied {@link Resource}. This will be the first entry in the list of
|
||||
* configured {@link #_welcomes welcome files} that existing within the directory referenced by the <code>Resource</code>.
|
||||
* If the resource is not a directory, or no matching file is found, then <code>null</code> is returned.
|
||||
* If the resource is not a directory, or no matching file is found, then it may look for a valid servlet mapping.
|
||||
* If there is none, then <code>null</code> is returned.
|
||||
* The list of welcome files is read from the {@link ContextHandler} for this servlet, or
|
||||
* <code>"index.jsp" , "index.html"</code> if that is <code>null</code>.
|
||||
* @param resource
|
||||
|
@ -541,6 +551,16 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
return _welcomes[i];
|
||||
}
|
||||
|
||||
if (_welcomeServlets)
|
||||
{
|
||||
ServletHandler servletHandler = (ServletHandler)_contextHandler.getChildHandlerByClass(ServletHandler.class);
|
||||
for (int i=0;i<_welcomes.length;i++)
|
||||
{
|
||||
if (servletHandler.matchesPath(_welcomes[i]))
|
||||
return _welcomes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -236,6 +236,16 @@ public class ServletHandler extends ScopedHandler
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Whether there is a ServletHolder that matches this path
|
||||
* @param pathInContext Path within _context.
|
||||
* @return whether there is a ServletHolder that matches this path
|
||||
*/
|
||||
public boolean matchesPath(String pathInContext)
|
||||
{
|
||||
return _servletPathMap.containsMatch(pathInContext);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param uriInContext uri to get dispatcher for
|
||||
* @return A {@link RequestDispatcher dispatcher} wrapping the resource at <code>uriInContext</code>,
|
||||
|
|
|
@ -81,6 +81,10 @@
|
|||
<!-- dirAllowed If true, directory listings are returned if no -->
|
||||
<!-- welcome file is found. Else 403 Forbidden. -->
|
||||
<!-- -->
|
||||
<!-- welcomeServlets If true, attempt to dispatch to welcome files -->
|
||||
<!-- that are servlets, if no matching static -->
|
||||
<!-- resources can be found. -->
|
||||
<!-- -->
|
||||
<!-- redirectWelcome If true, redirect welcome file requests -->
|
||||
<!-- else use request dispatcher forwards -->
|
||||
<!-- -->
|
||||
|
@ -129,6 +133,10 @@
|
|||
<param-name>dirAllowed</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>welcomeServlets</param-name>
|
||||
<param-value>false</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>redirectWelcome</param-name>
|
||||
<param-value>false</param-value>
|
||||
|
|
Loading…
Reference in New Issue