diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java index 3f41d532715..e69910480a7 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java @@ -97,7 +97,19 @@ public class FilterHolder extends Holder super.stop(); throw new IllegalStateException(msg); } + } + + + + + + /* ------------------------------------------------------------ */ + @Override + public void initialize() throws Exception + { + super.initialize(); + if (_filter==null) { try @@ -123,6 +135,7 @@ public class FilterHolder extends Holder _filter.init(_config); } + /* ------------------------------------------------------------ */ @Override public void doStop() diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java index f67b635bf17..0b7a1fb8f0e 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java @@ -82,6 +82,19 @@ public class Holder extends AbstractLifeCycle implements Dumpable { return _extInstance; } + + + /* ------------------------------------------------------------ */ + /** + * Do any setup necessary after starting + * @throws Exception + */ + public void initialize() + throws Exception + { + if (!isStarted()) + throw new IllegalStateException("Not started: "+this); + } /* ------------------------------------------------------------ */ @SuppressWarnings("unchecked") diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index a413cab28b1..9baefac40ab 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -741,6 +741,7 @@ public class ServletHandler extends ScopedHandler try { h.start(); + h.initialize(); } catch (Exception e) { diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java index 8ff369ef0ec..6de3b7e48bf 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java @@ -280,7 +280,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope _enabled = enabled; } - + /* ------------------------------------------------------------ */ public void doStart() throws Exception @@ -319,7 +319,17 @@ public class ServletHolder extends Holder implements UserIdentity.Scope if (_class!=null && javax.servlet.SingleThreadModel.class.isAssignableFrom(_class)) _servlet = new SingleThreadedWrapper(); - + + } + + + /* ------------------------------------------------------------ */ + @Override + public void initialize () + throws Exception + { + super.initialize(); + if (_extInstance || _initOnStartup) { try @@ -335,7 +345,8 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } } } - + + /* ------------------------------------------------------------ */ public void doStop() throws Exception diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java index 044c6660ae9..b81a1e44de4 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java @@ -98,7 +98,9 @@ public abstract class AbstractDoSFilterTest public void startFilters() throws Exception { _dosFilter.start(); + _dosFilter.initialize(); _timeoutFilter.start(); + _timeoutFilter.initialize(); } @After