geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1005218 - in /geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src: main/java/org/apache/geronimo/jetty8/ main/java/org/apache/geronimo/jetty8/handler/ test/java/org/apache/geronimo/jetty8/
Date Wed, 06 Oct 2010 19:54:06 GMT
Author: djencks
Date: Wed Oct  6 19:54:06 2010
New Revision: 1005218

URL: http://svn.apache.org/viewvc?rev=1005218&view=rev
Log:
GERONIMO-5508 implement ServletContainerInitializer support for jetty similar to tomcat

Modified:
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/test/java/org/apache/geronimo/jetty8/AbstractWebModuleTest.java

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java?rev=1005218&r1=1005217&r2=1005218&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java
(original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/WebAppContextWrapper.java
Wed Oct  6 19:54:06 2010
@@ -19,7 +19,9 @@ package org.apache.geronimo.jetty8;
 
 import java.net.URL;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -27,6 +29,7 @@ import javax.management.MalformedObjectN
 import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.security.auth.Subject;
+import javax.servlet.ServletContainerInitializer;
 import javax.servlet.SessionCookieConfig;
 import javax.transaction.TransactionManager;
 import javax.transaction.UserTransaction;
@@ -55,6 +58,7 @@ import org.apache.geronimo.management.ge
 import org.apache.geronimo.security.jacc.ApplicationPolicyConfigurationManager;
 import org.apache.geronimo.security.jacc.RunAsSource;
 import org.apache.geronimo.transaction.GeronimoUserTransaction;
+import org.apache.geronimo.web.WebAttributeName;
 import org.apache.geronimo.web.info.ErrorPageInfo;
 import org.apache.geronimo.web.info.WebAppInfo;
 import org.eclipse.jetty.http.MimeTypes;
@@ -130,8 +134,8 @@ public class WebAppContextWrapper implem
                                 @ParamReference(name = "ContextSource") ContextSource contextSource,
                                 @ParamReference(name = "TransactionManager") TransactionManager
transactionManager,
 
-                                @ParamAttribute(name = "deploymentAttributes") Map<String,
Object> deploymentAttributes,
-                                @ParamSpecial(type = SpecialAttributeType.kernel) Kernel
kernel) throws Exception {
+                                @ParamAttribute(name = "deploymentAttributes") Map<String,
Object> deploymentAttributes
+    ) throws Exception {
 
         assert contextSource != null;
         assert classLoader != null;
@@ -172,7 +176,38 @@ public class WebAppContextWrapper implem
 
         Context componentContext = contextSource.getContext();
         UserTransaction userTransaction = new GeronimoUserTransaction(transactionManager);
-        IntegrationContext integrationContext = new IntegrationContext(componentContext,
unshareableResources, applicationManagedSecurityResources, trackedConnectionAssociator, userTransaction,
bundle, holder);
+        Map<ServletContainerInitializer, Set<Class<?>>> servletContainerInitializerMap
= new LinkedHashMap<ServletContainerInitializer, Set<Class<?>>>();
+        //Set ServletContainerInitializer
+        Map<String, Set<String>> servletContainerInitializerClassNamesMap = (Map<String,
Set<String>>) deploymentAttributes.get(WebAttributeName.SERVLET_CONTAINER_INITIALIZERS.name());
+        if (servletContainerInitializerClassNamesMap != null) {
+            for (Map.Entry<String, Set<String>> entry : servletContainerInitializerClassNamesMap.entrySet())
{
+                String servletContainerInitializerClassName = entry.getKey();
+                Set<String> classNames = entry.getValue();
+                try {
+                    ServletContainerInitializer servletContainerInitializer = (ServletContainerInitializer)
bundle.loadClass(servletContainerInitializerClassName).newInstance();
+                    if (classNames == null || classNames.size() == 0) {
+                        servletContainerInitializerMap.put(servletContainerInitializer, null);
+                    } else {
+                        Set<Class<?>> classSet = new HashSet<Class<?>>();
+                        for (String cls : classNames) {
+                            try {
+                                classSet.add(bundle.loadClass(cls));
+                            } catch (ClassNotFoundException e) {
+                                log.warn("Fail to load class " + cls + " interested by ServletContainerInitializer
" + servletContainerInitializerClassName, e);
+                            }
+                        }
+                        servletContainerInitializerMap.put(servletContainerInitializer, classSet);
+                    }
+                } catch (IllegalAccessException e) {
+                    log.error("Fail to initialize ServletContainerInitializer " + servletContainerInitializerClassName,
e);
+                } catch (InstantiationException e) {
+                    log.error("Fail to initialize ServletContainerInitializer " + servletContainerInitializerClassName,
e);
+                } catch (ClassNotFoundException e) {
+                    log.error("Fail to initialize ServletContainerInitializer " + servletContainerInitializerClassName,
e);
+                }
+            }
+        }
+        IntegrationContext integrationContext = new IntegrationContext(componentContext,
unshareableResources, applicationManagedSecurityResources, trackedConnectionAssociator, userTransaction,
bundle, holder, servletContainerInitializerMap);
         webAppContext = new GeronimoWebAppContext(securityHandler, sessionHandler, servletHandler,
null, integrationContext, classLoader, modulePath, webAppInfo, policyContextID, applicationPolicyConfigurationManager);
         webAppContext.setContextPath(contextPath);
         //See Jetty-386.  Setting this to true can expose secured content.
@@ -281,9 +316,9 @@ public class WebAppContextWrapper implem
         return true;
     }
 
-    public URL getWARDirectory() {
-        throw new RuntimeException("don't call this");
-    }
+//    public URL getWARDirectory() {
+//        throw new RuntimeException("don't call this");
+//    }
 
     public String getWARName() {
         //todo: make this return something more consistent
@@ -337,11 +372,6 @@ public class WebAppContextWrapper implem
         return webAppContext.getDisplayName();
     }
 
-//    public void setDisplayName(String displayName) {
-//        this.displayName = displayName;
-//        this.webAppContext.setDisplayName(displayName);
-//    }
-
     public String getDeploymentDescriptor() {
         return originalSpecDD;
     }

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java?rev=1005218&r1=1005217&r2=1005218&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
(original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
Wed Oct  6 19:54:06 2010
@@ -36,6 +36,7 @@ import javax.security.auth.login.LoginEx
 import javax.security.jacc.PolicyContextException;
 import javax.servlet.Filter;
 import javax.servlet.Servlet;
+import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRegistration;
 import javax.servlet.ServletRegistration.Dynamic;
@@ -142,6 +143,9 @@ public class GeronimoWebAppContext exten
                 assembler.assemble(getServletContext(), webAppInfo);
                 webSecurityConstraintStore.setAnnotationScanRequired(true);
                 ((GeronimoWebAppContext.Context) _scontext).webXmlProcessed = true;
+                for (Map.Entry<ServletContainerInitializer, Set<Class<?>>>
entry: integrationContext.getServletContainerInitializerMap().entrySet()) {
+                     entry.getKey().onStartup(entry.getValue(), getServletContext());
+                }
                 super.doStart();
                 if (applicationPolicyConfigurationManager != null) {
                     SpecSecurityBuilder specSecurityBuilder = new SpecSecurityBuilder(webSecurityConstraintStore.exportMergedWebAppInfo());

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java?rev=1005218&r1=1005217&r2=1005218&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java
(original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/IntegrationContext.java
Wed Oct  6 19:54:06 2010
@@ -20,9 +20,12 @@
 
 package org.apache.geronimo.jetty8.handler;
 
+import java.util.Collections;
+import java.util.Map;
 import java.util.Set;
 
 import javax.naming.Context;
+import javax.servlet.ServletContainerInitializer;
 import javax.transaction.UserTransaction;
 import javax.transaction.Status;
 import javax.transaction.SystemException;
@@ -35,6 +38,7 @@ import org.apache.geronimo.connector.out
 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext;
 import org.apache.geronimo.j2ee.annotation.Holder;
 import org.apache.geronimo.naming.java.RootContext;
+import org.castor.cache.distributed.EHCache;
 import org.eclipse.jetty.server.Request;
 import org.osgi.framework.Bundle;
 
@@ -50,8 +54,9 @@ public class IntegrationContext {
     private final UserTransaction userTransaction;
     private final Bundle bundle;
     private final Holder holder;
+    private final Map<ServletContainerInitializer, Set<Class<?>>> servletContainerInitializerMap;
 
-    public IntegrationContext(Context componentContext, Set<String> unshareableResources,
Set<String> applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator,
UserTransaction userTransaction, Bundle bundle, Holder holder) {
+    public IntegrationContext(Context componentContext, Set<String> unshareableResources,
Set<String> applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator,
UserTransaction userTransaction, Bundle bundle, Holder holder, Map<ServletContainerInitializer,
Set<Class<?>>> servletContainerInitializerMap) {
         this.componentContext = componentContext;
         this.unshareableResources = unshareableResources;
         this.applicationManagedSecurityResources = applicationManagedSecurityResources;
@@ -59,6 +64,7 @@ public class IntegrationContext {
         this.userTransaction = userTransaction;
         this.bundle = bundle;
         this.holder = holder;
+        this.servletContainerInitializerMap = servletContainerInitializerMap == null? Collections.<ServletContainerInitializer,
Set<Class<?>>>emptyMap(): servletContainerInitializerMap;
     }
 
     public Context getComponentContext() {
@@ -163,5 +169,8 @@ public class IntegrationContext {
             }
         }
     }
-    
+
+    public Map<ServletContainerInitializer, Set<Class<?>>> getServletContainerInitializerMap()
{
+        return servletContainerInitializerMap;
+    }
 }

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/test/java/org/apache/geronimo/jetty8/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/test/java/org/apache/geronimo/jetty8/AbstractWebModuleTest.java?rev=1005218&r1=1005217&r2=1005218&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/test/java/org/apache/geronimo/jetty8/AbstractWebModuleTest.java
(original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/test/java/org/apache/geronimo/jetty8/AbstractWebModuleTest.java
Wed Oct  6 19:54:06 2010
@@ -178,8 +178,8 @@ public class AbstractWebModuleTest exten
                 null,
                 contextSource,
                 transactionManager,
-                deploymentAttributes,
-                null);
+                deploymentAttributes
+        );
         app.doStart();
         return app;
     }



Mime
View raw message