[Carbon-dev] svn commit r14411 - in trunk/carbon: . core/conf core/src/org/wso2/carbon/servlet distribution/assembly osgi/system osgi/tomcat-embed osgi/tomcat-embed/src/org/wso2/carbon/tomcat/embed samples/osgi_bundle1

svn at wso2.org svn at wso2.org
Sun Mar 2 05:59:17 PST 2008


Author: saminda
Date: Sun Mar  2 05:58:29 2008
New Revision: 14411

Log:

Improvements to TomcatServer


Modified:
   trunk/carbon/core/conf/felix.config.properties
   trunk/carbon/core/conf/server.xml
   trunk/carbon/core/src/org/wso2/carbon/servlet/ActionControllerServlet.java
   trunk/carbon/distribution/assembly/bin.xml
   trunk/carbon/osgi/system/pom.xml
   trunk/carbon/osgi/tomcat-embed/pom.xml
   trunk/carbon/osgi/tomcat-embed/src/org/wso2/carbon/tomcat/embed/TomcatServer.java
   trunk/carbon/pom.xml
   trunk/carbon/samples/osgi_bundle1/pom.xml

Modified: trunk/carbon/core/conf/felix.config.properties
==============================================================================
--- trunk/carbon/core/conf/felix.config.properties	(original)
+++ trunk/carbon/core/conf/felix.config.properties	Sun Mar  2 05:58:29 2008
@@ -76,6 +76,7 @@
  org.w3c.dom, \
  org.apache.log4j, \
  org.wso2.carbon.action, \
+ org.wso2.carbon.util, \
  com.sun.net.ssl, \
  com.sun.jdmk.comm, \
  com.sun.net.ssl.internal.ssl, \
@@ -247,3 +248,4 @@
 carbon.tomcat.work.dir=${carbon.home}/tmp/work
 #carbon.tomcat.host.name=localhost
 #obr.repository.url=http://bundles.osgi.org/obr/browse?_xml=1&cmd=repository
+carbon.server.xml.location=${carbon.home}/conf/server.xml

Modified: trunk/carbon/core/conf/server.xml
==============================================================================
--- trunk/carbon/core/conf/server.xml	(original)
+++ trunk/carbon/core/conf/server.xml	Sun Mar  2 05:58:29 2008
@@ -19,6 +19,6 @@
     <!-- Carbon primary context -->
     <primary-context>carbon</primary-context>
 
-    <component-repository-location>${carbon.home}/webapps/carbon/WEB-INF/lib</component-repository-location>
+    <component-repository-location>${carbon.home}/repository/osgi/component</component-repository-location>
 
 </config>

