View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.servlet;
20  
21  import java.util.ArrayList;
22  import java.util.Arrays;
23  import java.util.Collections;
24  import java.util.EnumSet;
25  import java.util.EventListener;
26  import java.util.HashMap;
27  import java.util.HashSet;
28  import java.util.List;
29  import java.util.Map;
30  import java.util.Set;
31  
32  import javax.servlet.Filter;
33  import javax.servlet.RequestDispatcher;
34  import javax.servlet.Servlet;
35  import javax.servlet.ServletContext;
36  import javax.servlet.ServletContextEvent;
37  import javax.servlet.ServletContextListener;
38  import javax.servlet.ServletException;
39  
40  import org.eclipse.jetty.security.ConstraintAware;
41  import org.eclipse.jetty.security.ConstraintSecurityHandler;
42  import org.eclipse.jetty.security.SecurityHandler;
43  import org.eclipse.jetty.server.Dispatcher;
44  import org.eclipse.jetty.server.DispatcherType;
45  import org.eclipse.jetty.server.Handler;
46  import org.eclipse.jetty.server.HandlerContainer;
47  import org.eclipse.jetty.server.handler.ContextHandler;
48  import org.eclipse.jetty.server.handler.ErrorHandler;
49  import org.eclipse.jetty.server.handler.HandlerCollection;
50  import org.eclipse.jetty.server.handler.HandlerWrapper;
51  import org.eclipse.jetty.server.session.SessionHandler;
52  import org.eclipse.jetty.servlet.api.FilterRegistration;
53  import org.eclipse.jetty.servlet.api.ServletRegistration;
54  import org.eclipse.jetty.util.Loader;
55  
56  
57  /* ------------------------------------------------------------ */
58  /** Servlet Context.
59   * This extension to the ContextHandler allows for
60   * simple construction of a context with ServletHandler and optionally
61   * session and security handlers, et.<pre>
62   *   new ServletContext("/context",Context.SESSIONS|Context.NO_SECURITY);
63   * </pre>
64   * <p/>
65   * This class should have been called ServletContext, but this would have
66   * cause confusion with {@link ServletContext}.
67   */
68  public class ServletContextHandler extends ContextHandler
69  {   
70      public final static int SESSIONS=1;
71      public final static int SECURITY=2;
72      public final static int NO_SESSIONS=0;
73      public final static int NO_SECURITY=0;
74  
75      protected final List<Decorator> _decorators= new ArrayList<Decorator>();
76      protected Class<? extends SecurityHandler> _defaultSecurityHandlerClass=org.eclipse.jetty.security.ConstraintSecurityHandler.class;
77      protected SessionHandler _sessionHandler;
78      protected SecurityHandler _securityHandler;
79      protected ServletHandler _servletHandler;
80      protected HandlerWrapper _wrapper;
81      protected int _options;
82      protected Object _restrictedContextListeners;
83      
84      /* ------------------------------------------------------------ */
85      public ServletContextHandler()
86      {
87          this(null,null,null,null,null);
88      }
89      
90      /* ------------------------------------------------------------ */
91      public ServletContextHandler(int options)
92      {
93          this(null,null,options);
94      }
95      
96      /* ------------------------------------------------------------ */
97      public ServletContextHandler(HandlerContainer parent, String contextPath)
98      {
99          this(parent,contextPath,null,null,null,null);
100     }
101     
102     /* ------------------------------------------------------------ */
103     public ServletContextHandler(HandlerContainer parent, String contextPath, int options)
104     {
105         this(parent,contextPath,null,null,null,null);
106         _options=options;
107     }
108     
109     /* ------------------------------------------------------------ */
110     public ServletContextHandler(HandlerContainer parent, String contextPath, boolean sessions, boolean security)
111     {
112         this(parent,contextPath,(sessions?SESSIONS:0)|(security?SECURITY:0));
113     }
114 
115     /* ------------------------------------------------------------ */
116     public ServletContextHandler(HandlerContainer parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
117     {   
118         this(parent,null,sessionHandler,securityHandler,servletHandler,errorHandler);
119     }
120 
121     /* ------------------------------------------------------------ */
122     public ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
123     {   
124         super((ContextHandler.Context)null);
125         _scontext = new Context();
126         _sessionHandler = sessionHandler;
127         _securityHandler = securityHandler;
128         _servletHandler = servletHandler;
129             
130         if (errorHandler!=null)
131             setErrorHandler(errorHandler);
132 
133         if (contextPath!=null)
134             setContextPath(contextPath);
135 
136         if (parent instanceof HandlerWrapper)
137             ((HandlerWrapper)parent).setHandler(this);
138         else if (parent instanceof HandlerCollection)
139             ((HandlerCollection)parent).addHandler(this);
140     }    
141 
142     /* ------------------------------------------------------------ */
143     /**
144      * @see org.eclipse.jetty.server.handler.ContextHandler#doStop()
145      */
146     @Override
147     protected void doStop() throws Exception
148     {
149         super.doStop();
150         if (_decorators != null)
151             _decorators.clear();
152         if (_wrapper != null)
153             _wrapper.setHandler(null);
154     }
155 
156     /* ------------------------------------------------------------ */
157     /** Get the defaultSecurityHandlerClass.
158      * @return the defaultSecurityHandlerClass
159      */
160     public Class<? extends SecurityHandler> getDefaultSecurityHandlerClass()
161     {
162         return _defaultSecurityHandlerClass;
163     }
164 
165     /* ------------------------------------------------------------ */
166     /** Set the defaultSecurityHandlerClass.
167      * @param defaultSecurityHandlerClass the defaultSecurityHandlerClass to set
168      */
169     public void setDefaultSecurityHandlerClass(Class<? extends SecurityHandler> defaultSecurityHandlerClass)
170     {
171         _defaultSecurityHandlerClass = defaultSecurityHandlerClass;
172     }
173 
174     /* ------------------------------------------------------------ */
175     protected SessionHandler newSessionHandler()
176     {
177         return new SessionHandler();
178     }
179     
180     /* ------------------------------------------------------------ */
181     protected SecurityHandler newSecurityHandler()
182     {
183         try
184         {
185             return (SecurityHandler)_defaultSecurityHandlerClass.newInstance();
186         }
187         catch(Exception e)
188         {
189             throw new IllegalStateException(e);
190         }
191     }
192 
193     /* ------------------------------------------------------------ */
194     protected ServletHandler newServletHandler()
195     {
196         return new ServletHandler();
197     }
198 
199     /* ------------------------------------------------------------ */
200     /**
201      * Finish constructing handlers and link them together.
202      * 
203      * @see org.eclipse.jetty.server.handler.ContextHandler#startContext()
204      */
205     protected void startContext() throws Exception
206     {
207         // force creation of missing handlers.
208         getSessionHandler();
209         getSecurityHandler();
210         getServletHandler();
211         
212         Handler handler = _servletHandler;
213         if (_securityHandler!=null)
214         {
215             _securityHandler.setHandler(handler);
216             handler=_securityHandler;
217         }
218         
219         if (_sessionHandler!=null)
220         {
221             _sessionHandler.setHandler(handler);
222             handler=_sessionHandler;
223         }
224         
225         // skip any wrapped handlers 
226         _wrapper=this;
227         while (_wrapper!=handler && _wrapper.getHandler() instanceof HandlerWrapper)
228             _wrapper=(HandlerWrapper)_wrapper.getHandler();
229         
230         // if we are not already linked
231         if (_wrapper!=handler)
232         {
233             if (_wrapper.getHandler()!=null )
234                 throw new IllegalStateException("!ScopedHandler");
235             _wrapper.setHandler(handler);
236         }
237         
238     	super.startContext();
239 
240     	// OK to Initialize servlet handler now
241     	if (_servletHandler != null && _servletHandler.isStarted())
242     	{
243     	    for (int i=_decorators.size()-1;i>=0; i--)
244     	    {
245     	        Decorator decorator = _decorators.get(i);
246                 if (_servletHandler.getFilters()!=null)
247                     for (FilterHolder holder:_servletHandler.getFilters())
248                         decorator.decorateFilterHolder(holder);
249     	        if(_servletHandler.getServlets()!=null)
250     	            for (ServletHolder holder:_servletHandler.getServlets())
251     	                decorator.decorateServletHolder(holder);
252     	    }   
253     	        
254     	    _servletHandler.initialize();
255     	}
256     }
257 
258     /* ------------------------------------------------------------ */
259     /**
260      * @return Returns the securityHandler.
261      */
262     public SecurityHandler getSecurityHandler()
263     {
264         if (_securityHandler==null && (_options&SECURITY)!=0 && !isStarted()) 
265             _securityHandler=newSecurityHandler();
266         
267         return _securityHandler;
268     }
269 
270     /* ------------------------------------------------------------ */
271     /**
272      * @return Returns the servletHandler.
273      */
274     public ServletHandler getServletHandler()
275     {
276         if (_servletHandler==null && !isStarted()) 
277             _servletHandler=newServletHandler();
278         return _servletHandler;
279     }
280 
281     /* ------------------------------------------------------------ */
282     /**
283      * @return Returns the sessionHandler.
284      */
285     public SessionHandler getSessionHandler()
286     {
287         if (_sessionHandler==null && (_options&SESSIONS)!=0 && !isStarted()) 
288             _sessionHandler=newSessionHandler();
289         return _sessionHandler;
290     }
291 
292     /* ------------------------------------------------------------ */
293     /** conveniance method to add a servlet.
294      */
295     public ServletHolder addServlet(String className,String pathSpec)
296     {
297         return getServletHandler().addServletWithMapping(className, pathSpec);
298     }
299 
300     /* ------------------------------------------------------------ */
301     /** conveniance method to add a servlet.
302      */
303     public ServletHolder addServlet(Class<? extends Servlet> servlet,String pathSpec)
304     {
305         return getServletHandler().addServletWithMapping(servlet.getName(), pathSpec);
306     }
307     
308     /* ------------------------------------------------------------ */
309     /** conveniance method to add a servlet.
310      */
311     public void addServlet(ServletHolder servlet,String pathSpec)
312     {
313         getServletHandler().addServletWithMapping(servlet, pathSpec);
314     }
315 
316     /* ------------------------------------------------------------ */
317     /** conveniance method to add a filter
318      */
319     public void addFilter(FilterHolder holder,String pathSpec,EnumSet<DispatcherType> dispatches)
320     {
321         getServletHandler().addFilterWithMapping(holder,pathSpec,dispatches);
322     }
323 
324     /* ------------------------------------------------------------ */
325     /** convenience method to add a filter
326      */
327     public FilterHolder addFilter(Class<? extends Filter> filterClass,String pathSpec,EnumSet<DispatcherType> dispatches)
328     {
329         return getServletHandler().addFilterWithMapping(filterClass,pathSpec,dispatches);
330     }
331 
332     /* ------------------------------------------------------------ */
333     /** convenience method to add a filter
334      */
335     public FilterHolder addFilter(String filterClass,String pathSpec,EnumSet<DispatcherType> dispatches)
336     {
337         return getServletHandler().addFilterWithMapping(filterClass,pathSpec,dispatches);
338     }
339     
340 
341     /* ------------------------------------------------------------ */
342     /** conveniance method to add a filter
343      */
344     public void addFilter(FilterHolder holder,String pathSpec,int dispatches)
345     {
346         getServletHandler().addFilterWithMapping(holder,pathSpec,dispatches);
347     }
348 
349     /* ------------------------------------------------------------ */
350     /** convenience method to add a filter
351      */
352     public FilterHolder addFilter(Class<? extends Filter> filterClass,String pathSpec,int dispatches)
353     {
354         return getServletHandler().addFilterWithMapping(filterClass,pathSpec,dispatches);
355     }
356 
357     /* ------------------------------------------------------------ */
358     /** convenience method to add a filter
359      */
360     public FilterHolder addFilter(String filterClass,String pathSpec,int dispatches)
361     {
362         return getServletHandler().addFilterWithMapping(filterClass,pathSpec,dispatches);
363     }
364 
365  
366 
367     public void callContextInitialized(ServletContextListener l, ServletContextEvent e)
368     {       
369         l.contextInitialized(e);  
370     }
371 
372 
373     public void callContextDestroyed(ServletContextListener l, ServletContextEvent e)
374     {
375         l.contextDestroyed(e);
376     }
377 
378 
379 
380     /* ------------------------------------------------------------ */
381     /**
382      * @param sessionHandler The sessionHandler to set.
383      */
384     public void setSessionHandler(SessionHandler sessionHandler)
385     {
386         if (isStarted())
387             throw new IllegalStateException("STARTED");
388 
389         _sessionHandler = sessionHandler;
390     }
391 
392     /* ------------------------------------------------------------ */
393     /**
394      * @param securityHandler The {@link SecurityHandler} to set on this context.
395      */
396     public void setSecurityHandler(SecurityHandler securityHandler)
397     {
398         if (isStarted())
399             throw new IllegalStateException("STARTED");
400 
401         _securityHandler = securityHandler;
402     }
403 
404     /* ------------------------------------------------------------ */
405     /**
406      * @param servletHandler The servletHandler to set.
407      */
408     public void setServletHandler(ServletHandler servletHandler)
409     {
410         if (isStarted())
411             throw new IllegalStateException("STARTED");
412 
413         _servletHandler = servletHandler;
414     }
415 
416     /* ------------------------------------------------------------ */
417     /**
418      * @return The decorator list used to resource inject new Filters, Servlets and EventListeners
419      */
420     public List<Decorator> getDecorators()
421     {
422         return Collections.unmodifiableList(_decorators);
423     }
424 
425     /* ------------------------------------------------------------ */
426     /**
427      * @param decorators The lis of {@link Decorator}s
428      */
429     public void setDecorators(List<Decorator> decorators)
430     {
431         _decorators.clear();
432         _decorators.addAll(decorators);
433     }
434     
435     /* ------------------------------------------------------------ */
436     /**
437      * @param decorator The decorator to add
438      */
439     public void addDecorator(Decorator decorator)
440     {
441         _decorators.add(decorator);
442     }
443 
444     /* ------------------------------------------------------------ */
445     void destroyServlet(Servlet servlet)
446     {
447         for (Decorator decorator : _decorators)
448             decorator.destroyServletInstance(servlet);
449     }
450 
451     /* ------------------------------------------------------------ */
452     void destroyFilter(Filter filter)
453     {
454         for (Decorator decorator : _decorators)
455             decorator.destroyFilterInstance(filter);
456     }
457     
458     /* ------------------------------------------------------------ */
459     public class Context extends ContextHandler.Context
460     {
461         /* ------------------------------------------------------------ */
462         /* 
463          * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
464          */
465         @Override
466         public RequestDispatcher getNamedDispatcher(String name)
467         {
468             ContextHandler context=org.eclipse.jetty.servlet.ServletContextHandler.this;
469             if (_servletHandler==null || _servletHandler.getServlet(name)==null)
470                 return null;
471             return new Dispatcher(context, name);
472         }
473         
474         /* ------------------------------------------------------------ */
475         /**
476          * @since servlet-api-3.0
477          */
478         public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass)
479         {
480             if (isStarted())
481                 throw new IllegalStateException();
482 
483             final ServletHandler handler = ServletContextHandler.this.getServletHandler();
484             final FilterHolder holder= handler.newFilterHolder();
485             holder.setName(filterName);
486             holder.setHeldClass(filterClass);
487             handler.addFilter(holder);
488             return holder.getRegistration();
489         }
490 
491         /* ------------------------------------------------------------ */
492         /**
493          * @since servlet-api-3.0
494          */
495         public FilterRegistration.Dynamic addFilter(String filterName, String className)
496         {
497             if (isStarted())
498                 throw new IllegalStateException();
499 
500             final ServletHandler handler = ServletContextHandler.this.getServletHandler();
501             final FilterHolder holder= handler.newFilterHolder();
502             holder.setName(filterName);
503             holder.setClassName(className);
504             handler.addFilter(holder);
505             return holder.getRegistration();
506         }
507 
508 
509         /* ------------------------------------------------------------ */
510         /**
511          * @since servlet-api-3.0
512          */
513         public FilterRegistration.Dynamic addFilter(String filterName, Filter filter)
514         {
515             if (isStarted())
516                 throw new IllegalStateException();
517 
518             final ServletHandler handler = ServletContextHandler.this.getServletHandler();
519             final FilterHolder holder= handler.newFilterHolder();
520             holder.setName(filterName);
521             holder.setFilter(filter);
522             handler.addFilter(holder);
523             return holder.getRegistration();
524         }
525         
526         /* ------------------------------------------------------------ */
527         /**
528          * @since servlet-api-3.0
529          */
530         public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass)
531         {
532             if (!isStarting())
533                 throw new IllegalStateException();
534 
535             final ServletHandler handler = ServletContextHandler.this.getServletHandler();
536             final ServletHolder holder= handler.newServletHolder();
537             holder.setName(servletName);
538             holder.setHeldClass(servletClass);
539             handler.addServlet(holder);
540             return holder.getRegistration();
541         }
542 
543         /* ------------------------------------------------------------ */
544         /**
545          * @since servlet-api-3.0
546          */
547         public ServletRegistration.Dynamic addServlet(String servletName, String className)
548         {
549             if (!isStarting())
550                 throw new IllegalStateException();
551             
552             final ServletHandler handler = ServletContextHandler.this.getServletHandler();
553             final ServletHolder holder= handler.newServletHolder();
554             holder.setName(servletName);
555             holder.setClassName(className);
556             handler.addServlet(holder);
557             return holder.getRegistration();
558         }
559 
560         /* ------------------------------------------------------------ */
561         /**
562          * @since servlet-api-3.0
563          */
564         public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet)
565         {
566             if (!isStarting())
567                 throw new IllegalStateException();
568 
569             final ServletHandler handler = ServletContextHandler.this.getServletHandler();
570             final ServletHolder holder= handler.newServletHolder();
571             holder.setName(servletName);
572             holder.setServlet(servlet);
573             handler.addServlet(holder);
574             return holder.getRegistration();
575         }
576 
577         /* ------------------------------------------------------------ */
578         public boolean setInitParameter(String name, String value)
579         {
580             // TODO other started conditions
581             if (!isStarting())
582                 throw new IllegalStateException();
583             
584             return super.setInitParameter(name,value);
585         }
586 
587         /* ------------------------------------------------------------ */
588         public <T extends Filter> T createFilter(Class<T> c) throws ServletException
589         {
590             try
591             {
592                 T f = c.newInstance();
593                 for (int i=_decorators.size()-1; i>=0; i--)
594                 {
595                     Decorator decorator = _decorators.get(i);
596                     f=decorator.decorateFilterInstance(f);
597                 }
598                 return f;
599             }
600             catch (InstantiationException e)
601             {
602                 throw new ServletException(e);
603             }
604             catch (IllegalAccessException e)
605             {
606                 throw new ServletException(e);
607             }
608         }
609 
610         /* ------------------------------------------------------------ */
611         public <T extends Servlet> T createServlet(Class<T> c) throws ServletException
612         {
613             try
614             {
615                 T s = c.newInstance();
616                 for (int i=_decorators.size()-1; i>=0; i--)
617                 {
618                     Decorator decorator = _decorators.get(i);
619                     s=decorator.decorateServletInstance(s);
620                 }
621                 return s;
622             }
623             catch (InstantiationException e)
624             {
625                 throw new ServletException(e);
626             }
627             catch (IllegalAccessException e)
628             {
629                 throw new ServletException(e);
630             }
631         }
632         
633         public FilterRegistration getFilterRegistration(String filterName)
634         {   
635             final FilterHolder holder=ServletContextHandler.this.getServletHandler().getFilter(filterName);
636             return (holder==null)?null:holder.getRegistration();
637         }
638 
639         
640         public Map<String, ? extends FilterRegistration> getFilterRegistrations()
641         {
642             HashMap<String, FilterRegistration> registrations = new HashMap<String, FilterRegistration>();
643             ServletHandler handler=ServletContextHandler.this.getServletHandler();
644             FilterHolder[] holders=handler.getFilters();
645             if (holders!=null)
646             {
647                 for (FilterHolder holder : holders)
648                     registrations.put(holder.getName(),holder.getRegistration());
649             }
650             return registrations;
651         }
652 
653         
654         public ServletRegistration getServletRegistration(String servletName)
655         { 
656             final ServletHolder holder=ServletContextHandler.this.getServletHandler().getServlet(servletName);
657             return (holder==null)?null:holder.getRegistration();
658         }
659 
660         
661         public Map<String, ? extends ServletRegistration> getServletRegistrations()
662         { 
663             HashMap<String, ServletRegistration> registrations = new HashMap<String, ServletRegistration>();
664             ServletHandler handler=ServletContextHandler.this.getServletHandler();
665             ServletHolder[] holders=handler.getServlets();
666             if (holders!=null)
667             {
668                 for (ServletHolder holder : holders)
669                     registrations.put(holder.getName(),holder.getRegistration());
670             }
671             return registrations;
672         }
673 
674   
675         public void addListener(String className)
676         {
677             // TODO other started conditions
678             if (!isStarting())
679                 throw new IllegalStateException();
680             try
681             {
682                 Class<? extends EventListener> clazz = getClassLoader()==null?Loader.loadClass(ContextHandler.class,className):getClassLoader().loadClass(className);
683                 addListener(clazz);
684             }
685             catch (ClassNotFoundException e)
686             {
687                 throw new IllegalArgumentException(e);
688             }
689         }
690 
691       
692         public <T extends EventListener> void addListener(T t)
693         {
694             if (!isStarting())
695                 throw new IllegalStateException();
696          
697             ServletContextHandler.this.addEventListener(t);
698         }
699 
700       
701         public void addListener(Class<? extends EventListener> listenerClass)
702         {
703             if (!isStarting())
704                 throw new IllegalStateException();
705 
706             try
707             {
708                 EventListener l = createListener(listenerClass);
709                 ServletContextHandler.this.addEventListener(l);
710             }
711             catch (ServletException e)
712             {
713                 throw new IllegalStateException(e);
714             }
715         }
716 
717    
718         public <T extends EventListener> T createListener(Class<T> clazz) throws ServletException
719         {
720             try
721             {
722                 T l = null;
723                 try
724                 {
725                     l = clazz.newInstance();
726                 }
727                 catch (InstantiationException e)
728                 {
729                     throw new ServletException(e);
730                 }
731                 catch (IllegalAccessException e)
732                 {
733                     throw new ServletException(e);
734                 }
735 
736                 for (int i=_decorators.size()-1; i>=0; i--)
737                 {
738                     Decorator decorator = _decorators.get(i);
739                     l=decorator.decorateListenerInstance(l);
740                 }
741                 return l;
742             }
743             catch(ServletException e)
744             {
745                 throw e;
746             }
747             catch(Exception e)
748             {
749                 throw new ServletException(e);
750             }
751         }
752 
753      
754         public void declareRoles(String... roleNames)
755         {
756             if (!isStarting())
757                 throw new IllegalStateException();
758            
759             //Get a reference to the SecurityHandler, which must be ConstraintAware
760             if (_securityHandler != null && _securityHandler instanceof ConstraintAware)
761             {
762                 HashSet<String> union = new HashSet<String>();
763                 Set<String> existing = ((ConstraintAware)_securityHandler).getRoles();
764                 if (existing != null)
765                     union.addAll(existing);
766                 union.addAll(Arrays.asList(roleNames));
767                 ((ConstraintSecurityHandler)_securityHandler).setRoles(union);
768             }
769         }
770     }
771     
772     
773     /* ------------------------------------------------------------ */
774     /** Interface to decorate loaded classes.
775      */
776     public interface Decorator
777     {
778         <T extends Filter> T decorateFilterInstance(T filter) throws ServletException;
779         <T extends Servlet> T decorateServletInstance(T servlet) throws ServletException;
780         <T extends EventListener> T decorateListenerInstance(T listener) throws ServletException;
781 
782         void decorateFilterHolder(FilterHolder filter) throws ServletException;
783         void decorateServletHolder(ServletHolder servlet) throws ServletException;
784         
785         void destroyServletInstance(Servlet s);
786         void destroyFilterInstance(Filter f);
787         void destroyListenerInstance(EventListener f);
788     }
789 }