[sip-comm-dev] ClassCastException embedding sip-communicator in an App


#1

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


#2

Hi all,

replying to myself...

This error is a OSGi misconfiguration issue.
All goes fine after writing in felix.client.run.properties, in section
org.osgi.framework.system.packages
all the service java packages that I want to use in my app.

By the way, I've found a couple of bugs, in MainMenu and Systray shutdown when felix.embedded.execution=true

Best regards,
Javier

Javier Mendiara Ca�ardo escribi�:

···

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

--
Javi Mendiara Ca�ardo

Skype: jmendiara.tid
MsnIM: javier.mendiara@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#3

Hi peoples,

    Why the Jabber Protocol don't update the presence correctly? The my presence don't update sip of my contact if me is connected. Any help is well arrival. Thank

Mizael Barros

···

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#4

Hello Javier,

As a matter of fact the system.packages property is meant for classes
that you want to use without being part of a bundle. The JRE classes are
one such example.

In the case of as service provided by a bundle, you should make sure
that it is exported by the bundle that contains it, and then import it
in the one that uses it.

Hope this helps
Emil

Javier Mendiara Cañardo написа:

···

Hi all,

replying to myself...

This error is a OSGi misconfiguration issue.
All goes fine after writing in felix.client.run.properties, in section
org.osgi.framework.system.packages
all the service java packages that I want to use in my app.

By the way, I've found a couple of bugs, in MainMenu and Systray
shutdown when felix.embedded.execution=true

Best regards,
Javier

Javier Mendiara Cañardo escribió:

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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#5

Hello Mizael,

I don't quite understand your problem. We haven't had any issues with
jabber presence so far so it might be a problem with your server or
network connection. Could you please describe your configuration and
maybe send out some logs so that we could try to better diagnose your
problem?

Cheers
Emil

Mizael Barros написа:

···

Hi peoples,

    Why the Jabber Protocol don't update the presence correctly? The my
presence don't update sip of my contact if me is connected. Any help is well
arrival. Thank

Mizael Barros

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net