Fwd: Problem in calling a method of one java application from another java application using DBus.

Shiv Nath Kumar shivnath27 at gmail.com
Thu Mar 4 01:06:13 PST 2010


Hi all,

I am  newbie in DBus programming using java. I am trying to call a method
"myfun" on an object class "Demo" in a simple java program (TestDBus.java)
from another java program (TestDBus1.java) using DBus Connection. I am able
to connecct both these applications to DBus but my code is not able to call
method "myfun" and I got some exception. My code and run time exception are
as below :
<-------------------------------------------- *Demo.java *
----------------------------------------------------------------->

package pack;
import org.freedesktop.DBus;
import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.DBusInterface;

interface TestDBusInt extends DBusInterface{
public void myfun();
}

public class Demo implements TestDBusInt{
    public Demo(){}
    public boolean isRemote(){return false;}
    public void myfun(){
        System.out.println("Within myfun of Demo class within
TestDBus.class");
    }
}


 <-----------------------------------------
*TestDBus.java*---------------------------------------------------------->

import org.freedesktop.DBus;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.*;
import pack.Demo;

public class TestDBus{

        public static void main(String[] args) throws
org.freedesktop.dbus.exceptions.DBusException {
                DBusConnection bus = null;

               // Getting the Bus Connection.

        System.out.println("Connecting Bus........");

                bus = DBusConnection.getConnection(DBusConnection.SESSION);

                System.out.println("Bus Connection Established.");

        //Getting Unique name of this connection.
        String conName=bus.getUniqueName();
        System.out.println("Unique Name of this Bus Connection =>
"+conName);


        //Requesting Bus Name.
        bus.requestBusName("My.FirstBus");


        //Getting the names owned by this connection.
        System.out.println("Names owned by this Bus Connection are =>");
        String []bnames1=bus.getNames();
        for(int i=0;i<bnames1.length;i++)
            System.out.println(bnames1[i]);


        //exporting the Demo class object on the path “/Test”

      *  DBusInterface db1=new Demo();
        bus.exportObject("/Test", db1);*

        while(true){}

        }
}

 <-----------------------------------------
*TestDBus1.java*---------------------------------------------------------->

import org.freedesktop.DBus;
import org.freedesktop.dbus.*;
import java.lang.reflect.*;
import org.freedesktop.DBus.Introspectable;
import org.freedesktop.*;
import pack.Demo;


public class TestDBus1 {

        public static void main(String[] args) throws
org.freedesktop.dbus.exceptions.DBusException {
        DBusConnection bus1 = null;
        DBusConnection bus2=null;

                System.out.println("Establishing Bus Connection.......");

                bus1 = DBusConnection.getConnection(DBusConnection.SESSION);

                 System.out.println("Bus Connection Established.");

        //Getting Unique name of this connection.
        String conName1=bus1.getUniqueName();
        System.out.println("Unique Name of this Bus Connection =>
"+conName1);


        // Getting and Displaying Introspection data on Remote Object.
       * Introspectable intro = (Introspectable) bus1.getRemoteObject(
                              "My.FirstBus", "/Test",
                               Introspectable.class);

        String data = intro.Introspect();*




        //System.out.println(db.myfun());


        System.out.println("<--------------------------- Introspection Data
Start ----------------------------------->");
        System.out.println(data);
        System.out.println("<--------------------------- Introspection Data
End   ----------------------------------->");


        //Getting the remote object and calling a method of that object.
  *DBusInterface db =bus1.getPeerRemoteObject("**My.FirstBus","/Test");
        DBusAsyncReply<Boolean> stuffreply =bus1.callMethodAsync(db,"**
myfun");*


         while(true){}

        }
}

<--------------------------------------------------*End Of
Code*-------------------------------------------------------------------------------------->




<--------------------------------------------*Console Output on running
TestDBus.java *--------------------------------------->

Connecting Bus........
Bus Connection Established.
Unique Name of this Bus Connection => :1.37
Names owned by this Bus Connection are =>
:1.37
My.FirstBus
^Cshivnath at cmk-kbcs-shivnath:~/jdk1.6.0_07/bin/dbusex2$ java TestDBus
Connecting Bus........
Bus Connection Established.
Unique Name of this Bus Connection => :1.39
Names owned by this Bus Connection are =>
:1.39
My.FirstBus



<------------------------------------- *Console Output on running
TestDBus1.java* --------------------------------------->

Establishing Bus Connection.......
Bus Connection Established.
Unique Name of this Bus Connection => :1.40
<--------------------------- Introspection Data Start
----------------------------------->
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection
1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/Test">
 <interface name="pack.TestDBusInt">
  <method name="myfun" >
  </method>
 </interface>
 <interface name="org.freedesktop.DBus.Introspectable">
  <method name="Introspect">
   <arg type="s" direction="out"/>
  </method>
 </interface>
 <interface name="org.freedesktop.DBus.Peer">
  <method name="Ping">
  </method>
 </interface>
</node>
<--------------------------- Introspection Data End
----------------------------------->
Exception in thread "main"
org.freedesktop.dbus.exceptions.DBusExecutionException: $Proxy2.myfun()
        at
org.freedesktop.dbus.AbstractConnection.callMethodAsync(AbstractConnection.java:683)
        at TestDBus1.main(TestDBus1.java:48)
<------------------------------------------------------*End of Console
Output*-------------------------------------------------------------->

I am not sure, if I am missing something obvious here and would  appreciate
any advice on this. Plz, help me if I am going wrong in some way. Plz
suggest me what to do to fix such exception and call the method as I want.
Waiting for your reply.

Thanks in Advance !!

-- 
Regards,
Shiv Nath Kumar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20100304/2a59f569/attachment-0001.htm>


More information about the dbus mailing list