I created an OGI bundle , named :
com.sdl.ws.integration.profserv.webservice.connector.server.external.beans
I can see the bundle under :
http://localhost:4502/system/console/bundles
Following is my JSP code , using which I am trying to access a bundlecontext
<%@ page import="org.osgi.framework.BundleContext"%>
<%@ page import="org.osgi.framework.FrameworkUtil"%>
<%@ page import="com.sample.osgi.components.FormattingServiceImpl.*"%>
<%@ page import="org.osgi.service.cm.ConfigurationAdmin"%>
<%@ page import="org.osgi.service.cm.Configuration"%>
<%@ page import="org.osgi.service.packageadmin.PackageAdmin"%>
<%
BundleContext bundleContext = FrameworkUtil.getBundle(FormattingServiceImpl).getBundleContext();
%>
I am getting the following error : FormattingServiceImpl cannot be resolved
I tried to use multiple ways to import the jar but nothing is working ,
Here is a structure how my bundle is configured :
I am stuck on the point how to access the bundle context from JSP , does any one has any suggestions / corrections ?
You're probably just missing the .class to refer to your FormattingServiceImpl class - the following works for me on a bare Apache Sling instance, using Sling's Resource interface instead of FormattingServiceImpl but with the same pattern:
<%@ page import="org.osgi.framework.BundleContext"%>
<%@ page import="org.osgi.framework.FrameworkUtil"%>
<%@ page import="org.apache.sling.api.resource.Resource"%>
<%
BundleContext bc = FrameworkUtil.getBundle(Resource.class).getBundleContext();
%>
<%= bc %>
That being said, there's IMO few valid use cases for getting a BundleContext in a JSP script, I would question the need for that in the first place.
Also, your code seems to indicate that FormattingServiceImpl is an implementation class and is exported by the bundle that defines it, that's usually also a bad idea. In general, bundles should only export packages containing the interfaces of the services that they provide.