[jboss-cvs] JBossAS SVN: r95283 - in projects/jboss-osgi/projects/bundles/webapp/trunk: src/main/java/org/jboss/osgi/webapp and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 21 08:48:57 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-21 08:48:57 -0400 (Wed, 21 Oct 2009)
New Revision: 95283

Added:
   projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/WebAppCapability.java
   projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppPublisherInterceptor.java
   projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebXMLParserInterceptor.java
Removed:
   projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppInterceptor.java
Modified:
   projects/jboss-osgi/projects/bundles/webapp/trunk/pom.xml
   projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppActivator.java
Log:
Distribute work over multiple interceptors

Modified: projects/jboss-osgi/projects/bundles/webapp/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/webapp/trunk/pom.xml	2009-10-21 12:32:49 UTC (rev 95282)
+++ projects/jboss-osgi/projects/bundles/webapp/trunk/pom.xml	2009-10-21 12:48:57 UTC (rev 95283)
@@ -21,7 +21,7 @@
   <artifactId>jboss-osgi-webapp</artifactId>
   <packaging>bundle</packaging>
 
-  <version>1.0.0-SNAPSHOT</version>
+  <version>0.7.0-SNAPSHOT</version>
   
   <!-- Parent -->
   <parent>
@@ -40,13 +40,23 @@
   <!-- Properties -->
   <properties>
     <version.jboss.osgi.deployment>1.0.0-SNAPSHOT</version.jboss.osgi.deployment>
-    <version.ops4j.pax.web>0.7.1</version.ops4j.pax.web>
-    <version.osgi>r4v42</version.osgi>
+    <version.ops4j.pax.base>1.2.1</version.ops4j.pax.base>
+    <version.ops4j.pax.web>0.7.0</version.ops4j.pax.web>
+    <version.osgi>4.2.0</version.osgi>
   </properties>
   
   <!-- Dependencies -->
   <dependencies>
     <dependency>
+      <!-- 
+        [TODO] Invalid maven dependency on pax base
+        http://issues.ops4j.org/browse/PAXWEB-177 
+      -->
+      <groupId>org.ops4j.base</groupId>
+      <artifactId>ops4j-base-util-xml</artifactId>
+      <version>${version.ops4j.pax.base}</version>
+    </dependency>
+    <dependency>
       <groupId>org.ops4j.pax.web</groupId>
       <artifactId>pax-web-api</artifactId>
       <version>${version.ops4j.pax.web}</version>
@@ -90,14 +100,23 @@
           <instructions>
             <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
             <Bundle-Activator>org.jboss.osgi.webapp.internal.WebAppActivator</Bundle-Activator>
-            <Private-Package>org.jboss.osgi.webapp.internal</Private-Package>
+            <Export-Package>
+              org.jboss.osgi.webapp;version=${version}
+            </Export-Package>
+            <Private-Package>
+              org.jboss.osgi.webapp.internal,
+              org.ops4j.pax.web.extender.war.internal,
+            </Private-Package>
             <Import-Package>
                javax.servlet, 
                javax.servlet.http, 
                javax.xml.parsers, 
+               org.apache.commons.logging;version=1.1,
                org.jboss.osgi.deployment.common;version=1.0,
                org.jboss.osgi.deployment.interceptor;version=1.0,
+               org.jboss.osgi.spi.capability;version=1.0,
                org.jboss.virtual,
+               org.ops4j.pax.web.service,
                org.osgi.service.http, 
                org.osgi.framework,
                org.osgi.util.tracker,

