CXF Distributed OSGi
  1. CXF Distributed OSGi
  2. DOSGI-115

Use Spring DM and Eclipse Gemini Blueprint with DOSGi

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.4.0
    • Component/s: DSW
    • Labels:
    • Environment:

      Developped in Windows OS

    • Estimated Complexity:
      Unknown

      Description

      Today cxf-dosgi-ri-dsw-cxf supports only Spring DM. This goal of this issue is to modify cxf-dosgi-ri-dsw-cxf to support both Spring DM and Eclipse Gemini Blueprint.
      The idea is :

      • 1) cxf-dosgi-ri-dsw-cxf :remove Spring DM dependencies (don't use directly org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext and org.springframework.osgi.context.BundleContextAware) in this project but use a commons interface :

      ------------------------------------------------------------------------
      package org.apache.cxf.dosgi.dsw.container;

      import java.util.List;

      import org.osgi.framework.BundleContext;
      import org.springframework.context.ApplicationContext;

      /**

      • OSGi Spring container API.
      • @author Angelo Zerr <angelo.zerr@gmail.com>
      • */
        public interface OsgiSpringContainer {

      /**

      • Publish the given springs files and returns the Spring
      • {@link ApplicationContext}

        .

      • @param springIntentLocations
      • @param bundleContext
      • @return
        */
        ApplicationContext publish(List<String> springIntentLocations,
        BundleContext bundleContext);

      /**

      • Returns the {@link BundleContext}

        from the given Spring application

      • context.
      • @param context
      • @return
        */
        BundleContext getBundleContext(ApplicationContext context);
        }
        ------------------------------------------------------------------------

      1.1) In the class OsgiUtils:

      do like this:

      ------------------------------------------------------------------------
      ApplicationContext ctx = OsgiSpringContainerProvider.getContainer().publish(springIntentLocations, bundleContext);
      ------------------------------------------------------------------------

      Instead of doing that:

      ------------------------------------------------------------------------
      //
      //
      // OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(springIntentLocations
      // .toArray(new String[] {}));
      // ctx.setPublishContextAsService(false);
      // ctx.setBundleContext(bundleContext);
      // ctx.refresh();
      ------------------------------------------------------------------------

      1.2) In the Activator class:

      Implements ApplicationContextAware (instead of BundleContextAware) :
      public class Activator implements ManagedService, ApplicationContextAware/,BundleContextAware/ {

      and implements setApplicationContext liek this

      ------------------------------------------------------------------------
      public void setApplicationContext(ApplicationContext context)
      throws BeansException

      { bc = OsgiUtils.getBundleContext(context); }

      ------------------------------------------------------------------------

      where OsgiUtils.getBundleContext use the interface

      ------------------------------------------------------------------------
      public static BundleContext getBundleContext(ApplicationContext context)

      { return OsgiSpringContainerProvider.getContainer().getBundleContext(context); }

      :
      ------------------------------------------------------------------------

      1.1) OsgiSpringContainerProvider:

      The OsgiSpringContainerProvider use SPI ServiceRegistry to retrieves the implemententation of OsgiSpringContainer :

      ------------------------------------------------------------------------
      package org.apache.cxf.dosgi.dsw.container;

      import java.util.Iterator;

      import javax.imageio.spi.ServiceRegistry;

      public class OsgiSpringContainerProvider {

      private static OsgiSpringContainer container;

      public static OsgiSpringContainer getContainer()
      throws OsgiSpringContainerNotFoundException {
      if (container == null)

      { container = getContainerFromFragment(); }

      return container;
      }

      public static synchronized OsgiSpringContainer getContainerFromFragment()
      throws OsgiSpringContainerNotFoundException {

      if (container != null)

      { return container; }

      Iterator<OsgiSpringContainer> containers = ServiceRegistry
      .lookupProviders(OsgiSpringContainer.class,
      OsgiSpringContainerProvider.class.getClassLoader());
      while (containers.hasNext())

      { return containers.next(); }

      throw new OsgiSpringContainerNotFoundException();
      }
      }
      ------------------------------------------------------------------------

      2) cxf-dosgi-ri-dsw-cxf-gemini : new project which is a fragment linked to cxf-dosgi-ri-dsw-cxf and register with SPI ServiceRegistry the Gemini BluePring implementation of OSgiSpringContainer :

      ------------------------------------------------------------------------
      package org.apache.cxf.dosgi.dsw.container.geminiblueprint;

      import java.util.List;

      import org.apache.cxf.dosgi.dsw.container.OsgiSpringContainer;
      import org.eclipse.gemini.blueprint.context.support.OsgiBundleXmlApplicationContext;
      import org.osgi.framework.BundleContext;
      import org.springframework.context.ApplicationContext;

      public class GeminiBlueprintContainer
      implements OsgiSpringContainer {

      public ApplicationContext publish(List<String> springIntentLocations,
      BundleContext bundleContext) {
      OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(
      springIntentLocations.toArray(new String[] {}));
      ctx.setPublishContextAsService(false);
      ctx.setBundleContext(bundleContext);
      ctx.refresh();
      return ctx;
      }

      public BundleContext getBundleContext(ApplicationContext context)

      { return ((OsgiBundleXmlApplicationContext)context).getBundleContext(); }
      }
      ------------------------------------------------------------------------

      This implementation is registered in the file META-INF/services/org.apache.cxf.dosgi.dsw.container.OsgiSpringContainer :

      ------------------------------------------------------------------------
      org.apache.cxf.dosgi.dsw.container.geminiblueprint.GeminiBlueprintContainer
      ------------------------------------------------------------------------

      This fragment has Eclipse Gemini Blueprint dependencies.

      3) cxf-dosgi-ri-dsw-cxf-springdm: new project which is a fragment linked to cxf-dosgi-ri-dsw-cxf and register with SPI ServiceRegistry the SppringDM implementation of OSgiSpringContainer :

      ------------------------------------------------------------------------
      package org.apache.cxf.dosgi.dsw.container.springdm;

      import java.util.List;

      import org.apache.cxf.dosgi.dsw.container.OsgiSpringContainer;
      import org.osgi.framework.BundleContext;
      import org.springframework.context.ApplicationContext;
      import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;

      public class SpringDMContainer implements
      OsgiSpringContainer {


      public ApplicationContext publish(List<String> springIntentLocations,
      BundleContext bundleContext) {
      OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(
      springIntentLocations.toArray(new String[] {}));
      ctx.setPublishContextAsService(false);
      ctx.setBundleContext(bundleContext);
      ctx.refresh();
      return ctx;
      }

      public BundleContext getBundleContext(ApplicationContext context) { return ((OsgiBundleXmlApplicationContext)context).getBundleContext(); }

      }
      ------------------------------------------------------------------------

      This implementation is registered in the file META-INF/services/org.apache.cxf.dosgi.dsw.container.OsgiSpringContainer :

      ------------------------------------------------------------------------
      org.apache.cxf.dosgi.dsw.container.springdm.SpringDMContainer
      ------------------------------------------------------------------------

      This fragment has Spring DM dependencies.

      4) Use cxf-dosgi-ri-dsw-cxf with Eclipse Gemini Blueprint

      So to use cxf-dosgi-ri-dsw-cxf with Eclipse Gemini Blueprint, add in the OSGi container cxf-dosgi-ri-dsw-cxf+cxf-dosgi-ri-dsw-cxf-gemini

      5) Use cxf-dosgi-ri-dsw-cxf with Spring DM

      So to use cxf-dosgi-ri-dsw-cxf with Spring DM, add in the OSGi container cxf-dosgi-ri-dsw-cxf+cxf-dosgi-ri-dsw-cxf-springdm

      I don't know Gemini Aires, but if it is based on Spring, we could create a new fragment cxf-dosgi-ri-dsw-cxf-aires.

      Hope you will like it this idea.

        Issue Links

          Activity

          Hide
          Angelo added a comment -

          This zip contains 3 Eclipse Projects:

          1) cxf-dosgi-ri-dsw-cxf : bundle which has no dependencies to Spring DM.
          2) cxf-dosgi-ri-dsw-cxf-gemini :fragment for Eclipse Gemini Blueprint using.
          3) cxf-dosgi-ri-dsw-cxf-springdm :fragment for Spring DM using.

          If you like this idea, I will create clean patch with pom.xml etc

          Show
          Angelo added a comment - This zip contains 3 Eclipse Projects: 1) cxf-dosgi-ri-dsw-cxf : bundle which has no dependencies to Spring DM. 2) cxf-dosgi-ri-dsw-cxf-gemini :fragment for Eclipse Gemini Blueprint using. 3) cxf-dosgi-ri-dsw-cxf-springdm :fragment for Spring DM using. If you like this idea, I will create clean patch with pom.xml etc
          Hide
          Sergey Beryozkin added a comment -

          Hi Angelo, I think we'd need to come up with the interface build around the Blueprint concepts, example,

          "import org.springframework.context.ApplicationContext;" won't work with Aries.

          May be we should introduce two interfaces:
          1. org.apache.cxf.dosgi.dsw.container.BlueprintContext
          2. org.apache.cxf.dosgi.dsw.container.BlueprintContainer,
          instead of org.apache.cxf.dosgi.dsw.container.OsgiSpringContainer

          BlueprintContainer would need to return BlueprintContext, and BlueprintContext implementation will delegate to SpringDM, Gemini or Aries application context manager

          What do you think ?

          Show
          Sergey Beryozkin added a comment - Hi Angelo, I think we'd need to come up with the interface build around the Blueprint concepts, example, "import org.springframework.context.ApplicationContext;" won't work with Aries. May be we should introduce two interfaces: 1. org.apache.cxf.dosgi.dsw.container.BlueprintContext 2. org.apache.cxf.dosgi.dsw.container.BlueprintContainer, instead of org.apache.cxf.dosgi.dsw.container.OsgiSpringContainer BlueprintContainer would need to return BlueprintContext, and BlueprintContext implementation will delegate to SpringDM, Gemini or Aries application context manager What do you think ?
          Hide
          Angelo added a comment -

          Hi Sergey,

          It's a good idea, but I think we should try to implement Aries in same time to check if it's OK.

          Regards Angelo

          Show
          Angelo added a comment - Hi Sergey, It's a good idea, but I think we should try to implement Aries in same time to check if it's OK. Regards Angelo
          Hide
          Sergey Beryozkin added a comment -

          Yes indeed.
          I wonder how the following can be rewritten with Aries:

          public BlueprintContext publish(List<String> springIntentLocations,
          BundleContext bundleContext) {
          OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(
          springIntentLocations.toArray(new String[] {}));
          ctx.setPublishContextAsService(false);
          ctx.setBundleContext(bundleContext);
          ctx.refresh();
          return new AriesBlueprintContext(ctx);
          }
          

          where BlueprintContext and AriesBlueprintContext are DOSGi-specific.

          Show
          Sergey Beryozkin added a comment - Yes indeed. I wonder how the following can be rewritten with Aries: public BlueprintContext publish(List< String > springIntentLocations, BundleContext bundleContext) { OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext( springIntentLocations.toArray( new String [] {})); ctx.setPublishContextAsService( false ); ctx.setBundleContext(bundleContext); ctx.refresh(); return new AriesBlueprintContext(ctx); } where BlueprintContext and AriesBlueprintContext are DOSGi-specific.
          Hide
          Christian Schneider added a comment -

          Do we really need to load a context? I see two better options.

          1) We could switch to blueprint and simply add the intentmap to the context that starts the dsw bundle.
          2) We could create the intentmap completely in code. It is a bit more work but would make us completely independent of blueprint and spring dm

          So I think if we can assume blueprint is always present like e.g. in Karaf 1 is better. If we can not assume this then 2 might be better.

          Show
          Christian Schneider added a comment - Do we really need to load a context? I see two better options. 1) We could switch to blueprint and simply add the intentmap to the context that starts the dsw bundle. 2) We could create the intentmap completely in code. It is a bit more work but would make us completely independent of blueprint and spring dm So I think if we can assume blueprint is always present like e.g. in Karaf 1 is better. If we can not assume this then 2 might be better.
          Hide
          Christian Schneider added a comment -

          Issue 86 seems similar to this one.

          Show
          Christian Schneider added a comment - Issue 86 seems similar to this one.
          Hide
          Christian Schneider added a comment -

          I will switch the loading of intents to a OSGi service aproach in DOSGI-86. As soon as this is done intent loading will also work with Gemini.

          Show
          Christian Schneider added a comment - I will switch the loading of intents to a OSGi service aproach in DOSGI-86 . As soon as this is done intent loading will also work with Gemini.

            People

            • Assignee:
              Christian Schneider
              Reporter:
              Angelo
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development