Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The service implementation and consumer bundle are built using DS.
@@@@ image Image Added
The Adder Service interface is as follows:

...

In the OSGI-INF/component.xml file the AdderServiceImpl is instantiated and registered with the OSGi service registry with the distribution properties. These properties instruct. Distributed OSGi into making the service available on http://localhost:9090/adderImage Removed.

Code Block
xml
xml
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="DS Service Sample">
  <implementation class="org.apache.cxf.dosgi.samples.ds.impl.AdderServiceImpl"/>
  
  <property name="osgiservice.remoteexported.interfaces" value=">*<" /property>>
  <property name="osgiservice.remoteexported.configuration.typeconfigs" value="pojoorg.apache.cxf.ws" />
  <property name="osgiorg.remoteapache.configurationcxf.pojows.address" value="http://localhost:9090/adder" />
  
  <service>
    <provide interface="org.apache.cxf.dosgi.samples.ds.AdderService"/>
  </service>
</scr:component>

...

So let's install the server side in Equinox, together with the Equinox DS implementation. You can do this from the Equinox command line, but in this document I'll launch Equinox from within Eclipse (last tried with Eclipse 3.6).
I'm starting off by importing the Single Bundle Distribution as a binary project in Eclipse by going File -> Import | Plug-ins and Fragments and then select the directory that contains the single bundle distribution JAR file. My workspace now looks like this:
@@@ image Image Added
Next I'll create an OSGi Framework launch configuration that includes DS. To do this

  1. deselect the 'Target Platform' tickbox in the Eclipse Launch configuration screen
  2. select org.eclipse.equinox.ds
  3. hit the 'Add Required Bundles' button

@@@ imageImage Added

Now run the OSGi container, you will get a setup like this:

Code Block
osgi> ss

Framework is launched.

id	State       Bundle
0	ACTIVE      org.eclipse.osgi_3.5.0.v20090520
1	ACTIVE      org.eclipse.equinox.util_1.0.100.v20090520-1800
2	ACTIVE      org.eclipse.osgi.services_3.2.0.v20090520-1800
3	ACTIVE      cxf-dosgi-ri-singlebundle-distribution_1.1.0.SNAPSHOT
4	ACTIVE      org.eclipse.equinox.ds_1.1.0.v20090520-1800

Now I can install the DOSGi DS bundles in the OSGi container directly from the maven repository.

Code Block
osgi> install httpshttp://repositoryrepo1.apachemaven.org/content/groups/snapshotsmaven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-ds-interface/1.1-SNAPSHOT2/cxf-dosgi-ri-samples-ds-interface-1.1-SNAPSHOT2.jar 
Bundle id is 5

osgi> install httpshttp://repositoryrepo1.apachemaven.org/content/groups/snapshotsmaven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-ds-impl/1.1-SNAPSHOT2/cxf-dosgi-ri-samples-ds-impl-1.1-SNAPSHOT2.jar
Bundle id is 6

osgi> start 6
... log messages may appear ...
Tip

You can also import the maven projects of the DS demo into Eclipse, this would save you from installing it with a URL as above. To do this, check out the CXF/DOSGi source from SVN (http://svn.apache.org/repos/asf/cxf/dosgi/trunkImage Removed), run mvn eclipse:eclipse and import all Eclipse projects under the samples/ds directory in Eclipse with File -> Import | Existing Projects into Workspace.

At this point, the service should be available remotely, you can check this by obtaining the WSDL:
@@@ image Image Added

The Adder Service Consumer

...

Code Block
java
java
public class AdderConsumer {
    private AdderService adder;
    
    public void bindAdder(AdderService a) {
        adder = a;
    }
    
    public void unbindAdder(AdderService a) {
        adder = null;
    }
    
    public void start(ComponentContext cc) {
        System.out.println("Using adder service: 1 + 1 = " + adder.add(1, 1));
    }
}

...

As in the Greeter demo, the client side needs to be configured to knoe know where teh the remote service actually is. This is one in the OSGI-INF/remote-service/remote-services.xml file:

Code Block
xml
xml
<service<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/sdrsa/v1.0.0">
  <service<endpoint-description>
    <provide<property interfacename="orgobjectClass">
      <array>
        <value>org.apache.cxf.dosgi.samples.ds.AdderService" />
 AdderService</value>
      </array>
   <property name="osgi.remote.interfaces">*</property>
    <property name="osgi.remote.configuration.type">pojo<endpoint.id">http://localhost:9090/adder</property>
    <property name="osgi.remote.configuration.pojo.address">http://localhost:9090/adder<service.imported.configs">org.apache.cxf.ws</property>
  </serviceendpoint-description>
</serviceendpoint-descriptions>

Install and run the consumer side of the demo in a separate Equinox instance (tip: you can duplicate the launch configuration used for the server side in the 'Run Configurations' dialog):

Code Block
osgi> install httpshttp://repositoryrepo1.apachemaven.org/content/groups/snapshotsmaven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-ds-interface/1.1-SNAPSHOT2/cxf-dosgi-ri-samples-ds-interface-1.1-SNAPSHOT2.jar 
Bundle id is 5

osgi> install httpshttp://repositoryrepo1.apachemaven.org/content/groups/snapshotsmaven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-ds-client/1.1-SNAPSHOT2/cxf-dosgi-ri-samples-ds-client-1.1-SNAPSHOT2.jar
Bundle id is 6

osgi> start 6
... log messages may appear, after a little while the following message appears:
Using adder service: 1 + 1 = 2

...

Code Block
Adder service invoked: 1 + 1 = 2

Consumer Note

Some OSGi Declarative Services implementations don't explicitly register interest in the requested services with the OSGi Framework. They rather user a generic Service Tracker or Service Listener to track all available services. This doesn't provide the CXF-DOSGi implementation with the information about what services the consumer is looking for through the ListenerHook and hence it can't register the remote service on-the-fly. A simple workaround to this problem is to add an Activator to a bundle in the client-side framework (this activator could be in any bundle) which registers an explicit ServiceTracker for the remote service the DS component wants to be injected with. An example of such an Activator can be found here.

In the future a more elegant solution to this problem will hopefully be provided.