The NepomukMiddleware is the way to make sure your service is visible to other NepomukServices. When a service is registered with the middleware it will do three things:
- Make this service accessible through the OSGIServiceTracker
- Attempt to make this services accessible through SOAP, this requires a valid WSDL file, see below. It will fail silently, so if you are not interested in SOAP (and you shouldn't be) just leave the WSDL out)
- Make this service accessible through XMLRPC
For accessing services through the middleware, see NepomukServices
Programming against the OSGI Nepomuk Middleware
Creating the service
- Create a java interface for your service (can be automatic, or the two steps can be reversed)
- Implement your service as a java class
- Use only simple types (String,Integer,Double), Arrays of these, Collections of these, or simple JavaBeans? (See also MiddlewareTypes)
- Add a NepomukType? annotation to your interface (Note that the WSDL pointed to in NepomukType? does not need to exist, it can be generated later if needed):
@NepomukType(type="http://www.dfki.uni-kl.de/~grimnes/2006/11/nepomuk/ExampleService.wsdl")
- OPTIONAL: Add a WebService? annotation to your interface (this is only needed if you want to general WSDL for your service or you want it SOAPified.):
@WebService(targetNamespace="http://exampleservice.examples.nepomuk.semanticdesktop.org", name="ExampleService")
- If you want a WSDL file - make sure you read CorrectWSDLs to learn about where to put your wsdl file for Nepomuk to cache it for offline work.
Registering
- Do NOT register your service directly with OSGI, instead use the Nepomuk registery:
ServiceReference sr = context.getServiceReference(OSGIRegistry.class.getName());
if (sr==null) {
log.fatal("Could not find Nepomuk Registry - aborting.");
throw new Exception("No Nepomuk registry found");
}
registry=(OSGIRegistry) context.getService(sr);
service = new ExampleServiceImpl();
registry.registerService(ExampleService.class, service, "ExampleService");
- This will register your service as:
- A soap service, accessible under http://localhost:8181/soap/servicename
- A OSGI Service, accessible as normal (but dont do this directly! See below)
- With the Nepomuk Middleware Registry
Invoking Services
- To discover Nepomuk service of a certain types, use the NepomukServices interface:
ServiceReference sr = bc.getServiceReference(NepomukServices.class.getName()); if (sr==null) { log.warn("Could not find NepomukServices - aborting."); throw new Exception("No NepomukServices found"); } NepomukServices registry = (NepomukServices) bc.getService(sr); ExampleService service = registry.getService(ExampleService.class);
Note, this only works when the ExampleService? has a NepomukType? annotation. The NepomukServices interface also has getRdfRepository and a few other utility method for commonly used services.
Debugging
If you have trouble you can go to http://localhost:8181/middleware/index This lists all services registered with the middleware and has links to their XMLRPC/SOAP endpoints as well as a link for generating WSDL for services that has WebService? annotations.
If you are attempting to do SOAP (which I do not recommend), the middleware will be default fail quietly. For verbose SOAP debugging set the property org.semanticdesktop.nepomuk.soap.debug to true in config.ini
Any questions/comments, let Gunnar know!
