[jboss-osgi-commits] JBoss-OSGI SVN: r95508 - in projects/jboss-osgi/trunk: testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Fri Oct 23 10:18:14 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-23 10:18:13 -0400 (Fri, 23 Oct 2009)
New Revision: 95508

Added:
   projects/jboss-osgi/trunk/distribution/docbook/src/main/graphics/jbossosgi-interceptor.odp
Modified:
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/HttpMetadata.java
   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
Log:
Unregister endpoint on STOPPING

Added: projects/jboss-osgi/trunk/distribution/docbook/src/main/graphics/jbossosgi-interceptor.odp
===================================================================
(Binary files differ)


Property changes on: projects/jboss-osgi/trunk/distribution/docbook/src/main/graphics/jbossosgi-interceptor.odp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/HttpMetadata.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/HttpMetadata.java	2009-10-23 14:14:15 UTC (rev 95507)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/HttpMetadata.java	2009-10-23 14:18:13 UTC (rev 95508)
@@ -43,4 +43,10 @@
    {
       return servletName;
    }
+
+   @Override
+   public String toString()
+   {
+      return "HttpMetadata [servletName=" + servletName + "]";
+   }
 }

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-23 14:14:15 UTC (rev 95507)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/ParserInterceptor.java	2009-10-23 14:18:13 UTC (rev 95508)
@@ -45,6 +45,12 @@
    // Provide logging
    private Logger log = LoggerFactory.getLogger(ParserInterceptor.class);
    
+   ParserInterceptor()
+   {
+      // Add the provided output
+      addOutput(HttpMetadata.class);
+   }
+   
    public void invoke(int state, Deployment dep) throws LifecycleInterceptorException
    {
       // Do nothing if the metadata is already available  
@@ -61,9 +67,7 @@
             if (propsFile != null)
             {
                log.info("Create and attach HttpMetadata");
-               Properties props = new Properties();
-               props.load(propsFile.openStream());
-               metadata = new HttpMetadata(props.getProperty("servlet.name"));
+               metadata = createHttpMetadata(propsFile);
                dep.addAttachment(HttpMetadata.class, metadata);
             }
          }
@@ -73,4 +77,13 @@
          }
       }
    }
+
+   private HttpMetadata createHttpMetadata(VirtualFile propsFile) throws IOException
+   {
+      Properties props = new Properties();
+      props.load(propsFile.openStream());
+      
+      HttpMetadata metadata = new HttpMetadata(props.getProperty("servlet.name"));
+      return metadata;
+   }
 }

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-23 14:14:15 UTC (rev 95507)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/interceptor/processor/PublisherInterceptor.java	2009-10-23 14:18:13 UTC (rev 95508)
@@ -45,7 +45,7 @@
 {
    // Provide logging
    private Logger log = LoggerFactory.getLogger(PublisherInterceptor.class);
-   
+
    PublisherInterceptor()
    {
       // Add the required input
@@ -54,18 +54,22 @@
 
    public void invoke(int state, Deployment dep) throws LifecycleInterceptorException
    {
+      // HttpMetadata is guaratied to be available because we registered
+      // this type as required input
+      HttpMetadata metadata = dep.getAttachment(HttpMetadata.class);
+      
+      // Register HttpMetadata on STARTING 
       if (state == Bundle.STARTING)
       {
-         HttpMetadata metadata = dep.getAttachment(HttpMetadata.class);
          String servletName = metadata.getServletName();
          try
          {
-            log.info("Publish HttpMetadata");
-            
+            log.info("Publish HttpMetadata: " + metadata);
+
             // Load the endpoint servlet from the attached bundle (is always attached)
             Bundle bundle = dep.getAttachment(Bundle.class);
             HttpServlet servlet = (HttpServlet)bundle.loadClass(servletName).newInstance();
-            
+
             // Register the servlet with the HttpService
             getHttpService(dep).registerServlet("/servlet", servlet, null, null);
          }
@@ -78,17 +82,24 @@
             throw new LifecycleInterceptorException("Cannot publish: " + servletName, ex);
          }
       }
+
+      // Unregister the endpoint on STOPPING 
+      else if (state == Bundle.STOPPING)
+      {
+         log.info("Unpublish HttpMetadata: " + metadata);
+         getHttpService(dep).unregister("/servlet");
+      }
    }
 
    private HttpService getHttpService(Deployment dep)
    {
       // Get the system bundle context (is always attached)
       BundleContext context = dep.getAttachment(BundleContext.class);
-      
+
       ServiceReference sref = context.getServiceReference(HttpService.class.getName());
       if (sref == null)
          throw new IllegalStateException("Required HttpService not available");
-      
+
       HttpService httpService = (HttpService)context.getService(sref);
       return httpService;
    }



More information about the jboss-osgi-commits mailing list