You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Ivan Gimenez <iv...@gmail.com> on 2016/04/27 13:16:38 UTC
Unable to resolve bundle from esp
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 ?
Re: Unable to resolve bundle from esp
Posted by Justin Edelson <ju...@justinedelson.com>.
Glad to help, but really you should try using Declarative Services for
anything real.
Regards,
Justin
On Wed, Apr 27, 2016 at 10:52 AM Ivan Gimenez <iv...@gmail.com>
wrote:
> Hi Justin
>
> At first I was confused as I included the Bundle-Activator in the
> MANIFEST.MF file included
>
> *Bundle-Activator: com.me.helloservice.Activator*
>
> but also realized in the pom.xml the reference to the maven bundling
> plugin
> org.apache.felix:maven-bundle-plugin
>
> .. my bad :-(
>
> this plugin auto-generates the metadata from bundle, so got rid of my
> static MANIFEST.MF configuration.
>
> Now I can see the great Hello World message ...
>
> Thanks for your help
>
Re: Unable to resolve bundle from esp
Posted by Ivan Gimenez <iv...@gmail.com>.
Hi Justin
At first I was confused as I included the Bundle-Activator in the
MANIFEST.MF file included
*Bundle-Activator: com.me.helloservice.Activator*
but also realized in the pom.xml the reference to the maven bundling plugin
org.apache.felix:maven-bundle-plugin
.. my bad :-(
this plugin auto-generates the metadata from bundle, so got rid of my
static MANIFEST.MF configuration.
Now I can see the great Hello World message ...
Thanks for your help
Re: Unable to resolve bundle from esp
Posted by Justin Edelson <ju...@justinedelson.com>.
Hi,
It would be enough (although using DS would be better/more idiomatic), but
in that case you need a Bundle-Activator header which you are missing.
Regards,
Justin
On Wed, Apr 27, 2016 at 8:38 AM Ivan Gimenez <iv...@gmail.com> wrote:
> 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 <ju...@justinedelson.com>
> 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 <iv...@gmail.com>
> > 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 ?
> > >
> >
>
Re: Unable to resolve bundle from esp
Posted by Ivan Gimenez <iv...@gmail.com>.
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 <ju...@justinedelson.com>
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 <iv...@gmail.com>
> 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 ?
> >
>
Re: Unable to resolve bundle from esp
Posted by Justin Edelson <ju...@justinedelson.com>.
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 <iv...@gmail.com> 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 ?
>