Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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="service.exported.interfaces" value="*" />
  <property name="service.exported.configs" value="org.apache.cxf.ws" />
  <property name="org.apache.cxf.ws.address" value="http://localhost:9090/adder" />
  
  <service>
    <provide interface="org.apache.cxf.dosgi.samples.ds.AdderService"/>
  </service>
</scr:component>

...

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.

...

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 know where 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="org"objectClass">
      <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
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.