JETTY-936 Improved servlet matching and optimized
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@895 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
d6415542d3
commit
1349237ab6
15
VERSION.txt
15
VERSION.txt
|
@ -6,9 +6,7 @@ jetty-7.0.1-SNAPSHOT
|
|||
+ 289027 deobfuscate HttpClient SSL passwords
|
||||
|
||||
jetty-7.0.0.RC6-SNAPSHOT
|
||||
+ 288055 jetty-client fails to resolve failed resolution attempts correctly
|
||||
+ 288153 jetty-client resend doesn't reset exchange
|
||||
+ 288182 PUT request fails during retry
|
||||
+ JETTY-936 274251 Improved servlet matching and optimized'
|
||||
+ JETTY-780 CNFE during startup of webapp with spring-context >= 2.5.1
|
||||
+ JETTY-1080 modify previous fix to work on windows
|
||||
+ JETTY-1084 HEAD command not setting content-type in response under certain circumstances
|
||||
|
@ -20,14 +18,17 @@ jetty-7.0.0.RC6-SNAPSHOT
|
|||
+ JETTY-1101 Updated servlet3 continuation constructor
|
||||
+ JETTY-1105 Custom error pages aren't working
|
||||
+ JETTY-1108 SSL EOF detection
|
||||
+ 288514 AbstractConnector does not handle InterruptedExceptions on shutdown
|
||||
+ 288466 LocalConnector is not thread safe
|
||||
+ 288772 Failure to connect does not set status to EXCEPTED
|
||||
+ 280723 Add non blocking statistics handler
|
||||
+ 283357 org.eclipse.jetty.server.HttpConnectionTest exceptions
|
||||
+ 282543 HttpClient SSL buffer size fix
|
||||
+ 283357 org.eclipse.jetty.server.HttpConnectionTest exceptions
|
||||
+ 288055 jetty-client fails to resolve failed resolution attempts correctly
|
||||
+ 288153 jetty-client resend doesn't reset exchange
|
||||
+ 288466 LocalConnector is not thread safe
|
||||
+ 288514 AbstractConnector does not handle InterruptedExceptions on shutdown
|
||||
+ 288772 Failure to connect does not set status to EXCEPTED
|
||||
+ 289146 formalize reload policy functionality
|
||||
+ 289156 jetty-client: no longer throw runtime exception for bad authn details
|
||||
+ 288182 PUT request fails during retry
|
||||
|
||||
jetty-6.1.20 27 August 2009
|
||||
+ JETTY-838 Don't log and throw
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -74,7 +75,7 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
|
|||
*
|
||||
* welcomeServlets If true, attempt to dispatch to welcome files
|
||||
* that are servlets, but only after no matching static
|
||||
* resources could be found.
|
||||
* resources could be found. Default is true.
|
||||
*
|
||||
* This must be false if you want directory listings,
|
||||
* but have index.jsp in your welcome file list.
|
||||
|
@ -126,7 +127,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
|
||||
private boolean _acceptRanges=true;
|
||||
private boolean _dirAllowed=true;
|
||||
private boolean _welcomeServlets=false;
|
||||
private boolean _welcomeServlets=true;
|
||||
private boolean _redirectWelcome=false;
|
||||
private boolean _gzip=true;
|
||||
|
||||
|
@ -139,6 +140,8 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
private boolean _useFileMappedBuffer=false;
|
||||
private ByteArrayBuffer _cacheControl;
|
||||
private String _relativeResourceBase;
|
||||
private ServletHandler _servletHandler;
|
||||
private ServletHolder _defaultHolder;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -240,6 +243,11 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
Log.warn(Log.EXCEPTION,e);
|
||||
throw new UnavailableException(e.toString());
|
||||
}
|
||||
|
||||
_servletHandler= (ServletHandler) _contextHandler.getChildHandlerByClass(ServletHandler.class);
|
||||
for (ServletHolder h :_servletHandler.getServlets())
|
||||
if (h.getServletInstance()==this)
|
||||
_defaultHolder=h;
|
||||
|
||||
if (Log.isDebugEnabled()) Log.debug("resource base = "+_resourceBase);
|
||||
}
|
||||
|
@ -486,28 +494,27 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
// else look for a welcome file
|
||||
else if (null!=(welcome=getWelcomeFile(pathInContext)))
|
||||
{
|
||||
String ipath=URIUtil.addPaths(pathInContext,welcome);
|
||||
if (_redirectWelcome)
|
||||
{
|
||||
// Redirect to the index
|
||||
response.setContentLength(0);
|
||||
String q=request.getQueryString();
|
||||
if (q!=null&&q.length()!=0)
|
||||
response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths( _servletContext.getContextPath(),ipath)+"?"+q));
|
||||
response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths( _servletContext.getContextPath(),welcome)+"?"+q));
|
||||
else
|
||||
response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths( _servletContext.getContextPath(),ipath)));
|
||||
response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths( _servletContext.getContextPath(),welcome)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Forward to the index
|
||||
RequestDispatcher dispatcher=request.getRequestDispatcher(ipath);
|
||||
RequestDispatcher dispatcher=request.getRequestDispatcher(welcome);
|
||||
if (dispatcher!=null)
|
||||
{
|
||||
if (included.booleanValue())
|
||||
dispatcher.include(request,response);
|
||||
else
|
||||
{
|
||||
request.setAttribute("org.eclipse.jetty.server.welcome",ipath);
|
||||
request.setAttribute("org.eclipse.jetty.server.welcome",welcome);
|
||||
dispatcher.forward(request,response);
|
||||
}
|
||||
}
|
||||
|
@ -570,7 +577,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
* 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
|
||||
* @return The name of the matching welcome file.
|
||||
* @return The path of the matching welcome file in context or null.
|
||||
* @throws IOException
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
|
@ -578,25 +585,23 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
{
|
||||
if (_welcomes==null)
|
||||
return null;
|
||||
|
||||
|
||||
String welcome_servlet=null;
|
||||
for (int i=0;i<_welcomes.length;i++)
|
||||
{
|
||||
Resource welcome=getResource(URIUtil.addPaths(pathInContext,_welcomes[i]));
|
||||
String welcome_in_context=URIUtil.addPaths(pathInContext,_welcomes[i]);
|
||||
Resource welcome=getResource(welcome_in_context);
|
||||
if (welcome!=null && welcome.exists())
|
||||
return _welcomes[i];
|
||||
}
|
||||
|
||||
if (_welcomeServlets)
|
||||
{
|
||||
ServletHandler servletHandler = (ServletHandler)_contextHandler.getChildHandlerByClass(ServletHandler.class);
|
||||
for (int i=0;i<_welcomes.length;i++)
|
||||
|
||||
if (_welcomeServlets && welcome_servlet==null)
|
||||
{
|
||||
if (servletHandler.matchesPath(_welcomes[i]))
|
||||
return _welcomes[i];
|
||||
Map.Entry entry=_servletHandler.getHolderEntry(welcome_in_context);
|
||||
if (entry!=null && entry.getValue()!=_defaultHolder)
|
||||
welcome_servlet=welcome_in_context;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return welcome_servlet;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -229,18 +229,8 @@ public class ServletHandler extends ScopedHandler
|
|||
return null;
|
||||
return _servletPathMap.getMatch(pathInContext);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** 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>,
|
||||
|
|
|
@ -317,6 +317,15 @@ public class ServletHolder extends Holder implements UserIdentity.Scope, Compara
|
|||
return _servlet;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the servlet instance (no initialization done).
|
||||
* @return The servlet or null
|
||||
*/
|
||||
public Servlet getServletInstance()
|
||||
{
|
||||
return _servlet;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Check to ensure class of servlet is acceptable.
|
||||
|
|
|
@ -30,7 +30,7 @@ public class DefaultServletTest extends TestCase
|
|||
|
||||
context = new ServletContextHandler();
|
||||
context.setContextPath("/context");
|
||||
context.setWelcomeFiles(new String[] {}); // no welcome files
|
||||
context.setWelcomeFiles(new String[] {"index.html","index.jsp","index.htm"});
|
||||
|
||||
server.setHandler(context);
|
||||
server.addConnector(connector);
|
||||
|
@ -179,7 +179,7 @@ public class DefaultServletTest extends TestCase
|
|||
|
||||
public void testListingContextBreakout() throws Exception
|
||||
{
|
||||
ServletHolder defholder = context.addServlet(DefaultServlet.class,"/*");
|
||||
ServletHolder defholder = context.addServlet(DefaultServlet.class,"/");
|
||||
defholder.setInitParameter("dirAllowed","true");
|
||||
defholder.setInitParameter("redirectWelcome","false");
|
||||
defholder.setInitParameter("gzip","false");
|
||||
|
@ -193,7 +193,7 @@ public class DefaultServletTest extends TestCase
|
|||
resBase.mkdirs();
|
||||
|
||||
File index = new File(resBase, "index.html");
|
||||
createFile(index, "<h>Hello Index</h1>");
|
||||
createFile(index, "<h1>Hello Index</h1>");
|
||||
|
||||
File wackyDir = new File(resBase, "dir?");
|
||||
if ( !_runningOnWindows )
|
||||
|
@ -226,7 +226,7 @@ public class DefaultServletTest extends TestCase
|
|||
String response;
|
||||
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("Directory: /context/<",response);
|
||||
assertResponseContains("<h1>Hello Index</h1>",response);
|
||||
|
||||
response= connector.getResponses("GET /context/dir?/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("404",response);
|
||||
|
@ -256,7 +256,7 @@ public class DefaultServletTest extends TestCase
|
|||
assertResponseNotContains("Sssh",response);
|
||||
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("Directory: /context/<",response);
|
||||
assertResponseContains("<h1>Hello Index</h1>",response);
|
||||
|
||||
response= connector.getResponses("GET /context/dir;/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("404",response);
|
||||
|
@ -283,6 +283,96 @@ public class DefaultServletTest extends TestCase
|
|||
assertResponseNotContains("Sssh",response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testWelcome() throws Exception
|
||||
{
|
||||
File testDir = new File("target/tests/" + getName());
|
||||
prepareEmptyTestDir(testDir);
|
||||
File resBase = new File(testDir, "docroot");
|
||||
resBase.mkdirs();
|
||||
File inde = new File(resBase, "index.htm");
|
||||
File index = new File(resBase, "index.html");
|
||||
|
||||
|
||||
String resBasePath = resBase.getAbsolutePath();
|
||||
|
||||
ServletHolder defholder = context.addServlet(DefaultServlet.class,"/");
|
||||
defholder.setInitParameter("dirAllowed","false");
|
||||
defholder.setInitParameter("redirectWelcome","false");
|
||||
defholder.setInitParameter("welcomeServlets","false");
|
||||
defholder.setInitParameter("gzip","false");
|
||||
defholder.setInitParameter("resourceBase",resBasePath);
|
||||
|
||||
ServletHolder jspholder = context.addServlet(NoJspServlet.class,"*.jsp");
|
||||
|
||||
String response;
|
||||
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("403",response);
|
||||
|
||||
createFile(index, "<h1>Hello Index</h1>");
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Index</h1>",response);
|
||||
|
||||
createFile(inde, "<h1>Hello Inde</h1>");
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Index</h1>",response);
|
||||
|
||||
index.delete();
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Inde</h1>",response);
|
||||
|
||||
inde.delete();
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("403",response);
|
||||
|
||||
}
|
||||
|
||||
public void testWelcomeServlet() throws Exception
|
||||
{
|
||||
File testDir = new File("target/tests/" + getName());
|
||||
prepareEmptyTestDir(testDir);
|
||||
File resBase = new File(testDir, "docroot");
|
||||
resBase.mkdirs();
|
||||
File inde = new File(resBase, "index.htm");
|
||||
File index = new File(resBase, "index.html");
|
||||
|
||||
|
||||
String resBasePath = resBase.getAbsolutePath();
|
||||
|
||||
ServletHolder defholder = context.addServlet(DefaultServlet.class,"/");
|
||||
defholder.setInitParameter("dirAllowed","false");
|
||||
defholder.setInitParameter("redirectWelcome","false");
|
||||
defholder.setInitParameter("welcomeServlets","true");
|
||||
defholder.setInitParameter("gzip","false");
|
||||
defholder.setInitParameter("resourceBase",resBasePath);
|
||||
|
||||
ServletHolder jspholder = context.addServlet(NoJspServlet.class,"*.jsp");
|
||||
|
||||
String response;
|
||||
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("JSP support not configured",response);
|
||||
|
||||
createFile(index, "<h1>Hello Index</h1>");
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Index</h1>",response);
|
||||
|
||||
createFile(inde, "<h1>Hello Inde</h1>");
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Index</h1>",response);
|
||||
|
||||
index.delete();
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Inde</h1>",response);
|
||||
|
||||
inde.delete();
|
||||
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("JSP support not configured",response);
|
||||
|
||||
}
|
||||
|
||||
private void createFile(File file, String str) throws IOException
|
||||
{
|
||||
FileOutputStream out = null;
|
||||
|
|
Loading…
Reference in New Issue