Modified: trunk/carbon/core/src/org/wso2/carbon/servlet/ActionControllerServlet.java
==============================================================================
--- trunk/carbon/core/src/org/wso2/carbon/servlet/ActionControllerServlet.java	(original)
+++ trunk/carbon/core/src/org/wso2/carbon/servlet/ActionControllerServlet.java	Sun Mar  2 05:58:29 2008
@@ -140,16 +140,22 @@
         public void serviceChanged(ServiceEvent event) {
             if (event.getType() == ServiceEvent.REGISTERED) {
                 ServiceReference ref = event.getServiceReference();
-                Action action = (Action) EmbeddedFelix.felix.getBundleContext().getService(ref);
-                if (action != null) {
-                    serviceActionMap.put(action.getName(), action);
+                Object service = EmbeddedFelix.felix.getBundleContext().getService(ref);
+                if (service instanceof Action) {
+                    Action action = (Action) service;
+                    if (action != null) {
+                        serviceActionMap.put(action.getName(), action);
+                    }
                 }
             } else if (event.getType() == ServiceEvent.UNREGISTERING) {
                 ServiceReference ref = event.getServiceReference();
-                Action action = (Action) EmbeddedFelix.felix.getBundleContext().getService(ref);
-                if (action != null) {
-                    synchronized (serviceActionMap) {
-                        serviceActionMap.remove(action.getName());
+                Object service = EmbeddedFelix.felix.getBundleContext().getService(ref);
+                if (service instanceof Action) {
+                    Action action = (Action) service;
+                    if (action != null) {
+                        synchronized (serviceActionMap) {
+                            serviceActionMap.remove(action.getName());
+                        }
                     }
                 }
             }

Modified: trunk/carbon/distribution/assembly/bin.xml
==============================================================================
--- trunk/carbon/distribution/assembly/bin.xml	(original)
+++ trunk/carbon/distribution/assembly/bin.xml	Sun Mar  2 05:58:29 2008
@@ -63,12 +63,12 @@
 
         <file>
             <source>../osgi/system/target/system-${version}.jar</source>
-            <outputDirectory>${platform.dir}/webapps/carbon/WEB-INF/lib</outputDirectory>
+            <outputDirectory>${platform.dir}/repository/osgi/component</outputDirectory>
         </file>
 
         <file>
             <source>../samples/osgi_bundle1/target/osgi_bundle1-${version}.jar</source>
-            <outputDirectory>${platform.dir}/webapps/carbon/WEB-INF/lib</outputDirectory>
+            <outputDirectory>${platform.dir}/repository/osgi/component</outputDirectory>
         </file>
 
         <file>

Modified: trunk/carbon/osgi/system/pom.xml
==============================================================================
--- trunk/carbon/osgi/system/pom.xml	(original)
+++ trunk/carbon/osgi/system/pom.xml	Sun Mar  2 05:58:29 2008
@@ -16,12 +16,12 @@
         <dependency>
             <groupId>org.wso2.carbon</groupId>
             <artifactId>wso2carbon-core</artifactId>
-            <version>${pom.version}</version>
-            <scope>compile</scope>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.framework</artifactId>
+            <scope>provided</scope>
             <exclusions>
                 <exclusion>
                     <groupId>org.apache.felix</groupId>
@@ -32,7 +32,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.osgi.compendium</artifactId>
-            <scope>compile</scope>
+            <scope>provided</scope>
             <exclusions>
                 <exclusion>
                     <groupId>org.apache.felix</groupId>

Modified: trunk/carbon/osgi/tomcat-embed/pom.xml
==============================================================================
--- trunk/carbon/osgi/tomcat-embed/pom.xml	(original)
+++ trunk/carbon/osgi/tomcat-embed/pom.xml	Sun Mar  2 05:58:29 2008
@@ -15,6 +15,12 @@
     <dependencies>
 
         <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>wso2carbon-core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.framework</artifactId>
             <scope>provided</scope>
@@ -215,11 +221,7 @@
                             org.wso2.carbon.tomcat.embed,
                             org.wso2.carbon.tomcat.embed.connector
                         </Export-Package>
-                        <Private-Package>
-                            org.wso2.carbon.tomcat.embed,
-                            org.wso2.carbon.tomcat.embed.connector
-                        </Private-Package>
-                        <Import-Package>*;resolution:=optional</Import-Package>
+                        <Import-Package>*</Import-Package>
                         <Bundle-Version>5.5.23</Bundle-Version>
                         <DynamicImport-Package>*</DynamicImport-Package>
                         <!--<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>-->

Modified: trunk/carbon/osgi/tomcat-embed/src/org/wso2/carbon/tomcat/embed/TomcatServer.java
==============================================================================
--- trunk/carbon/osgi/tomcat-embed/src/org/wso2/carbon/tomcat/embed/TomcatServer.java	(original)
+++ trunk/carbon/osgi/tomcat-embed/src/org/wso2/carbon/tomcat/embed/TomcatServer.java	Sun Mar  2 05:58:29 2008
@@ -20,15 +20,17 @@
 import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.loader.WebappLoader;
 import org.apache.catalina.realm.MemoryRealm;
 import org.apache.catalina.startup.Embedded;
+import org.osgi.framework.BundleContext;
 import org.wso2.carbon.tomcat.embed.connector.Http;
 import org.wso2.carbon.tomcat.embed.connector.Https;
-import org.osgi.framework.BundleContext;
+import org.wso2.carbon.util.ServerConfiguration;
 
 import java.io.File;
 import java.io.FileFilter;
-import java.net.SocketException;
+import java.net.MalformedURLException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -46,8 +48,7 @@
         embedded = EmbeddedTomcatCache.getInstance();
     }
 
-    public void start(BundleContext context)
-            throws LifecycleException, SocketException {
+    public void start(BundleContext context) throws Exception {
         String hostName = context.getProperty("carbon.tomcat.host.name");
         if (hostName != null) {
             NetworkUtils.init(hostName);
@@ -73,7 +74,7 @@
         workDir = workDir.replaceFirst("\\$\\{carbon.home\\}", System.getProperty(CARBON_HOME));
         ((StandardHost) defaultHost).setWorkDir(workDir);
 
-        new InitialRepositoryListener(webappsDir, defaultHost).register();
+        new InitialRepositoryListener(context, webappsDir, defaultHost).register();
         /*adding connectors */
         String httpPortStr = context.getProperty("carbon.tomcat.http.port");
         String httpsPortStr = context.getProperty("carbon.tomcat.https.part");
@@ -117,14 +118,48 @@
         }
     }
 
+    private class ComponentFilter implements FileFilter {
+        public boolean accept(File pathname) {
+            return pathname.isFile() && pathname.getName().endsWith(".jar");
+        }
+    }
+
     private class InitialRepositoryListener {
         private String webappsHome;
         private Host host;
         private Map<String, File> warMap = new HashMap<String, File>();
+        WebappLoader loader;
 
-        public InitialRepositoryListener(String webappsHome, Host host) {
+        public InitialRepositoryListener(BundleContext context, String webappsHome, Host host)
+                throws Exception {
             this.webappsHome = webappsHome;
             this.host = host;
+            String serverXmlLocation = context.getProperty("carbon.server.xml.location");
+            if (serverXmlLocation == null || serverXmlLocation.length() == 0) {
+                throw new Exception("server.xml is not available.");
+            }
+            serverXmlLocation = serverXmlLocation
+                    .replaceFirst("\\$\\{carbon.home\\}", System.getProperty(CARBON_HOME));
+            ServerConfiguration serverConfiguration = ServerConfiguration.getInstance();
+            serverConfiguration.init(serverXmlLocation);
+            String osgiComponentRepoLocation =
+                    serverConfiguration.getFirstProperty("component-repository-location");
+            if (osgiComponentRepoLocation == null || osgiComponentRepoLocation.length() == 0) {
+                throw new Exception("OSGi component location is not available");
+            }
+
+            try {
+                File osgiCompFile = new File(osgiComponentRepoLocation);
+                File[] componentFiles = osgiCompFile.listFiles(new ComponentFilter());
+                loader = new WebappLoader();
+                if (componentFiles != null && componentFiles.length > 0) {
+                    for (File file : componentFiles) {
+                        loader.addRepository(file.toURL().toString());
+                    }
+                }
+            } catch (MalformedURLException e) {
+                throw new Exception(e);
+            }
         }
 
         public void register() {
@@ -148,7 +183,8 @@
                                 defaultContext = embedded.createContext("/" + dirName,
                                                                         context.getAbsolutePath());
                             }
-                            defaultContext.setReloadable(false);
+                            defaultContext.setLoader(loader);
+                            defaultContext.setReloadable(true);
                             host.addChild(defaultContext);
                         }
 
@@ -177,7 +213,8 @@
             for (String key : keySet) {
                 Context context =
                         embedded.createContext("/" + key, warMap.get(key).getAbsolutePath());
-                context.setReloadable(false);
+                context.setLoader(loader);
+                context.setReloadable(true);
                 host.addChild(context);
             }
         }

Modified: trunk/carbon/pom.xml
==============================================================================
--- trunk/carbon/pom.xml	(original)
+++ trunk/carbon/pom.xml	Sun Mar  2 05:58:29 2008
@@ -300,18 +300,24 @@
             <dependency>
                 <groupId>javax.servlet</groupId>
                 <artifactId>servlet-api</artifactId>
-                <version>2.4</version>
+                <version>${servlet.api.version}</version>
             </dependency>
 
             <dependency>
                 <groupId>javax.servlet</groupId>
                 <artifactId>jstl</artifactId>
-                <version>1.1.2</version>
+                <version>${taglibs.version}</version>
             </dependency>
             <dependency>
                 <groupId>taglibs</groupId>
                 <artifactId>standard</artifactId>
-                <version>1.1.2</version>
+                <version>${taglibs.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.wso2.carbon</groupId>
+                <artifactId>wso2carbon-core</artifactId>
+                <version>${version}</version>
             </dependency>
 
         </dependencies>
@@ -361,6 +367,8 @@
         <commons.digester.version>1.8</commons.digester.version>
         <commons.beanutils.version>1.7.0</commons.beanutils.version>
         <annogen.version>0.1.0</annogen.version>
+        <servlet.api.version>2.4</servlet.api.version>
+        <taglibs.version>1.1.2</taglibs.version>
 
         <xmlschema.version>SNAPSHOT</xmlschema.version>
         <axiom.version>SNAPSHOT</axiom.version>

Modified: trunk/carbon/samples/osgi_bundle1/pom.xml
==============================================================================
--- trunk/carbon/samples/osgi_bundle1/pom.xml	(original)
+++ trunk/carbon/samples/osgi_bundle1/pom.xml	Sun Mar  2 05:58:29 2008
@@ -16,11 +16,12 @@
         <dependency>
             <groupId>org.wso2.carbon</groupId>
             <artifactId>wso2carbon-core</artifactId>
-            <version>${pom.version}</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.framework</artifactId>
+            <scope>provided</scope>
             <exclusions>
                 <exclusion>
                     <groupId>org.apache.felix</groupId>
@@ -31,6 +32,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
             <exclusions>
                 <exclusion>
                     <groupId>org.apache.felix</groupId>



More information about the Carbon-dev mailing list