Hi all,
I'm new to both OSGi and sip-communicator.
I want to embed sipcommunicator in my own application for making a video call [0], using services provided by bundles, but i have not succeed in running OSGi + sip-communicator.[1], and I capture a ClassCastException when using a Service from a bundle
My development environment is WindowsXP with Java1.5, Eclipse and the same Felix distribution included in sip-communicator.
I've succesfully compiled the latest sip-communicator version from SVN and generated all the sc-bundles (via ant)
I've copied the lib/*; sc-bundles/* (copying windows media.jar too) to my project, and configured the launch as manuals says [2]
-Djava.library.path=lib/native/windows
-Dfelix.config.properties=file:lib/felix.client.run.properties
-Djava.util.logging.config.file=lib/logging.properties
I've added to my classpath the same jars that are needed for compiling sip-communicator, as seen in the distribution file "ide/eclipse/.classpath"
I've used in my app the same felix.client.run.properties that is present in the sip-communicator distribution
For trying all goes ok, I have chosen to use the Systray Service and show one message.
First, I've imported to my project the source code of service interfaces defined in
net.java.sip.communicator.service.systray;
net.java.sip.communicator.service.systray.event;
but when I want to get the service from the context I've a ClassCastException
java.lang.ClassCastException: net.java.sip.communicator.impl.systray.jdic.SystrayServiceJdicImpl
I start felix with a BundleActivator (MyActivator)
···
---------------------------
import net.java.sip.communicator.service.systray.SystrayService; //sources in my project
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.cache.BundleCache;
import org.apache.felix.framework.util.StringMap;
import org.apache.felix.main.Main;
import org.cogknow.phone.felix.CogknowActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
class HostApp{
private Felix m_felix = null;
private MyActivator m_activator = null;
public void initialize() throws Exception {
Main.loadSystemProperties();
Properties configProps = Main.loadConfigProperties();
Main.copySystemProperties(configProps);
try {
List list = new ArrayList();
this.m_activator = new MyActivator();
list.add(this.m_activator);
Map configMap = new StringMap(configProps, false);
m_felix = new Felix(configMap, list);
m_felix.start();
} catch (Exception e) {
System.out.println("Could not start framework");
e.printStackTrace();
System.exit(-1);
}
public void sendMessage(){
this.m_activator.getSystrayService().showPopupMessage("Title", "Content", SystrayService.INFORMATION_MESSAGE_TYPE);
}
}
--------------------------
public class MyActivator implements BundleActivator {
private Logger logger = Logger.getLogger(MyActivator.class.getName());
private BundleContext context = null;
private SystrayService systrayService = null;
public void start(BundleContext context) throws Exception {
logger.info(MyActivator.class.getName() + " [STARTED]");
this.context = context;
}
public void stop(BundleContext arg0) throws Exception {
context = null;
}
public BundleContext getContext() {
return context;
}
public SystrayService getSystrayService(){
if (this.systrayService == null){
ServiceReference serviceReference = context
.getServiceReference(SystrayService.class.getName()); //this goes ok!
this.systrayService = (SystrayService) context
.getService(serviceReference); //EXCEPTION!!!!!!
}
return systrayService;
}
}
--------------------------
The logs in console starts and register all the bundles OK (as the execution of sip-communicator does)
It also prints MyActivator [STARTED] Message as well
but when I call myHostApp.sendMessage() i get the exception commented above:
java.lang.ClassCastException: net.java.sip.communicator.impl.systray.jdic.SystrayServiceJdicImpl
thrown in
MyActivator::getSystrayService() -> this.systrayService = (SystrayService) context.getService(serviceReference);
Is a problem with ClassLoaders? How can I solve it?
Is Java5 compatibility issue?
Please, could you tell me what I'm doing wrong.
Many thanks in advance, and I please receive my apologies for the length of the question
[0]https://sip-communicator.dev.java.net/servlets/ReadMsg?list=dev&msgNo=1974
[1]http://felix.apache.org/site/launching-and-embedding-apache-felix.html
[2]http://www.sip-communicator.org/index.php/Documentation/ConfigureEclipseNew
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net