diff options
author | Greg Wilkins | 2010-07-26 09:40:47 +0000 |
---|---|---|
committer | Greg Wilkins | 2010-07-26 09:40:47 +0000 |
commit | b4f4c0ae36ef23321b5b9cd0698fdf8acb907d6a (patch) | |
tree | 6785010a099e2b157cba0a8146a572c397ef93fb /jetty-servlet/src/main | |
parent | badbe6d252d8c3b69e7568f35a7533b15ff08560 (diff) | |
download | org.eclipse.jetty.project-b4f4c0ae36ef23321b5b9cd0698fdf8acb907d6a.tar.gz org.eclipse.jetty.project-b4f4c0ae36ef23321b5b9cd0698fdf8acb907d6a.tar.xz org.eclipse.jetty.project-b4f4c0ae36ef23321b5b9cd0698fdf8acb907d6a.zip |
320073 further improved configuration
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2175 7e9141cc-0065-0410-87d8-b60c137991c4
Diffstat (limited to 'jetty-servlet/src/main')
-rw-r--r-- | jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java | 48 | ||||
-rw-r--r-- | jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java | 63 |
2 files changed, 62 insertions, 49 deletions
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java index 9f82314b85..3b27819248 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java @@ -67,13 +67,13 @@ import org.eclipse.jetty.util.resource.ResourceFactory; * on the servlet itself or as ServletContext initParameters with a prefix * of org.eclipse.jetty.servlet.Default. : * <PRE> - * acceptRanges If true, range requests and responses are + * acceptRanges If true, range requests and responses are * supported * - * dirAllowed If true, directory listings are returned if no + * 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 + * welcomeServlets If true, attempt to dispatch to welcome files * that are servlets, but only after no matching static * resources could be found. If false, then a welcome * file must exist on disk. If "exact", then exact @@ -83,17 +83,17 @@ import org.eclipse.jetty.util.resource.ResourceFactory; * 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 + * redirectWelcome If true, welcome files are redirected rather than * forwarded to. * - * gzip If set to true, then static content will be served as + * gzip If set to true, then static content will be served as * gzip content encoded if a matching resource is * found ending with ".gz" * * resourceBase Set to replace the context resource base * * resourceCache If set, this is a context attribute name, which the servlet - * will use to look for a shared ResourceCache instance. + * will use to look for a shared ResourceCache instance. * * relativeResourceBase * Set with a pathname relative to the base of the @@ -222,30 +222,28 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory _cache=(ResourceCache)_servletContext.getAttribute(resourceCache); if (_cache==null) - throw new UnavailableException("Could not find resourceCache "+resourceCache); + Log.debug("Could not find resourceCache "+resourceCache); } - else + + try { - try + if (_cache==null && max_cached_files>0) { - if (max_cached_files>0) - { - _cache= new ResourceCache(this,_mimeTypes,_useFileMappedBuffer); - - if (max_cache_size>0) - _cache.setMaxCacheSize(max_cache_size); - if (max_cached_file_size>=-1) - _cache.setMaxCachedFileSize(max_cached_file_size); - if (max_cached_files>=-1) - _cache.setMaxCachedFiles(max_cached_files); - } - } - catch (Exception e) - { - Log.warn(Log.EXCEPTION,e); - throw new UnavailableException(e.toString()); + _cache= new ResourceCache(this,_mimeTypes,_useFileMappedBuffer); + + if (max_cache_size>0) + _cache.setMaxCacheSize(max_cache_size); + if (max_cached_file_size>=-1) + _cache.setMaxCachedFileSize(max_cached_file_size); + if (max_cached_files>=-1) + _cache.setMaxCachedFiles(max_cached_files); } } + catch (Exception e) + { + Log.warn(Log.EXCEPTION,e); + throw new UnavailableException(e.toString()); + } _servletHandler= (ServletHandler) _contextHandler.getChildHandlerByClass(ServletHandler.class); for (ServletHolder h :_servletHandler.getServlets()) diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index d2c4fd3b82..e05f2d8c81 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -13,11 +13,14 @@ package org.eclipse.jetty.servlet; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.EventListener; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -63,13 +66,13 @@ public class ServletContextHandler extends ContextHandler public final static int SECURITY=2; public final static int NO_SESSIONS=0; public final static int NO_SECURITY=0; - + + protected final List<Decorator> _decorators= new ArrayList<Decorator>(); protected Class<? extends SecurityHandler> _defaultSecurityHandlerClass=org.eclipse.jetty.security.ConstraintSecurityHandler.class; protected SessionHandler _sessionHandler; protected SecurityHandler _securityHandler; protected ServletHandler _servletHandler; protected int _options; - protected Decorator _decorator; protected Object _restrictedContextListeners; /* ------------------------------------------------------------ */ @@ -227,14 +230,14 @@ public class ServletContextHandler extends ContextHandler // OK to Initialize servlet handler now if (_servletHandler != null && _servletHandler.isStarted()) { - if (_decorator!=null) + for (Decorator decorator : _decorators) { if (_servletHandler.getFilters()!=null) for (FilterHolder holder:_servletHandler.getFilters()) - _decorator.decorateFilterHolder(holder); + decorator.decorateFilterHolder(holder); if(_servletHandler.getServlets()!=null) for (ServletHolder holder:_servletHandler.getServlets()) - _decorator.decorateServletHolder(holder); + decorator.decorateServletHolder(holder); } _servletHandler.initialize(); @@ -401,34 +404,44 @@ public class ServletContextHandler extends ContextHandler /* ------------------------------------------------------------ */ /** - * @return The decorator used to resource inject new Filters, Servlets and EventListeners + * @return The decorator list used to resource inject new Filters, Servlets and EventListeners */ - public Decorator getDecorator() + public List<Decorator> getDecorators() { - return _decorator; + return Collections.unmodifiableList(_decorators); } /* ------------------------------------------------------------ */ /** - * @param decorator The inject used to resource inject new Filters, Servlets and EventListeners + * @param decorators The lis of {@link Decorator}s */ - public void setDecorator(Decorator decorator) + public void setDecorators(List<Decorator> decorators) { - _decorator = decorator; + _decorators.clear(); + _decorators.addAll(decorators); + } + + /* ------------------------------------------------------------ */ + /** + * @param decorator The decorator to add + */ + public void addDecorator(Decorator decorator) + { + _decorators.add(decorator); } /* ------------------------------------------------------------ */ void destroyServlet(Servlet servlet) { - if (_decorator!=null) - _decorator.destroyServletInstance(servlet); + for (Decorator decorator : _decorators) + decorator.destroyServletInstance(servlet); } /* ------------------------------------------------------------ */ void destroyFilter(Filter filter) { - if (_decorator!=null) - _decorator.destroyFilterInstance(filter); + for (Decorator decorator : _decorators) + decorator.destroyFilterInstance(filter); } /* ------------------------------------------------------------ */ @@ -563,8 +576,8 @@ public class ServletContextHandler extends ContextHandler try { T f = c.newInstance(); - if (_decorator!=null) - f=_decorator.decorateFilterInstance(f); + for (Decorator decorator : _decorators) + f=decorator.decorateFilterInstance(f); return f; } catch (InstantiationException e) @@ -583,8 +596,8 @@ public class ServletContextHandler extends ContextHandler try { T s = c.newInstance(); - if (_decorator!=null) - s=_decorator.decorateServletInstance(s); + for (Decorator decorator : _decorators) + s=decorator.decorateServletInstance(s); return s; } catch (InstantiationException e) @@ -699,9 +712,9 @@ public class ServletContextHandler extends ContextHandler { throw new ServletException(e); } - - if (_decorator!=null) - l=_decorator.decorateListenerInstance(l); + + for (Decorator decorator : _decorators) + l=decorator.decorateListenerInstance(l); return l; } catch(ServletException e) @@ -733,6 +746,10 @@ public class ServletContextHandler extends ContextHandler } } + + /* ------------------------------------------------------------ */ + /** Interface to decorate loaded classes. + */ public interface Decorator { <T extends Filter> T decorateFilterInstance(T filter) throws ServletException; @@ -745,7 +762,5 @@ public class ServletContextHandler extends ContextHandler void destroyServletInstance(Servlet s); void destroyFilterInstance(Filter f); void destroyListenerInstance(EventListener f); - - public Decorator cloneFor(ContextHandler context); } } |