Hi there,<br><br>I use dbus-java to communicate via DBus. This works
fine as long as I stick to primitve types natively supported by the
java dbus lib such as String, int, boolean and so on. However I try to
send objects instances (of a class called Metadata) via DBus, which
have
a String member and a ArrayList<String> member. So I implemented
the serialize and deserialize methods according to the API and the
tutorial which ships with the lib. When trying to call a remote method
which
should deliver a Metadata object, I receive the following exception:<br><br>Exception in thread "main" org.freedesktop.dbus.exceptions<div id="mb_0">.DBusExecutionException: Wrong return type (not expecting Tuple)<br>
at org.freedesktop.dbus.RemoteInvocationHandler.convertRV(RemoteInvocationHandler.java:65)<br>
at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:138)<br> at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:187)<br> at $Proxy1.pongMD(Unknown Source)<br>
at de.ichaus.entw.DBusTest.dBusClient.DBusClient.main(DBusClient.java:65)<br><br>I put together a small testcase existing of a server and a client in case anyone want to run it.<br><br>I thought it might be a problem with that List member in Metadata.
Won't work with Vector<String>, ArrayList<String> or
Collection<String> either. <br>I tried both versions <span></span>Version 2.4 and 1.13 of the library.<br><br>It would be great if anyone could suggest something I am missing out on or got wrong. :)<br><br>Greetings Johannes Felten<br>
<br>CLASSES:<br><br>//------------------------------------------------------------------------------------------------------------------<br>package de.ichaus.entw.DBusTest.dBusServer;<br><br>import java.io.IOException;<br>
<br>import org.freedesktop.dbus.DBusConnection;<br>import org.freedesktop.dbus.exceptions.DBusException;<br><br>public class DBusServer{<br><br> private static DBusConnection conn = null;<br> private static Pong pongObj = null;<br>
<br> private static void connect(){<br> try {<br> conn = DBusConnection.getConnection(DBusConnection.SESSION);<br> conn.requestBusName("de.ichaus.entw.DBusServerPingPong");<br> conn.exportObject("/pongObj",pongObj);<br>
} catch (DBusException e) {<br> e.printStackTrace();<br> }<br> }<br><br> /**<br> * @param args<br> */<br> public static void main(String[] args) {<br> pongObj = new Pong();<br>
<br> connect();<br> System.out.print("Press ENTER to exit.");<br> try {<br> System.in.read();<br> } catch (IOException e) {<br> // TODO Auto-generated catch block<br>
e.printStackTrace();<br> }<br> finally{<br> conn.disconnect();<br> }<br><br> }<br><br>}<br><br>//------------------------------------------------------------------------------------------------------------------<br>
<br>package de.ichaus.entw.DBusTest.dBusServer;<br><br>import java.util.ArrayList;<br><br>import org.freedesktop.dbus.DBusInterface;<br>import org.freedesktop.dbus.Tuple;<br><br>import de.ichaus.entw.DBusTest.types.Metadata;<br>
<br>public class Pong implements DBusConnectorInterface {<br><br> private Metadata pongMD;<br><br> public Pong(){};<br><br> public String pong() {<br> return "pong";<br> }<br><br> public void makeMD(String mdStr){<br>
ArrayList<String> strLst = new ArrayList<String>(3);<br> for (int i=0; i<3; i++)<br> strLst.add(mdStr+"_"+i);<br> pongMD = new Metadata(mdStr, strLst);<br> }<br>
<br> public Metadata pongMD(){<br> return pongMD;<br> }<br><br> public boolean isRemote() {<br> return false;<br> }<br><br>}<br><br>
<br>
//------------------------------------------------------------------------------------------------------------------<br><br>package de.ichaus.entw.DBusTest.dBusClient;<br><br>import java.util.Calendar;<br><br>import org.freedesktop.dbus.DBusConnection;<br>
import org.freedesktop.dbus.exceptions.DBusException;<br><br>import de.ichaus.entw.DBusTest.dBusServer.DBusConnectorInterface;<br>import de.ichaus.entw.DBusTest.dBusServer.Pong;<br><br>public class DBusClient {<br><br> private static DBusConnection conn = null;<br>
private static DBusConnectorInterface pongObj = null;<br><br> private static void connect(){<br> try {<br> conn = DBusConnection.getConnection(DBusConnection.SESSION);<br> //pongObj = (DBusConnectorInterface)conn.getRemoteObject("de.ichaus.entw.DBusServerPingPong", "/pongObj");<br>
//pongObj = (DBusConnectorInterface)conn.getRemoteObject("de.ichaus.entw.DBusServerPingPong", "/pongObj", de.ichaus.entw.DBusTest.dBusServer.DBusConnectorInterface.class);<br> pongObj = (DBusConnectorInterface)conn.getRemoteObject("de.ichaus.entw.DBusServerPingPong", "/pongObj", DBusConnectorInterface.class);<br>
} catch (DBusException e) {<br> // TODO Auto-generated catch block<br> e.printStackTrace();<br> }<br> }<br><br> private static String getTimeStamp(){<br> Calendar rightNow = Calendar.getInstance();<br>
return rightNow.get(Calendar.YEAR) + "-"<br> + (rightNow.get(Calendar.MONTH) + 1) + "-"<br> + rightNow.get(Calendar.DAY_OF_MONTH) + " "<br> + rightNow.get(Calendar.HOUR_OF_DAY) + ":"<br>
+ rightNow.get(Calendar.MINUTE) + ":"<br> + rightNow.get(Calendar.SECOND) + "."<br> + rightNow.get(Calendar.MILLISECOND);<br> }<br><br> /**<br> * @param args<br>
*/<br> public static void main(String[] args) {<br> System.out.println("Starttime: " + getTimeStamp());<br> connect();<br> System.out.println("Connected: " + getTimeStamp());<br>
<br> System.out.println("\n Play some ping pong...");<br> for (int i = 0; i < 10; i++) {<br> System.out.println("I said ping...");<br> if (pongObj != null)<br> System.out.println("Server said " + pongObj.pong());<br>
else<br> System.out.println("Server said nothing...");<br> }<br><br> System.out.println("Endtime: " + getTimeStamp());<br> System.out.println(" Finished ping pong play.");<br>
<br> System.out.println("\nPlay some Metadata ping pong...");<br> for (int i = 0; i < 10; i++) {<br> System.out.println("I said makeMD...");<br> if (pongObj != null)<br>
{<br> pongObj.makeMD("pong_"+i);<br> System.out.println("Server said " + pongObj.pongMD());<br> }<br> else<br> System.out.println("Server said nothing...");<br>
}<br> System.out.println(" Finished Metadata ping pong.");<br><br> if (conn != null)<br> conn.disconnect();<br><br> System.out.println("Disconnected: " + getTimeStamp());<br>
}<br>}<br><br>//------------------------------------------------------------------------------------------------------------------<br>
package de.ichaus.entw.DBusTest.dBusServer;<br><br>import org.freedesktop.dbus.DBusInterface;<br><br>import de.ichaus.entw.DBusTest.types.Metadata;<br><br>public interface DBusConnectorInterface extends DBusInterface {<br>
<br> public String pong();<br> public void makeMD(String mdStr);<br> public Metadata pongMD();<br><br>}<br><br>//------------------------------------------------------------------------------------------------------------------<br>
<br>package de.ichaus.entw.DBusTest.types;<br><br>import java.util.ArrayList;<br>import java.util.List;<br><br>import org.freedesktop.dbus.DBusSerializable;<br>import org.freedesktop.dbus.Position;<br>import org.freedesktop.dbus.exceptions.DBusException;<br>
<br>public class Metadata implements DBusSerializable{<br><br> @Position(0)<br> private String md5Sum = "";<br> @Position(1)<br> private List<String> someStrings;<br><br> public Metadata(){}<br>
<br> public Metadata(String md5, List<String> strings){<br> md5Sum = md5;<br> someStrings = strings;<br> }<br><br> public Object[] serialize() throws DBusException {<br> return new Object[] {this.md5Sum, this.someStrings};<br>
}<br><br> public void deserialize(String md5sum, List<String> someStrings){<br> this.md5Sum = md5sum;<br> this.someStrings = new ArrayList<String>(someStrings);<br> }<br><br>}<br><br>//------------------------------------------------------------------------------------------------------------------</div>