Hello,
I am having trouble with the OSGI tutorials, with the host application
using a bundle service (Tutorial 2 - dictionary service). I have read
previous posts on classloader issues between host app and bundles and also
read (apache-felix-framework-launching-and-embedding.html) page as well.
My problem is that despite trying to 'inject' the service interface class
from the host into the bundle, as detailed in Felix pages above, the bundle
is still using its own service interface, causing the ClassCastException. I
have shown this to be the case as if use:
Class<?> bundleInstance =
felix.getBundleContext().getBundle(1).loadClass("felix.bundle.dictionary.DictionaryService");
Object dictionary =
bundleInstance.cast(felix.getBundleContext().getService(ref))
then it works. I find this very 'clunky' and would much rather do:
DictionaryService dictionary = (DictionaryService)
felix.getBundleContext().getService(ref);
I have attached my host application and would appreciate any feeback as to
how to solve the classloader issue (I have seen the HostActivator code, and
tried it, but fail to see how that would solve my problem).
Serge
/***********************************************/
public static void main(String[] argv) throws Exception
{
System.out.println("\nWelcome to Felix.");
try
{
Properties config = new Properties();
config.setProperty(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY,
"install,start");
config.setProperty(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY,
"/Users/serge/dev/osgi/Felix/bundle");
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"felix.bundle.dictionary.DictionaryService");
felix = getFrameworkFactory().newFramework(config);
felix.init();
AutoProcessor.process(config, felix.getBundleContext());
felix.start();
ServiceReference ref =
felix.getBundleContext().getServiceReference(DictionaryService.class.getName());
Class<?> hostClassInstance = DictionaryService.class; // hosts
version
Class<?> bundleClassInstance =
felix.getBundleContext().getBundle(1).loadClass("felix.bundle.dictionary.DictionaryService");
//bundle version
// -------- !!!!
// THIS LINE FAILS BECAUSE hostClassInstance != bundleClassInstance
DictionaryService svc = (DictionaryService)
felix.getBundleContext().getService(ref);
// ---------- !!!!
boolean found = svc.checkWord("hello");
System.out.println("word hello exists - " + found);
felix.waitForStop(4000);
felix.getBundleContext().ungetService(ref); //reference counting
for bundle unloading
System.exit(0);
}
catch (Exception ex)
{
.......
}
}
--
View this message in context:
http://old.nabble.com/service-interface-classes-not-being-exported-into-bundle---ClassCaseException-tp27302355p27302355.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]