Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: add the interface type if given when creating the proxy #198

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ protected <T extends DBusInterface> T dynamicProxy(String _source, String _path,
ifcs.add(DBusInterface.class);
}

RemoteObject ro = new RemoteObject(_source, _path, null, false);
RemoteObject ro = new RemoteObject(_source, _path, _type, false);
DBusInterface newi = (DBusInterface) Proxy.newProxyInstance(ifcs.get(0).getClassLoader(),
ifcs.toArray(Class[]::new), new RemoteInvocationHandler(this, ro));
getImportedObjects().put(newi, ro);
Expand Down
13 changes: 13 additions & 0 deletions dbus-java-tests/src/test/java/org/freedesktop/DBus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.freedesktop;

import org.freedesktop.dbus.interfaces.DBusInterface;

public interface DBus extends DBusInterface {
public interface Peer extends DBusInterface {

public String GetMachineId();

public void Ping();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// The package must be "both" org.freedesktop.dbus.connections.impl and org.freedesktop.dbus in order
// for the test to be able to access the requisite methods and fields... obviously this is an issue...
package org.freedesktop.dbus;

import java.lang.reflect.Proxy;

import org.freedesktop.DBus;
import org.freedesktop.dbus.bin.EmbeddedDBusDaemon;
import org.freedesktop.dbus.connections.BusAddress;
import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
import org.freedesktop.dbus.connections.transports.TransportBuilder;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.freedesktop.dbus.test.AbstractBaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class InterfaceCreationTest extends AbstractBaseTest {

@Test
public void testCorrectInterfaceCreation() throws Exception {
String protocolType = TransportBuilder.getRegisteredBusTypes().get(0);
BusAddress busAddress = TransportBuilder.createWithDynamicSession(protocolType).configure().build()
.getBusAddress();

BusAddress listenBusAddress = BusAddress.of(busAddress).getListenerAddress();

try (EmbeddedDBusDaemon daemon = new EmbeddedDBusDaemon(listenBusAddress)) {
daemon.startInBackground();
this.logger.debug("Started embedded bus on address {}", listenBusAddress);

waitForDaemon(daemon);

// connect to started daemon process
this.logger.info("Connecting to embedded DBus {}", busAddress);

final String source = "org.freedesktop.DBus";
final String path = "/org/freedesktop/DBus";

try (DBusConnection connection = DBusConnectionBuilder.forAddress(busAddress).build()) {
DBusInterface dbi = null;
RemoteInvocationHandler rih = null;
RemoteObject ro = null;
Class<? extends DBusInterface> type = DBus.Peer.class;

dbi = connection.getExportedObject(source, path, null);
Assertions.assertNotNull(dbi);

rih = RemoteInvocationHandler.class.cast(Proxy.getInvocationHandler(dbi));
Assertions.assertNotNull(rih);

ro = rih.remote;

Assertions.assertNull(ro.getInterface());

dbi = connection.getExportedObject(source, path, type);
Assertions.assertNotNull(dbi);
Assertions.assertTrue(type.isInstance(dbi));

rih = RemoteInvocationHandler.class.cast(Proxy.getInvocationHandler(dbi));
Assertions.assertNotNull(rih);

ro = rih.remote;

Assertions.assertNotNull(ro.getInterface());
Assertions.assertSame(type, ro.getInterface());
}
}
}

}