Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call OSGi service from sightly javascript use function

Tags:

rhino

aem

sightly

I am trying to access an OSGi service from a sightly javascript use function. Through the sling SlingScriptHelper. I can call the sling.getService(Service.class) method from javascript, but I do not know how to specify the class in javascript.

It looks like it should be possible to reference java classes using the fully qualified name or using rhino's importPackage(..).

However, I get the following exception:

org.apache.sling.scripting.sightly.SightlyException:
org.mozilla.javascript.EvaluatorException: Can't find method
org.apache.sling.scripting.core.impl.InternalScriptHelper.getService(object).
like image 988
diffa Avatar asked Sep 16 '25 23:09

diffa


1 Answers

To do this, prepend Packages to the fully-qualified class name, e.g.

var myService = sling.getService(Packages.com.myco.MyService);

(where com.myco.MyService is the service interface)

See https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/content/src/main/content/jcr_root/apps/acs-commons/sightly/templates/dhlm.js#L23 for an example.

like image 190
Justin Edelson Avatar answered Sep 19 '25 15:09

Justin Edelson