Copied: projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/WebAppCapability.java (from rev 95269, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/WebAppCapability.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/WebAppCapability.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/WebAppCapability.java	2009-10-21 12:48:57 UTC (rev 95283)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.webapp;
+
+//$Id: $
+
+import org.jboss.osgi.spi.capability.Capability;
+import org.jboss.osgi.spi.capability.HttpServiceCapability;
+import org.jboss.osgi.spi.testing.OSGiRuntime;
+
+/**
+ * Adds the WebApp (WAR) capability to the {@link OSGiRuntime}
+ * under test. 
+ *
+ * Dependent Capability: {@link HttpServiceCapability}
+ * Installed bundles: pax-web-extender-war.jar
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 07-Oct-2009
+ */
+public class WebAppCapability extends Capability
+{
+   public WebAppCapability()
+   {
+      super(null);
+      
+      addDependency(new HttpServiceCapability());
+
+      addBundle("bundles/jboss-osgi-webapp.jar");
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppActivator.java	2009-10-21 12:32:49 UTC (rev 95282)
+++ projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppActivator.java	2009-10-21 12:48:57 UTC (rev 95283)
@@ -35,23 +35,33 @@
  */
 public class WebAppActivator implements BundleActivator
 {
-   private WebAppPublisherExt publisher;
-   private WebAppInterceptor interceptor;
+   private WebAppPublisherExt paxwebPublisher;
+   private WebXMLParserInterceptor webappParserInterceptor;
+   private WebAppPublisherInterceptor webappPublishInterceptor;
    
    public void start(BundleContext context)
    {
-      publisher = new WebAppPublisherExt();
+      paxwebPublisher = new WebAppPublisherExt();
 
-      interceptor = new WebAppInterceptor(context, publisher);
-      interceptor.start();
+      webappParserInterceptor = new WebXMLParserInterceptor(context);
+      webappParserInterceptor.start();
+
+      webappPublishInterceptor = new WebAppPublisherInterceptor(context, paxwebPublisher);
+      webappPublishInterceptor.start();
    }
 
    public void stop(BundleContext context)
    {
-      if (interceptor != null)
+      if (webappParserInterceptor != null)
       {
-         interceptor.stop();
-         interceptor = null;
+         webappParserInterceptor.stop();
+         webappParserInterceptor = null;
       }
+      
+      if (webappPublishInterceptor != null)
+      {
+         webappPublishInterceptor.stop();
+         webappPublishInterceptor = null;
+      }
    }
 }
\ No newline at end of file

Deleted: projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppInterceptor.java
===================================================================
--- projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppInterceptor.java	2009-10-21 12:32:49 UTC (rev 95282)
+++ projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppInterceptor.java	2009-10-21 12:48:57 UTC (rev 95283)
@@ -1,122 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.webapp.internal;
-
-//$Id$
-
-import java.io.IOException;
-
-import org.jboss.osgi.deployment.common.Deployment;
-import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptor;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
-import org.jboss.virtual.VirtualFile;
-import org.ops4j.pax.web.extender.war.internal.WebAppPublisherExt;
-import org.ops4j.pax.web.extender.war.internal.model.WebApp;
-import org.ops4j.pax.web.extender.war.internal.parser.dom.DOMWebXmlParser;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * The WebApp lifecycle interceptor.
- * 
- * @author thomas.diesler at jboss.com
- * @since 20-Oct-2009
- */
-public class WebAppInterceptor extends AbstractLifecycleInterceptor implements LifecycleInterceptor
-{
-   private BundleContext context;
-   private ServiceTracker serviceTracker;
-   private WebAppPublisherExt publisher;
-   
-   public WebAppInterceptor(BundleContext context, WebAppPublisherExt publisher)
-   {
-      this.context = context;
-      this.publisher = publisher;
-   }
-
-   public void start()
-   {
-      final LifecycleInterceptor interceptor = this;
-      serviceTracker = new ServiceTracker(context, LifecycleInterceptorService.class.getName(), null)
-      {
-         @Override
-         public Object addingService(ServiceReference reference)
-         {
-            LifecycleInterceptorService service = (LifecycleInterceptorService)super.addingService(reference);
-            service.addInterceptor(interceptor);
-            return service;
-         }
-
-         @Override
-         public void removedService(ServiceReference reference, Object service)
-         {
-            ((LifecycleInterceptorService)service).removeInterceptor(interceptor);
-            super.removedService(reference, service);
-         }
-      };
-      serviceTracker.open();
-   }
-   
-   public void stop()
-   {
-      if (serviceTracker != null)
-      {
-         serviceTracker.close();
-         serviceTracker = null;
-      }
-   }
-
-   public void invoke(int state, Deployment dep) throws LifecycleInterceptorException
-   {
-      if (state == Bundle.STARTING)
-      {
-         try
-         {
-            VirtualFile root = dep.getRoot();
-            VirtualFile webXML = root.getChild("/WEB-INF/web.xml");
-            if (webXML != null)
-            {
-               DOMWebXmlParser parser = new DOMWebXmlParser();
-               WebApp webApp = parser.parse(webXML.openStream());
-               dep.addAttachment(WebApp.class, webApp);
-               publisher.publish(webApp);
-            }
-         }
-         catch (IOException ex)
-         {
-            throw new LifecycleInterceptorException("Cannot parse web.xml", ex);
-         }
-      }
-      else if (state == Bundle.STOPPING)
-      {
-         WebApp webApp = dep.getAttachment(WebApp.class);
-         if (webApp != null)
-         {
-            publisher.unpublish(webApp);
-         }
-      }
-   }
-}
\ No newline at end of file

Added: projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppPublisherInterceptor.java
===================================================================
--- projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppPublisherInterceptor.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppPublisherInterceptor.java	2009-10-21 12:48:57 UTC (rev 95283)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.webapp.internal;
+
+//$Id$
+
+import org.jboss.osgi.deployment.common.Deployment;
+import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
+import org.ops4j.pax.web.extender.war.internal.WebAppPublisherExt;
+import org.ops4j.pax.web.extender.war.internal.model.WebApp;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * The WebApp lifecycle interceptor.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 20-Oct-2009
+ */
+public class WebAppPublisherInterceptor extends AbstractLifecycleInterceptor implements LifecycleInterceptor
+{
+   private BundleContext context;
+   private ServiceTracker serviceTracker;
+   private WebAppPublisherExt publisher;
+
+   public WebAppPublisherInterceptor(BundleContext context, WebAppPublisherExt publisher)
+   {
+      this.context = context;
+      this.publisher = publisher;
+
+      // Add the required input
+      addInput(WebApp.class);
+   }
+
+   public void start()
+   {
+      final LifecycleInterceptor interceptor = this;
+      serviceTracker = new ServiceTracker(context, LifecycleInterceptorService.class.getName(), null)
+      {
+         @Override
+         public Object addingService(ServiceReference reference)
+         {
+            LifecycleInterceptorService service = (LifecycleInterceptorService)super.addingService(reference);
+            service.addInterceptor(interceptor);
+            return service;
+         }
+
+         @Override
+         public void removedService(ServiceReference reference, Object service)
+         {
+            ((LifecycleInterceptorService)service).removeInterceptor(interceptor);
+            super.removedService(reference, service);
+         }
+      };
+      serviceTracker.open();
+   }
+
+   public void stop()
+   {
+      if (serviceTracker != null)
+      {
+         serviceTracker.close();
+         serviceTracker = null;
+      }
+   }
+
+   public void invoke(int state, Deployment dep) throws LifecycleInterceptorException
+   {
+      if (state == Bundle.STARTING)
+      {
+         WebApp webApp = dep.getAttachment(WebApp.class);
+         publisher.publish(webApp);
+      }
+      else if (state == Bundle.STOPPING)
+      {
+         WebApp webApp = dep.getAttachment(WebApp.class);
+         publisher.unpublish(webApp);
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppPublisherInterceptor.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebXMLParserInterceptor.java (from rev 95268, projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebAppInterceptor.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebXMLParserInterceptor.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/webapp/trunk/src/main/java/org/jboss/osgi/webapp/internal/WebXMLParserInterceptor.java	2009-10-21 12:48:57 UTC (rev 95283)
@@ -0,0 +1,138 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.webapp.internal;
+
+//$Id$
+
+import java.io.IOException;
+
+import org.jboss.osgi.deployment.common.Deployment;
+import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
+import org.jboss.virtual.VirtualFile;
+import org.ops4j.pax.web.extender.war.internal.model.WebApp;
+import org.ops4j.pax.web.extender.war.internal.parser.dom.DOMWebXmlParser;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * The WebApp lifecycle interceptor.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 20-Oct-2009
+ */
+public class WebXMLParserInterceptor extends AbstractLifecycleInterceptor implements LifecycleInterceptor
+{
+   private BundleContext context;
+   private ServiceTracker serviceTracker;
+
+   public WebXMLParserInterceptor(BundleContext context)
+   {
+      this.context = context;
+
+      // Advertise output
+      addOutput(WebApp.class);
+   }
+
+   public void start()
+   {
+      final LifecycleInterceptor interceptor = this;
+      serviceTracker = new ServiceTracker(context, LifecycleInterceptorService.class.getName(), null)
+      {
+         @Override
+         public Object addingService(ServiceReference reference)
+         {
+            LifecycleInterceptorService service = (LifecycleInterceptorService)super.addingService(reference);
+            service.addInterceptor(interceptor);
+            return service;
+         }
+
+         @Override
+         public void removedService(ServiceReference reference, Object service)
+         {
+            ((LifecycleInterceptorService)service).removeInterceptor(interceptor);
+            super.removedService(reference, service);
+         }
+      };
+      serviceTracker.open();
+   }
+
+   public void stop()
+   {
+      if (serviceTracker != null)
+      {
+         serviceTracker.close();
+         serviceTracker = null;
+      }
+   }
+
+   public void invoke(int state, Deployment dep) throws LifecycleInterceptorException
+   {
+      if (state == Bundle.STARTING)
+      {
+         try
+         {
+            VirtualFile webXML = dep.getRoot().getChild("/WEB-INF/web.xml");
+            if (webXML != null)
+            {
+               // Create and attach the the WebApp metadata
+               WebApp webApp = createWebAppMetadata(dep, webXML);
+               dep.addAttachment(WebApp.class, webApp);
+            }
+         }
+         catch (IOException ex)
+         {
+            throw new LifecycleInterceptorException("Cannot parse web.xml", ex);
+         }
+      }
+   }
+
+   private WebApp createWebAppMetadata(Deployment dep, VirtualFile webXML) throws IOException
+   {
+      // Parse the web.xml
+      DOMWebXmlParser parser = new DOMWebXmlParser();
+      WebApp webApp = parser.parse(webXML.openStream());
+
+      // Associate the Bundle with the WebApp metadata 
+      Bundle bundle = dep.getAttachment(Bundle.class);
+      webApp.setBundle(bundle);
+
+      // Set the context name as first looking for a manifest entry named Webapp-Context
+      // if not set use bundle symbolic name
+      String contextName = dep.getManifestHeader("Webapp-Context");
+      if (contextName == null)
+      {
+         contextName = bundle.getSymbolicName();
+      }
+      if ("/".equals(contextName.trim()))
+      {
+         contextName = "";
+      }
+      webApp.setContextName(contextName);
+      
+      return webApp;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list