You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2009/12/16 18:52:14 UTC

svn commit: r891349 - in /geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src: main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java

Author: rickmcguire
Date: Wed Dec 16 17:52:14 2009
New Revision: 891349

URL: http://svn.apache.org/viewvc?rev=891349&view=rev
Log:
Set the BundleContext as a ServletContext attribute for Tomcat. 


Modified:
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java?rev=891349&r1=891348&r2=891349&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java Wed Dec 16 17:52:14 2009
@@ -72,6 +72,8 @@
 import org.apache.geronimo.webservices.WebServiceContainerFactory;
 import org.apache.naming.resources.DirContextURLStreamHandler;
 
+import org.osgi.framework.Bundle;
+
 /**
  * Wrapper for a WebApplicationContext that sets up its J2EE environment.
  *
@@ -83,6 +85,7 @@
 
     protected final TomcatContainer container;
     private final ClassLoader classLoader;
+    private final Bundle bundle;
     protected Context context = null;
     private String path = null;
     private String docBase = null;
@@ -114,7 +117,7 @@
     // JSR 77
     private final String j2EEServer;
     private final String j2EEApplication;
-    
+
 //  statistics
     private ModuleStats statsProvider;
     private boolean reset = true;
@@ -123,6 +126,7 @@
 
     public TomcatWebAppContext(
             ClassLoader classLoader,
+            Bundle bundle,
             String objectName,
             String originalSpecDD,
             URL configurationBaseUrl,
@@ -154,6 +158,7 @@
             Kernel kernel)
             throws Exception {
         assert classLoader != null;
+        assert bundle != null;
         assert configurationBaseUrl != null;
         assert transactionManager != null;
         assert trackedConnectionAssociator != null;
@@ -176,6 +181,7 @@
         }
         this.setDocBase(root.getPath());
         this.container = container;
+        this.bundle = bundle;
         this.originalSpecDD = originalSpecDD;
 
         this.virtualServer = virtualServer;
@@ -210,7 +216,7 @@
         }
 
         this.displayName = displayName;
-        
+
         //Add the valve list
         if (tomcatValveChain != null){
             ArrayList<Valve> chain = new ArrayList<Valve>();
@@ -223,7 +229,7 @@
         } else {
             valveChain = null;
         }
-        
+
         //Add the Lifecycle Listener list
         if (lifecycleListenerChain != null){
             ArrayList<LifecycleListener> chain = new ArrayList<LifecycleListener>();
@@ -252,7 +258,7 @@
         }
 
         this.crossContext = crossContext;
-        
+
         this.workDir = workDir;
 
         this.disableCookies = disableCookies;
@@ -262,7 +268,7 @@
         this.classLoader = classLoader;
 
         this.kernel = kernel;
-        
+
         if (objectName != null) {
             ObjectName myObjectName = ObjectNameUtil.getObjectName(objectName);
             verifyObjectName(myObjectName);
@@ -272,7 +278,7 @@
             // StandardContext uses default value of these as "none"
             j2EEServer = null;
             j2EEApplication = null;
-        }       
+        }
     }
 
     private Map createWebServices(Map webServiceFactoryMap, Kernel kernel) throws Exception {
@@ -407,7 +413,7 @@
     public Valve getClusteredValve() {
         return clusteredValve;
     }
-    
+
     public List getValveChain() {
         return valveChain;
     }
@@ -431,7 +437,7 @@
     public String getWorkDir() {
         return workDir;
     }
-    
+
     public Map getWebServices(){
         return webServices;
     }
@@ -452,13 +458,13 @@
 
         return result;
     }
-    
+
     public String getDisplayName(){
         return displayName;
     }
 
     public void setDisplayName(String displayName) {
-        this.displayName = displayName;        
+        this.displayName = displayName;
     }
 
     /**
@@ -504,8 +510,8 @@
     public String getDeploymentDescriptor() {
         return originalSpecDD;
     }
-    
-//  JSR 77 statistics - The static values are initialized at the time of 
+
+//  JSR 77 statistics - The static values are initialized at the time of
     // creration, getStats return fresh value everytime
     public Stats getStats() {
         if (reset) {
@@ -514,7 +520,7 @@
         }
         else return statsProvider.updateStats();
     }
-        
+
     public void resetStats() {
         reset = true;
     }
@@ -523,6 +529,8 @@
 
         // See the note of TomcatContainer::addContext
         container.addContext(this);
+        // set the bundle context attribute in the servlet context
+        context.getServletContext().setAttribute("osgi-bundlecontext", bundle.getBundleContext());
         // Is it necessary - doesn't Tomcat Embedded take care of it?
         // super.start();
         //register the classloader <> dir context association so that tomcat's jndi based getResources works.
@@ -566,6 +574,7 @@
         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic("Tomcat WebApplication Context", TomcatWebAppContext.class, NameFactory.WEB_MODULE);
 
         infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
+        infoBuilder.addAttribute("bundle", Bundle.class, false);
         infoBuilder.addAttribute("objectName", String.class, false);
         infoBuilder.addAttribute("deploymentDescriptor", String.class, true);
         infoBuilder.addAttribute("configurationBaseUrl", URL.class, true);
@@ -604,6 +613,7 @@
 
         infoBuilder.setConstructor(new String[] {
                 "classLoader",
+                "bundle",
                 "objectName",
                 "deploymentDescriptor",
                 "configurationBaseUrl",
@@ -632,7 +642,7 @@
                 "ContextCustomizer",
                 "J2EEServer",
                 "J2EEApplication",
-                "kernel"                
+                "kernel"
                 }
         );
 

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?rev=891349&r1=891348&r2=891349&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java Wed Dec 16 17:52:14 2009
@@ -20,6 +20,7 @@
 import org.apache.geronimo.connector.outbound.connectiontracking.GeronimoTransactionListener;
 import org.apache.geronimo.kernel.config.ConfigurationData;
 import org.apache.geronimo.kernel.osgi.MockBundleContext;
+import org.apache.geronimo.kernel.osgi.MockBundle;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.security.SecurityServiceImpl;
 import org.apache.geronimo.security.deploy.PrincipalInfo;
@@ -73,6 +74,7 @@
     protected TomcatWebAppContext setUpInsecureAppContext(URI relativeWebAppRoot, URL configurationBaseURL, SecurityHolder securityHolder, RunAsSource runAsSource, ObjectRetriever tomcatRealm, ValveGBean valveChain) throws Exception {
 
         TomcatWebAppContext app = new TomcatWebAppContext(cl,
+                new MockBundle(cl, "", 0L),
                 null,
                 null,
                 new URL(configurationBaseURL, relativeWebAppRoot.getPath()),