You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2010/01/25 19:55:40 UTC

svn commit: r902923 - in /geronimo/server/trunk: framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/ plugins/jetty8/geronimo-jetty8/ plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/ plugins/j...

Author: gawor
Date: Mon Jan 25 18:55:39 2010
New Revision: 902923

URL: http://svn.apache.org/viewvc?rev=902923&view=rev
Log:
GERONIMO-5030: Register ServletContext into service registry as mandated by OSGi Web Applications specification

Added:
    geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java   (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/MockBundle.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/src/main/java/org/apache/geronimo/jetty8/handler/GeronimoWebAppContext.java
    geronimo/server/trunk/plugins/jetty8/jetty8-clustering-wadi/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/jetty8/jetty8/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatContainer.java
    geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/wab/geronimo-web/pom.xml

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/MockBundle.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/MockBundle.java?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/MockBundle.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/MockBundle.java Mon Jan 25 18:55:39 2010
@@ -27,6 +27,7 @@
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Map;
 import java.util.Vector;
 
@@ -80,7 +81,7 @@
     }
 
     public Dictionary getHeaders() {
-        return null;
+        return new Hashtable();
     }
 
     public long getBundleId() {

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml (original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8/pom.xml Mon Jan 25 18:55:39 2010
@@ -51,6 +51,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-web</artifactId>
+            <version>${version}</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.geronimo.framework</groupId>
             <artifactId>geronimo-kernel</artifactId>
             <version>${version}</version>

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=902923&r1=902922&r2=902923&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 Mon Jan 25 18:55:39 2010
@@ -23,14 +23,11 @@
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.URLConnection;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.eclipse.jetty.server.Handler;
-import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.handler.ErrorHandler;
 import org.eclipse.jetty.security.SecurityHandler;
@@ -39,8 +36,12 @@
 import org.eclipse.jetty.webapp.WebAppContext;
 import org.eclipse.jetty.util.resource.Resource;
 import org.eclipse.jetty.util.resource.URLResource;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceRegistration;
 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext;
 import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext;
+import org.apache.geronimo.osgi.web.WebApplicationConstants;
+import org.apache.geronimo.osgi.web.WebApplicationUtils;
 
 /**
  * @version $Rev$ $Date$
@@ -49,12 +50,13 @@
 
     private final IntegrationContext integrationContext;
     private final String modulePath;
+    private ServiceRegistration serviceRegistration;
 
     public GeronimoWebAppContext(SecurityHandler securityHandler, SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler, IntegrationContext integrationContext, ClassLoader classLoader, String modulePath) {
         super(sessionHandler, securityHandler, servletHandler, errorHandler);
         this.integrationContext = integrationContext;
         setClassLoader(classLoader);
-        setAttribute("osgi-bundlecontext", integrationContext.getBundle().getBundleContext());
+        setAttribute(WebApplicationConstants.BUNDLE_CONTEXT_ATTRIBUTE, integrationContext.getBundle().getBundleContext());
         this.modulePath = modulePath;
     }
 
@@ -74,10 +76,18 @@
             integrationContext.restoreContext(context);
             integrationContext.completeTx(txActive, null);
         }
+        // for OSGi Web Applications support register ServletContext in service registry
+        Bundle bundle = integrationContext.getBundle();
+        if (WebApplicationUtils.isWebApplicationBundle(bundle)) {
+            serviceRegistration = WebApplicationUtils.registerServletContext(bundle, getServletContext());
+        }
     }
 
     @Override
     protected void doStop() throws Exception {
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
+        }
         javax.naming.Context context = integrationContext.setContext();
         boolean txActive = integrationContext.isTxActive();
         SharedConnectorInstanceContext newContext = integrationContext.newConnectorInstanceContext(null);

Modified: geronimo/server/trunk/plugins/jetty8/jetty8-clustering-wadi/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/jetty8-clustering-wadi/src/main/history/dependencies.xml?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/jetty8-clustering-wadi/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/jetty8/jetty8-clustering-wadi/src/main/history/dependencies.xml Mon Jan 25 18:55:39 2010
@@ -32,6 +32,11 @@
         <type>jar</type>
     </dependency>
     <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-web</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
         <groupId>org.eclipse.jetty</groupId>
         <artifactId>jetty-jaspi</artifactId>
         <type>jar</type>

Modified: geronimo/server/trunk/plugins/jetty8/jetty8/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/jetty8/src/main/history/dependencies.xml?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/jetty8/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/jetty8/jetty8/src/main/history/dependencies.xml Mon Jan 25 18:55:39 2010
@@ -37,6 +37,11 @@
         <type>jar</type>
     </dependency>
     <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-web</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
         <groupId>org.eclipse.jetty</groupId>
         <artifactId>jetty-ajp</artifactId>
         <type>jar</type>

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/pom.xml Mon Jan 25 18:55:39 2010
@@ -47,6 +47,12 @@
             <version>${version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-web</artifactId>
+            <version>${version}</version>
+        </dependency>
+
         <!-- g-security comes from this -->
         <dependency>
             <groupId>org.apache.geronimo.framework</groupId>

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java Mon Jan 25 18:55:39 2010
@@ -45,6 +45,7 @@
 import org.apache.catalina.valves.ValveBase;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.common.GeronimoSecurityException;
+import org.apache.geronimo.osgi.web.WebApplicationUtils;
 import org.apache.geronimo.security.ContextManager;
 import org.apache.geronimo.security.jaas.ConfigurationFactory;
 import org.apache.geronimo.security.jacc.RunAsSource;
@@ -60,6 +61,8 @@
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.geronimo.webservices.WebServiceContainerInvoker;
 import org.apache.tomcat.InstanceManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceRegistration;
 
 
 /**
@@ -87,11 +90,16 @@
     private boolean authenticatorInstalled;
     private ConfigurationFactory configurationFactory;
     private String policyContextId;
+    
+    private Bundle bundle;
+    private ServiceRegistration serviceRegistration;
 
     public GeronimoStandardContext() {
     }
 
     public void setContextProperties(TomcatContext ctx) throws DeploymentException {
+        bundle = ctx.getBundle();
+        
         setResources(new BundleDirContext(ctx.getBundle(), ctx.getModulePath()));
 
         // Create ReadOnlyContext
@@ -304,6 +312,10 @@
     }
 
     public void kill() throws Exception {
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
+        }
+        
         Object context[] = null;
 
         if (beforeAfter != null){
@@ -359,6 +371,11 @@
         } else {
             super.start();
         }
+        
+        // for OSGi Web Applications support register ServletContext in service registry
+        if (WebApplicationUtils.isWebApplicationBundle(bundle)) {
+            serviceRegistration = WebApplicationUtils.registerServletContext(bundle, getServletContext());
+        }
     }
 
     public void addChild(Container child) {

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatContainer.java?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatContainer.java (original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatContainer.java Mon Jan 25 18:55:39 2010
@@ -46,6 +46,7 @@
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.management.geronimo.NetworkConnector;
 import org.apache.geronimo.management.geronimo.WebManager;
+import org.apache.geronimo.osgi.web.WebApplicationConstants;
 import org.apache.geronimo.security.jaas.ConfigurationFactory;
 import org.apache.geronimo.security.ContextManager;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
@@ -283,7 +284,8 @@
         }
         context.setParent(host);
         // set the bundle context attribute in the servlet context
-        context.getServletContext().setAttribute("osgi-bundlecontext", contextInfo.getBundle().getBundleContext());
+        context.getServletContext().setAttribute(WebApplicationConstants.BUNDLE_CONTEXT_ATTRIBUTE, 
+                                                 contextInfo.getBundle().getBundleContext());
 
         // Set the context for the Tomcat implementation
         contextInfo.setContext(context);

Modified: geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/history/dependencies.xml?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/history/dependencies.xml Mon Jan 25 18:55:39 2010
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<plugin-artifact xmlns="http://geronimo.apache.org/xml/ns/plugins-1.3" xmlns:ns2="http://geronimo.apache.org/xml/ns/attributes-1.2">
+<plugin-artifact xmlns:ns2="http://geronimo.apache.org/xml/ns/attributes-1.2" xmlns="http://geronimo.apache.org/xml/ns/plugins-1.3">
     <module-id>
         <groupId>org.apache.geronimo.configs</groupId>
         <artifactId>tomcat7</artifactId>
@@ -58,6 +58,11 @@
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-web</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
         <artifactId>geronimo-webservices</artifactId>
         <type>jar</type>
     </dependency>

Modified: geronimo/server/trunk/plugins/wab/geronimo-web/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/wab/geronimo-web/pom.xml?rev=902923&r1=902922&r2=902923&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/wab/geronimo-web/pom.xml (original)
+++ geronimo/server/trunk/plugins/wab/geronimo-web/pom.xml Mon Jan 25 18:55:39 2010
@@ -50,6 +50,11 @@
             <groupId>org.ops4j.pax.logging</groupId>
             <artifactId>pax-logging-api</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-servlet_3.0_spec</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

Added: geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java?rev=902923&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java (added)
+++ geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java Mon Jan 25 18:55:39 2010
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.osgi.web;
+
+import java.util.Hashtable;
+
+import javax.servlet.ServletContext;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+public class WebApplicationUtils {
+
+    public static boolean isWebApplicationBundle(Bundle bundle) {
+        return (bundle != null && bundle.getHeaders().get(WebApplicationConstants.CONTEXT_PATH_HEADER) != null);
+    }
+    
+    public static ServiceRegistration registerServletContext(BundleContext bundleContext, ServletContext context) {   
+        return registerServletContext(bundleContext.getBundle(), context);
+    }
+    
+    public static ServiceRegistration registerServletContext(Bundle bundle, ServletContext context) {        
+        Hashtable<String, String> properties = new Hashtable<String, String>();
+        properties.put(WebApplicationConstants.WEB_SYMBOLIC_NAME, bundle.getSymbolicName());
+        String version = (String) bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+        if (version != null) {
+            properties.put(WebApplicationConstants.WEB_VERSION, version);
+        }
+        properties.put(WebApplicationConstants.WEB_CONTEXT_PATH, context.getContextPath());
+        return bundle.getBundleContext().registerService(ServletContext.class.getName(), context, properties);
+    }
+    
+}

Propchange: geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/wab/geronimo-web/src/main/java/org/apache/geronimo/osgi/web/WebApplicationUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain