[jboss-cvs] JBossAS SVN: r95563 - in projects/jboss-osgi/trunk: distribution/installer/src/main/resources/runtime/server/conf and 12 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 26 08:01:13 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-26 08:01:12 -0400 (Mon, 26 Oct 2009)
New Revision: 95563

Added:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java
Modified:
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
   projects/jboss-osgi/trunk/testsuite/example/pom.xml
   projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/ParserInterceptor.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/PublisherInterceptor.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppInterceptorTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF
Log:
Add bootstrap support for lifecycle interceptors

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml	2009-10-26 12:01:12 UTC (rev 95563)
@@ -129,11 +129,23 @@
   </bean>
   <bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+    <incallback method="addInterceptor" />
+    <uncallback method="removeInterceptor" />
   </bean>
   
   <!--
   ********************************
   *                              *  
+  *  OSGi Interceptors           *
+  *                              *
+  ********************************
+  -->
+  
+  <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.deployers.WebXMLVerifierInterceptor"/>
+  
+  <!--
+  ********************************
+  *                              *  
   *  OSGi Deployment             *
   *                              *
   ********************************

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml	2009-10-26 12:01:12 UTC (rev 95563)
@@ -121,11 +121,23 @@
   </bean>
   <bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+    <incallback method="addInterceptor" />
+    <uncallback method="removeInterceptor" />
   </bean>
   
   <!--
   ********************************
   *                              *  
+  *  OSGi Interceptors           *
+  *                              *
+  ********************************
+  -->
+  
+  <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.deployers.WebXMLVerifierInterceptor"/>
+  
+  <!--
+  ********************************
+  *                              *  
   *  OSGi Deployment             *
   *                              *
   ********************************

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -60,10 +60,12 @@
    
    protected AbstractLifecycleInterceptorService(BundleContext context)
    {
+      if (context == null)
+         throw new IllegalStateException("Null context");
       this.context = context;
    }
    
-   public BundleContext getBundleContext()
+   public BundleContext getSystemContext()
    {
       return context;
    }
@@ -219,7 +221,7 @@
          
          String name = bundle.getSymbolicName();
          Version version = bundle.getVersion();
-         Deployment dep = getDeployment(name, version);
+         Deployment dep = getDeployment(getSystemContext(), name, version);
          if (dep == null)
             throw new IllegalStateException("Cannot get deployment for: " + name + "-" + version);
          
@@ -257,5 +259,5 @@
    /**
     * Get the deployment for the given bundle symbolic name and version 
     */
-   protected abstract Deployment getDeployment(String symbolicName, Version version);
+   protected abstract Deployment getDeployment(BundleContext context, String symbolicName, Version version);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -45,7 +45,7 @@
    {
       super(context);
    }
-   
+
    @Override
    public List<LifecycleInterceptor> getInterceptorChain()
    {
@@ -53,18 +53,18 @@
    }
 
    @Override
-   protected Deployment getDeployment(String symbolicName, Version version)
+   protected Deployment getDeployment(BundleContext context, String symbolicName, Version version)
    {
-      DeploymentRegistryService service = getDeploymentRegistryService();
+      DeploymentRegistryService service = getDeploymentRegistryService(context);
       return service.getDeployment(symbolicName, version);
    }
 
-   private DeploymentRegistryService getDeploymentRegistryService()
+   private DeploymentRegistryService getDeploymentRegistryService(BundleContext context)
    {
-      ServiceReference sref = getBundleContext().getServiceReference(DeploymentRegistryService.class.getName());
+      ServiceReference sref = context.getServiceReference(DeploymentRegistryService.class.getName());
       if (sref == null)
          throw new IllegalStateException("Cannot obtain deployment registry service");
       
-      return (DeploymentRegistryService)getBundleContext().getService(sref);
+      return (DeploymentRegistryService)context.getService(sref);
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -676,7 +676,7 @@
     * 
     * @return the system bundle context
     */
-   public BundleContext getBundleContext()
+   public BundleContext getSystemContext()
    {
       return systemBundle.getBundleContext();
    }
@@ -1142,7 +1142,7 @@
       if (systemBundle.getState() != Bundle.STARTING)
          initFramework();
 
-      // Create the system bundl context
+      // Create the system bundle context
       systemBundle.createBundleContext();
 
       // Start registered service plugins

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -85,7 +85,7 @@
    {
       if (packageAdmin == null)
       {
-         BundleContext sysContext = bundleManager.getBundleContext();
+         BundleContext sysContext = bundleManager.getSystemContext();
          ServiceReference sref = sysContext.getServiceReference(PackageAdmin.class.getName());
          if (sref == null)
             throw new IllegalStateException("Cannot obtain PackageAdmin");

Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -0,0 +1,61 @@
+/*
+ * 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.framework.deployers;
+
+//$Id$
+
+import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.InvocationContext;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.Bundle;
+
+/**
+ * The lifecycle interceptor that verifies that deployments ending in '.war'
+ * have a WEB-INF/web.xml descriptor.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 20-Oct-2009
+ */
+public class WebXMLVerifierInterceptor extends AbstractLifecycleInterceptor implements LifecycleInterceptor
+{
+   public void invoke(int state, InvocationContext context) throws LifecycleInterceptorException
+   {
+      if (state == Bundle.STARTING)
+      {
+         try
+         {
+            VirtualFile root = context.getRoot();
+            VirtualFile webXML = root.getChild("/WEB-INF/web.xml");
+            if (root.getName().endsWith(".war") && webXML == null)
+            {
+               throw new LifecycleInterceptorException("Cannot obtain web.xml from: " + root.toURL());
+            }
+         }
+         catch (Exception ex)
+         {
+            throw new LifecycleInterceptorException("Cannot parse web.xml", ex);
+         }
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/internal/AbstractServicePluginImpl.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -42,6 +42,6 @@
 
    public BundleContext getSystemContext()
    {
-      return bundleManager.getBundleContext();
+      return bundleManager.getSystemContext();
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -23,6 +23,9 @@
 
 //$Id$
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.logging.Logger;
 import org.jboss.osgi.deployment.deployer.DeployerService;
@@ -51,20 +54,21 @@
    // Provide logging
    final Logger log = Logger.getLogger(LifecycleInterceptorServiceImpl.class);
 
+   private Set<LifecycleInterceptor> bootstrapInterceptors = new HashSet<LifecycleInterceptor>();
    private AbstractLifecycleInterceptorService delegate;
    private ServiceRegistration registration;
 
-   public LifecycleInterceptorServiceImpl(OSGiBundleManager bundleManager)
+   public LifecycleInterceptorServiceImpl(final OSGiBundleManager bundleManager)
    {
       super(bundleManager);
    }
 
    public void startService()
    {
-      final BundleContext context = getSystemContext();
+      BundleContext context = getSystemContext();
       delegate = new AbstractLifecycleInterceptorService(context)
       {
-         protected Deployment getDeployment(String name, Version version)
+         protected Deployment getDeployment(BundleContext context, String name, Version version)
          {
             OSGiBundleState bundle = (OSGiBundleState)bundleManager.getBundle(name, version);
             if (bundle == null)
@@ -82,6 +86,11 @@
             return dep;
          }
       };
+      
+      // Add bootstrap interceptors
+      for (LifecycleInterceptor aux : bootstrapInterceptors)
+         addInterceptor(aux);
+      
       registration = context.registerService(LifecycleInterceptorService.class.getName(), delegate, null);
    }
 
@@ -97,8 +106,14 @@
 
    public void addInterceptor(LifecycleInterceptor interceptor)
    {
-      if (delegate != null)
+      if (delegate == null)
+      {
+         bootstrapInterceptors.add(interceptor);
+      }
+      else
+      {
          delegate.addInterceptor(interceptor);
+      }
    }
 
    public void removeInterceptor(LifecycleInterceptor interceptor)

Modified: projects/jboss-osgi/trunk/testsuite/example/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/pom.xml	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/pom.xml	2009-10-26 12:01:12 UTC (rev 95563)
@@ -241,6 +241,7 @@
                 
                 <!-- https://issues.apache.org/jira/browse/FELIX-1804 -->
                 <exclude>org/jboss/test/osgi/example/interceptor/**</exclude>
+                <exclude>org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.class</exclude>
                 <exclude>org/jboss/test/osgi/example/webapp/WebAppInterceptorTestCase.class</exclude>
               </excludes>
             </configuration>

Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2009-10-26 12:01:12 UTC (rev 95563)
@@ -76,6 +76,15 @@
         <include name="message.txt"/>
       </fileset>
     </war> 
+    <jar destfile="${tests.output.dir}/test-libs/example-webapp-negative.war"
+      manifest="${tests.resources.dir}/webapp/MANIFEST.MF">
+      <zipfileset dir="${tests.classes.dir}" prefix="WEB-INF/classes">
+        <include name="**/example/webapp/bundle/*.class"/>
+      </zipfileset>
+      <fileset dir="${tests.resources.dir}/webapp">
+        <include name="message.txt"/>
+      </fileset>
+    </jar> 
     
     <!-- xml/jaxb -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-xml-jaxb.jar" files="${tests.resources.dir}/xml/jaxb/example-xml-jaxb.bnd" />

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/ParserInterceptor.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/ParserInterceptor.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/ParserInterceptor.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -51,7 +51,7 @@
       addOutput(HttpMetadata.class);
    }
 
-   public void invoke(int state, InvocationContext context) throws LifecycleInterceptorException
+   public void invoke(int state, InvocationContext context)
    {
       // Do nothing if the metadata is already available  
       HttpMetadata metadata = context.getAttachment(HttpMetadata.class);

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/PublisherInterceptor.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/PublisherInterceptor.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/PublisherInterceptor.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -52,12 +52,12 @@
       addInput(HttpMetadata.class);
    }
 
-   public void invoke(int state, InvocationContext context) throws LifecycleInterceptorException
+   public void invoke(int state, InvocationContext context)
    {
       // HttpMetadata is guaratied to be available because we registered
       // this type as required input
       HttpMetadata metadata = context.getAttachment(HttpMetadata.class);
-      
+
       // Register HttpMetadata on STARTING 
       if (state == Bundle.STARTING)
       {
@@ -72,7 +72,8 @@
             HttpServlet servlet = (HttpServlet)servletClass.newInstance();
 
             // Register the servlet with the HttpService
-            getHttpService(context).registerServlet("/servlet", servlet, null, null);
+            HttpService httpService = getHttpService(context, true);
+            httpService.registerServlet("/servlet", servlet, null, null);
          }
          catch (RuntimeException rte)
          {
@@ -88,15 +89,17 @@
       else if (state == Bundle.STOPPING)
       {
          log.info("Unpublish HttpMetadata: " + metadata);
-         getHttpService(context).unregister("/servlet");
+         HttpService httpService = getHttpService(context, false);
+         if (httpService != null)
+            httpService.unregister("/servlet");
       }
    }
 
-   private HttpService getHttpService(InvocationContext context)
+   private HttpService getHttpService(InvocationContext context, boolean required)
    {
       BundleContext syscontext = context.getSystemContext();
       ServiceReference sref = syscontext.getServiceReference(HttpService.class.getName());
-      if (sref == null)
+      if (sref == null && required == true)
          throw new IllegalStateException("Required HttpService not available");
 
       HttpService httpService = (HttpService)syscontext.getService(sref);

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -0,0 +1,46 @@
+/*
+ * 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.test.osgi.example.webapp;
+
+// $Id$
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import org.jboss.osgi.testing.OSGiTest;
+
+/**
+ * A test that deployes a WAR bundle 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 06-Oct-2009
+ */
+public abstract class AbstractWebAppTestCase extends OSGiTest
+{
+   protected String getHttpResponse(String reqPath) throws Exception
+   {
+      URL url = new URL("http://" + getServerHost() + ":8090/webapp" + reqPath);
+      BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
+      return br.readLine();
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/AbstractWebAppTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppExtenderTestCase.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -25,14 +25,10 @@
 
 import static org.junit.Assert.assertEquals;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
 
 import org.jboss.osgi.spi.capability.HttpServiceCapability;
 import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiTest;
 import org.jboss.osgi.testing.OSGiTestHelper;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -44,7 +40,7 @@
  * @author thomas.diesler at jboss.com
  * @since 06-Oct-2009
  */
-public class WebAppExtenderTestCase extends OSGiTest
+public class WebAppExtenderTestCase extends AbstractWebAppTestCase
 {
    private static OSGiRuntime runtime;
 
@@ -92,30 +88,28 @@
    // Due to the nature of asynchronous event processing by the 
    // extender pattern, we cannot assume that the endpoint is
    // available immediately
-   private String getHttpResponse(String reqPath) throws Exception
+   protected String getHttpResponse(String reqPath) throws Exception
    {
+      int timeout = 25;
       String line = null;
       IOException lastException = null;
-      URL url = new URL("http://" + runtime.getServerHost() + ":8090/example-webapp" + reqPath);
-
-      int timeout = 25;
       while (line == null && 0 < timeout--)
       {
-         Thread.sleep(200);
          try
          {
-            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
-            line = br.readLine();
+            line = super.getHttpResponse(reqPath);
          }
          catch (IOException ex)
          {
             lastException = ex;
          }
+         if (line == null)
+            Thread.sleep(200);
       }
-
+      
       if (line == null && lastException != null)
          throw lastException;
-
+      
       return line;
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppInterceptorTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppInterceptorTestCase.java	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppInterceptorTestCase.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -25,13 +25,8 @@
 
 import static org.junit.Assert.assertEquals;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.net.URL;
-
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiTest;
 import org.jboss.osgi.testing.OSGiTestHelper;
 import org.jboss.osgi.webapp.WebAppCapability;
 import org.junit.AfterClass;
@@ -44,7 +39,7 @@
  * @author thomas.diesler at jboss.com
  * @since 06-Oct-2009
  */
-public class WebAppInterceptorTestCase extends OSGiTest
+public class WebAppInterceptorTestCase extends AbstractWebAppTestCase
 {
    private static OSGiRuntime runtime;
 
@@ -87,11 +82,4 @@
       String line = getHttpResponse("/servlet?test=initProp");
       assertEquals("initProp=SomeValue", line);
    }
-
-   private String getHttpResponse(String reqPath) throws Exception
-   {
-      URL url = new URL("http://" + runtime.getServerHost() + ":8090/example-webapp" + reqPath);
-      BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
-      return br.readLine();
-   }
 }
\ No newline at end of file

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java	2009-10-26 12:01:12 UTC (rev 95563)
@@ -0,0 +1,80 @@
+/*
+ * 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.test.osgi.example.webapp;
+
+// $Id$
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiTestHelper;
+import org.jboss.osgi.webapp.WebAppCapability;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.BundleException;
+
+/**
+ * A test that deployes a WAR bundle that contains no WEB-INF/web.xml
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 26-Oct-2009
+ */
+public class WebAppNegativeTestCase extends AbstractWebAppTestCase
+{
+   private static OSGiRuntime runtime;
+
+   @BeforeClass
+   public static void setUpClass() throws Exception
+   {
+      OSGiTestHelper osgiTestHelper = new OSGiTestHelper();
+
+      runtime = osgiTestHelper.getDefaultRuntime();
+      runtime.addCapability(new WebAppCapability());
+   }
+
+   @AfterClass
+   public static void tearDownClass() throws Exception
+   {
+      runtime.shutdown();
+      runtime = null;
+   }
+
+   @Test
+   public void testServletAccess() throws Exception
+   {
+      OSGiBundle bundle = runtime.installBundle("example-webapp-negative.war");
+      try
+      {
+         bundle.start();
+         fail("BundleException expected");
+      }
+      catch (BundleException ex)
+      {
+         Throwable cause = ex.getCause();
+         assertTrue(cause instanceof LifecycleInterceptorException);
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml	2009-10-26 12:01:12 UTC (rev 95563)
@@ -105,11 +105,23 @@
   </bean>
   <bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+    <incallback method="addInterceptor" />
+    <uncallback method="removeInterceptor" />
   </bean>
   
   <!--
   ********************************
   *                              *  
+  *  OSGi Interceptors           *
+  *                              *
+  ********************************
+  -->
+  
+  <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.deployers.WebXMLVerifierInterceptor"/>
+  
+  <!--
+  ********************************
+  *                              *  
   *  OSGi Deployment             *
   *                              *
   ********************************

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF	2009-10-26 12:00:08 UTC (rev 95562)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/webapp/MANIFEST.MF	2009-10-26 12:01:12 UTC (rev 95563)
@@ -4,4 +4,4 @@
 Bundle-SymbolicName: example-webapp
 Bundle-ClassPath: .,WEB-INF/classes
 Import-Package: javax.servlet,javax.servlet.http,org.osgi.service.http,org.ops4j.pax.web.service
-
+Webapp-Context: webapp




More information about the jboss-cvs-commits mailing list