From 3ca0c6806a2c801b3bc485b8bc26cd24f5fae009 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 22 Jul 2010 06:33:54 +0000 Subject: [PATCH] 320073 support decorator cloning for WebAppContext templates git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2171 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../annotations/WebAppDecoratorWrapper.java | 8 ++++++++ .../jetty/plus/webapp/Configuration.java | 2 +- .../jetty/plus/webapp/WebAppDecorator.java | 19 ++++++++++++++----- .../jetty/servlet/ServletContextHandler.java | 2 ++ .../eclipse/jetty/webapp/WebAppContext.java | 9 ++++++++- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebAppDecoratorWrapper.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebAppDecoratorWrapper.java index c1f96731c5d..295f530e1bd 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebAppDecoratorWrapper.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebAppDecoratorWrapper.java @@ -19,6 +19,7 @@ import javax.servlet.Filter; import javax.servlet.Servlet; import javax.servlet.ServletException; +import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletContextHandler.Decorator; @@ -47,6 +48,13 @@ public class WebAppDecoratorWrapper implements Decorator _introspector.registerHandler(new PreDestroyAnnotationHandler(context)); _introspector.registerHandler(new DeclareRolesAnnotationHandler(context)); } + + /* ------------------------------------------------------------ */ + public Decorator cloneFor(ContextHandler context) + { + WebAppContext wac = (WebAppContext)context; + return new WebAppDecoratorWrapper(wac,_wrappedDecorator.cloneFor(context)); + } /* ------------------------------------------------------------ */ /** diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/Configuration.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/Configuration.java index 603eb58eeac..396d70c243a 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/Configuration.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/Configuration.java @@ -40,7 +40,7 @@ public class Configuration implements org.eclipse.jetty.webapp.Configuration public void preConfigure (WebAppContext context) throws Exception { - WebAppDecorator decorator = new WebAppDecorator(context); + WebAppDecorator decorator = new WebAppDecorator(); InjectionCollection injections = new InjectionCollection(); context.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections); decorator.setInjections(injections); diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/WebAppDecorator.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/WebAppDecorator.java index ede7090f96e..f33b66b459f 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/WebAppDecorator.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/WebAppDecorator.java @@ -22,6 +22,7 @@ import javax.servlet.ServletException; import org.eclipse.jetty.plus.annotation.InjectionCollection; import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection; import org.eclipse.jetty.plus.annotation.RunAsCollection; +import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletContextHandler.Decorator; @@ -35,18 +36,26 @@ import org.eclipse.jetty.webapp.WebAppContext; */ public class WebAppDecorator implements Decorator { - private WebAppContext _context; private InjectionCollection _injections; private LifeCycleCallbackCollection _callbacks; private RunAsCollection _runAses; - public WebAppDecorator (WebAppContext context) + public WebAppDecorator () { - _context = context; } - - + /* ------------------------------------------------------------ */ + /** + * @see org.eclipse.jetty.servlet.ServletContextHandler.Decorator#cloneFor(org.eclipse.jetty.server.handler.ContextHandler) + */ + public Decorator cloneFor(ContextHandler context) + { + // TODO maybe need to check for non-shared classloader??? + return this; + } + + + public InjectionCollection getInjections() { return _injections; 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 9a85cf4e16f..d2c4fd3b825 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 @@ -745,5 +745,7 @@ public class ServletContextHandler extends ContextHandler void destroyServletInstance(Servlet s); void destroyFilterInstance(Filter f); void destroyListenerInstance(EventListener f); + + public Decorator cloneFor(ContextHandler context); } } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index 285d233043a..3595f49d543 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -168,11 +168,14 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL throw new IllegalArgumentException("template is started"); _scontext=new Context(); setErrorHandler(new ErrorPageErrorHandler()); + + //Make a new MetaData to hold descriptor and annotation metadata _metadata = template.getMetaData(); _configurations = new Configuration[]{new MetaDataConfiguration(template)}; - System.err.println("webapp "+getContextPath()+" @ "+hashCode()); + // TODO we need some better way to work out what attributes should be copied at this stage. + setAliases(template.isAliases()); setBaseResource(template.getBaseResource()); setClassLoader(template.getClassLoader()); // TODO maybe not share classloader? @@ -182,6 +185,10 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL setLogger(template.getLogger()); // TODO maybe not shared ??? setMaxFormContentSize(template.getMaxFormContentSize()); + Decorator decorator = template.getDecorator(); + if (decorator!=null) + setDecorator(decorator.cloneFor(this)); + Enumeration names=template.getAttributeNames(); while(names.hasMoreElements()) {