Java Reference
In-Depth Information
CONFIGURING THE DISTRIBUTION PROVIDER FOR DISCOVERY
The Remote Services specification doesn't explicitly define how discovery is imple-
mented, only how it should behave. The Apache CXF Distributed OSG i implementa-
tion provides discovery based on the Apache Hadoop Zookeeper project ( http://
hadoop.apache.org/zookeeper/ ) , but its usage is beyond the scope of this topic.
Luckily, Apache CXF Distributed OSG i also provides a static version of discovery based
on the Remote Services Admin Endpoint description from the R4.2 Enterprise specifi-
cation. With this approach, the discovery process is directed by XML files contained in
bundles installed in the framework. The following listing shows the XML that
describes the StockProvider service, which is nearly identical to the configuration for
publishing the service.
Listing 15.12 XML discovery file for the StockProvider service for Apache CXF
<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
<service-description>
<provide interface="org.foo.stockprovider.StockProvider" />
<property name="service.exported.interfaces">*</property>
<property name="service.exported.configs">
org.apache.cxf.ws
</property>
<property name="org.apache.cxf.ws.address">
http://localhost:9090/stockprovider
</property>
</service-description>
</service-descriptions>
For this example, package this file in OSGI-INF /remote-service/remote-services.xml of
a new bundle called stockprovider-client-1.0.jar. You define the interface that the dis-
covered service will provide B . Then you provide the configuration entries needed by
the distribution provider to bind to the remote service into the OSG i service registry C .
In this example, this new bundle is purely for configuring the discovery process, so it
only contains this XML file.
That's all there is to it. The service is automatically published into the OSG i service
registry; you can look it up and invoke methods on it, which results in remote method
invocations being sent using SOAP to the server proxy created in the remote JVM .
You now know how to provide and consume remote services. Let's wrap up this
example by seeing how to use this service in the stock-watcher application.
Defines
provided
service
interface B
Specifies configuration
information C
USING YOUR WEB SERVICE
It's time to see the updated stock-watcher application in action. Go into the
chapter15/webservice/ directory of the topic's companion code. Type ant to build
the example and java -Dorg.osgi.service.http.port=8081 -jar launcher.jar
bundles/ to execute it. Doing so starts the remote StockProvider service.
Now you need to start the stock-watcher application. In a separate command shell,
go into the chapter15/webservice-client/ directory of the companion code. Type ant
to build the application and java -jar launcher.jar bundles/ to start it. Browse to
Search WWH ::




Custom Search