Hi Justin,
But should it not be enough that the OSGi Activator programmatically
registers the service in the Service Registry with registerService() ?
I am using a code like the following...
package com.me.helloservice;
import java.util.Dictionary;
import java.util.Hashtable;
import com.me.helloservice.impl.HelloServiceImpl;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
public class Activator implements BundleActivator {
private ServiceRegistration registration;
public void start(BundleContext context) throws Exception {
HelloService greeter = new HelloServiceImpl();
final Dictionary<String, Object> props = new Hashtable<String,
Object>();
props.put(Constants.SERVICE_DESCRIPTION, "Greatest Service on
Earth");
props.put(Constants.SERVICE_VENDOR, "Me");
registration =
context.registerService(HelloService.class.getName(), greeter, props);
System.err.println("HelloService Started");
}
public void stop(BundleContext context) throws Exception {
System.err.println("HelloService Stopped");
registration.unregister();
}
}
On Wed, Apr 27, 2016 at 1:35 PM, Justin Edelson <[email protected]>
wrote:
> Hi,
> The line
>
> var service = sling.getService(Packages.com.me.helloservice.HelloService);
>
> Is trying to get an OSGi service from the Service Registry named
> com.me.helloservice.HelloService. Is such a service actually registered?
> Generally (although not exclusively), those services are registered using
> Declarative Services and your bundle doesn't have any DS components.
>
> Regards,
> Justin
>
>
>
> On Wed, Apr 27, 2016 at 7:16 AM Ivan Gimenez <[email protected]>
> wrote:
>
> > Hi
> >
> > I am evaluating Apache Sling for a project. I am running Sling8 via
> > launchpad, downloaded org.apache.sling.launchpad-8.jar from Apache Site.
> >
> > I am trying to learn the basics before developing anything, so I created
> an
> > OSGi bundle I try to invoke from an ESP script (GET.esp) using
> >
> > <html>
> > <head>
> > <title><%= currentNode["jcr:title"] %></title>
> > </head>
> > <body>
> >
> >
> > <%
> > var service =
> > sling.getService(Packages.com.me.helloservice.HelloService);
> > var msg = "null service";
> > if(service)
> > msg = service.sayHello();
> > %>
> > <p><%= msg %></p>
> >
> > </body>
> > </html>
> >
> >
> > The page shows "null service" isntead of "Hello World!". (simplest OSGi
> > bundle BTW)
> >
> > but ESP script is unable to resolve the OSGi bundle, althouth it has been
> > properly loaded as shown in the Apache Felix system console.
> >
> > 123
> >
> > HelloServicePluginHelloServicePlugin
> > Symbolic NameHelloServicePluginVersion0.0.1.SNAPSHOTBundle
> > Locationinputstream:HelloServicePlugin-0.0.1-SNAPSHOT.jarLast
> > ModificationTue Apr 26 17:40:50 CEST 2016DescriptionHello Service
> > PluginStart Level20Exported
> > Packagescom.me.helloservice,version=0.0.1Imported
> > Packagesorg.osgi.framework,version=1.8.0 from org.apache.felix.framework
> > (0)
> > <http://localhost:8080/system/console/bundles/0>Manifest
> > HeadersArchiver-Version: Plexus Archiver
> > Bnd-LastModified: 1461685217794
> > Build-Jdk: 1.8.0_77
> > Built-By: igimenez
> > Bundle-Description: Hello Service Plugin
> > Bundle-ManifestVersion: 2
> > Bundle-Name: HelloServicePlugin
> > Bundle-SymbolicName: HelloServicePlugin
> > Bundle-Version: 0.0.1.SNAPSHOT
> > Created-By: Apache Maven Bundle Plugin
> > Export-Package: com.me.helloservice; uses:="org.osgi.framework";
> > version="0.0.1"
> > Import-Package: org.osgi.framework; version="[1.5, 2)"
> > Manifest-Version: 1.0
> > Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=1.8))"
> > Tool: Bnd-3.0.0.201509101326
> > do I need to add any annotation on the OSGI plugin to allow to be invoked
> > from Sling ?
> >
>