Blueprint Container

The BlueprintTestCase shows how a number of components can be wired together and registered as OSGi service through the Blueprint Container Service.

The example uses this simple blueprint descriptor

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" ...>
  
  <bean id="beanA" class="org.jboss.test.osgi.example.blueprint.bundle.BeanA">
    <property name="mbeanServer" ref="mbeanService"/>
  </bean>
  
  <service id="serviceA" ref="beanA" interface="org.jboss.test.osgi.example.blueprint.bundle.ServiceA">
  </service>
  
  <service id="serviceB" interface="org.jboss.test.osgi.example.blueprint.bundle.ServiceB">
    <bean class="org.jboss.test.osgi.example.blueprint.bundle.BeanB">
       <property name="beanA" ref="beanA"/>
    </bean>
  </service>
  
  <reference id="mbeanService" interface="javax.management.MBeanServer"/>

</blueprint>

The Blueprint Container registers two services ServiceA and ServiceB . ServiceA is backed up by BeanA , ServiceB is backed up by the anonymous BeanB . BeanA is injected into BeanB and the MBeanServer gets injected into BeanA. Both beans are plain POJOs. There is no BundleActivator neccessary to register the services.

The example test verifies the correct wiring like this

@Test
public void testServiceA() throws Exception
{
  ServiceReference sref = context.getServiceReference(ServiceA.class.getName());
  assertNotNull("ServiceA not null", sref);
  
  ServiceA service = (ServiceA)context.getService(sref);
  MBeanServer mbeanServer = service.getMbeanServer();
  assertNotNull("MBeanServer not null", mbeanServer);
}
@Test
public void testServiceB() throws Exception
{
  ServiceReference sref = context.getServiceReference(ServiceB.class.getName());
  assertNotNull("ServiceB not null", sref);
  
  ServiceB service = (ServiceB)context.getService(sref);
  BeanA beanA = service.getBeanA();
  assertNotNull("BeanA not null", beanA);
}

Blueprint support in AS7

This test uses the OSGi Repository functionality to provision the runtime with the required support functionality like this

ManagementSupport.provideMBeanServer(context, bundle);
   BlueprintSupport.provideBlueprint(context, bundle);

To enable blueprint support in AS7 you would configure these capabilities

<capability name="org.apache.aries:org.apache.aries.util:0.4"/>
<capability name="org.apache.aries.proxy:org.apache.aries.proxy:0.4"/>
<capability name="org.apache.aries.blueprint:org.apache.aries.blueprint:0.4"/>