Versions Compared

Key

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

...

The Server Side

The Greeter Service implementation bundle provides a trivial implementation of the GreeterService interface. Additionally, it has an Activator:

...

  • The osgi.remote.interfaces property is set to '*', which means that all the interfaces passes to registerService are good for remotingshould be made accessible remotely. In this case it's just the GreeterService interface.
  • The osgi.remote.configuration.type is set to pojo, which is a CXF specific configuration type that can be used to set the URL at which the service is to be exposed. This is done via the osgi.remote.configuration.pojo.address property.

Let's run the server in Felix 1.4.1. As a prerequisite it requires some of the OSGi Compendium Specification interfaces. These don't come with the Felix download but are built as part of the Felix build. When building a CXF DOSGi distribution, the Felix bundle with these interfaces is pulled in via Maven and put in the target/deps directory.
To set up my Felix environment, I'm running the following commands:

Code Block
C:\felix-1.4.1>java -jar bin\felix.jar

Welcome to Felix.
=================

-> ps
START LEVEL 1
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (1.4.1)
[   1] [Active     ] [    1] Apache Felix Shell Service (1.0.2)
[   2] [Active     ] [    1] Apache Felix Shell TUI (1.0.2)
[   3] [Active     ] [    1] Apache Felix Bundle Repository (1.2.1)
-> start file:/<dosgi-root>/distribution/single-bundle/target/deps/org.osgi.compendium-1.2.0.jar
-> start file:/<dosgi-root>/distribution/single-bundle/target/cxf-dosgi-ri-singlebundle-distribution-1.0-SNAPSHOT.jar

Some log meesages messages may come up now.
Note that instead of manually adding these bundles to the Felix container, you can also append the target/felix.config.properties.append file to the <felix-root>/conf/config.properties file. This will automatically load these two bundles when Felix starts up.

...

Some more log messages come up. When it says INFO: Remote org.apache.cxf.dosgi.samples.greeter.GreeterService endpoint has been published into Discovery service you know that the service is exposed remotely, and you can verify this by requesting the WSDL:

This WSDL was dynamically generated from the exposed GreeterService Java interface. Under the hood, the Aegis data binding is used for this.

The Service Consumer side.

...

Code Block
<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
  <service-description>
    <provide interface="org.apache.cxf.dosgi.samples.greeter.GreeterService" />
    <property name="osgi.remote.interfaces">*</property>
    <property name="osgi.remote.configuration.type">pojo</property>
    <property name="osgi.remote.configuration.pojo.address">http://localhost:9090/greeter</property>
  </service-description>
</service-descriptions>

TheLet's run the consumer in Equinox, so that we have a bundle the bundles running in Equinox talking to a remoted service running in Felix!
As with Felix, we will have to load the bundle with the OSGi compendium interfaces. There's one that ships with Equinox.

...

Code Block
osgi> install file:/<dosgi-root>/samples/greeter/interface/target/cxf-dosgi-ri-samples-greeter-interface-1.0-SNAPSHOT.jar
Bundle id is 3
osgi> install file:/<dosgi-root>/samples/greeter/client/target/cxf-dosgi-ri-samples-greeter-client-1.0-SNAPSHOT.jar
Bundle id is 4
osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      org.eclipse.osgi_3.5.0.v20081201-1815
1       ACTIVE      org.eclipse.osgi.services_3.2.0.v20081205-1800
2       ACTIVE      cxf-dosgi-ri-singlebundle-distribution_1.0.0.SNAPSHOT
3       INSTALLED   cxf-dosgi-ri-samples-greeter-interface_1.0.0.SNAPSHOT
4       INSTALLED   cxf-dosgi-ri-samples-greeter-client_1.0.0.SNAPSHOT

osgi> start 4

After a few moments the following window appears:

This means that The window appears once the ServiceTracker in the consumer has received a callback that the GreeterService has been found. The value entered will used to invoke the (remote) OSGi service, with a call like this:

Code Block
Map<GreetingPhrase, String> result = greetergreeterService.greetMe("foobar");

I can see that the invocation has been received by the service implementation as in the Felix window the following appears.

...