Reputation: 6916
I am just starting on Apache sling and CQ5 development. There is this concept of using OSGI bundles in Sling.
I can't find out how the sling framework actually interacts with these bundles and where does the response from bundles go ?
Upvotes: 7
Views: 2084
Reputation: 2996
OSGi is module framework and service platform used by Sling and the CQ5 product. Sling itself is comprised of a series of bundles hosted within the Felix OSGi container. Bundles are a collection group of components/services and java classes managed by the container. The bundle can specify which packages will be imported, exported and also the versions of those dependencies.
There are a number of ways that you can interact with OSGi from Sling. From a JSP/JSP you can use the sling object (of type SlingScriptHelper), which is most likely available in your JSP page if you have included the following line:
<%@include file="/libs/foundation/global.jsp"%>
in your component or have the following:
<cq:defineObjects>
You can use it like so:
QueryBuilder queryBuilder = sling.getService(QueryBuilder.class);
Additionally, if you have your own OSGi components (e.g. Servlet, Service, etc) you can inject references to other OSGI components/services using SCR annotations. Bertrand describes this in his answer to Getting OSGi services from a bundle in Sling/CQ. Effectively this means adding the @Reference annotation to your OSGI component variables in your components, like so:
@Reference
private SlingRepository repository;
When your component is loaded, then the reference will be injected by the OSGi container.
A bundle doesn't have a response as such. A deployed bundle should be visible in the system console:
http://localhost:4502/system/console/bundles
with its components, services & configuration declared here:
http://localhost:4502/system/console/services
http://localhost:4502/system/console/components
http://localhost:4502/system/console/configMgr
(Replace localhost:4502 with your own CQ server host:port)
Once you have obtained a reference to a component, then you can call the methods on that and use the return values from those calls.
Upvotes: 8