Java DBus : Exception in calling remote object method
Shiv Nath Kumar
shivnath27 at gmail.com
Sun Mar 7 21:04:25 PST 2010
I want to call a remote object method using DBus. I developed some code for
that taking some help from the source code of
org/freedesktop/dbus/test/Test.java and
org/freedesktop/dbus.test/TestRemoteInterface.java.
But I get some exception when i run my program.
My code along with terminal output is as below :
*<DBusInt.java>*
package pack1;
import org.freedesktop.dbus.DBusInterface;
//import org.apertium.Info; // The interface we use to access
org.apertium.info/
public interface DBusInt extends DBusInterface{
public String myfun();
}
* <TestDBus.java>
*
import org.freedesktop.DBus;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.*;
import org.freedesktop.DBus.Peer;
import pack1.DBusInt;
//import org.apertium.Info; // The interface we use to access
org.apertium.info/
class testclass implements DBusInt
{
private DBusConnection conn;
public testclass(DBusConnection conn)
{
this.conn = conn;
}
/** Local classes MUST implement this to return false */
public boolean isRemote() { return false; }
public String myfun()
{
System.out.println("Within myfun");
return "This is a response from myfun !!";
}
}
public class TestDBus{
static DBusConnection serverconn = null;
static DBusConnection clientconn = null;
public static void main(String args[])throws DBusException{
serverconn =
DBusConnection.getConnection(DBusConnection.SESSION);
clientconn =
DBusConnection.getConnection(DBusConnection.SESSION);
System.out.println("Registering Name");
serverconn.requestBusName("foo.bar.Test");
System.out.println("Listening for Method Calls");
testclass tclass = new testclass(serverconn);
/** This exports an instance of the test class as the object
/Test. */
serverconn.exportObject("/Test", tclass);
System.out.println("Calling Method0/1 ");
/** This gets a remote object matching our bus name and
exported object path. */
* DBusInt tri =
(DBusInt)clientconn.getPeerRemoteObject("foo.bar.Test", "/Test");*
System.out.println("Got Remote Object: "+tri);
/** Call the remote object and get a response. */
String rname = tri.myfun();
System.out.println("Got Remote Name: "+rname);
//String str=(DBusInt)clientconn.getPeerRemoteObject("foo.bar.Test",
"/Test").myfun();
}
}
*<TERMINAL OUTPUT>
*Registering Name
Listening for Method Calls
Calling Method0/1
Exception in thread "main" java.lang.ClassCastException: $Proxy2 cannot be
cast to pack1.DBusInt
at TestDBus.main(TestDBus.java:57)
plz help me to fix this exception. I have bold marked the line in
TestDBus.java which is causing exception.
Thanks in advance!!
--
Regards,
Shiv Nath Kumar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20100308/9643f921/attachment.html>
More information about the dbus
mailing list