VirtualBox

Opened 11 years ago

Closed 11 years ago

#12029 closed defect (fixed)

Cannot get state of running machines via Java web service

Reported by: rshaw Owned by:
Component: webservices Version: VirtualBox 4.2.16
Keywords: vboxwebsrv machine state Cc:
Guest type: all Host type: all

Description

As stated in the title, the function IVirtualBox#getMachineStates is currently unusable over vboxwebsrv. One can iterate over every single machine and get their state one by one but this creates a large number of network calls instead of requesting them all at once. getMachineStates seems to be broken due to a misnaming of enum values. I ran this code against a VirtualBox instance with a single machine that was powered off. Here is my SSCCE.

import java.util.List;
import org.virtualbox_4_2.IMachine;
import org.virtualbox_4_2.IVirtualBox;
import org.virtualbox_4_2.VirtualBoxManager;

public class Main {
	public static void main(String[] args) {
		String url = "http://localhost:18083";
		VirtualBoxManager manager = VirtualBoxManager.createInstance(url);
		manager.connect(url, null, null);
		IVirtualBox vbox = manager.getVBox();
		List<IMachine> machines = vbox.getMachines();
		vbox.getMachineStates(machines);	
	}
}
Exception in thread "main" java.lang.AssertionError: java.lang.reflect.InvocationTargetException
	at org.virtualbox_4_2.Helper.convertEnums(Helper.java:108)
	at org.virtualbox_4_2.IVirtualBox.getMachineStates(IVirtualBox.java:755)
	at Main.main(Main.java:13)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.virtualbox_4_2.Helper.convertEnums(Helper.java:100)
	... 2 more
Caused by: java.lang.IllegalArgumentException: No enum constant org.virtualbox_4_2.MachineState.POWERED_OFF
	at java.lang.Enum.valueOf(Enum.java:236)
	at org.virtualbox_4_2.MachineState.fromValue(MachineState.java:344)
	... 7 more

Change History (6)

comment:1 by Klaus Espenlaub, 11 years ago

Scratching my head... all the corresponding code is automatically generated, and I have no idea whatsoever why all of a sudden there are such alien enum values such as POWERED_OFF. That's not our API naming style, we don't have such all caps things separated by underscore. Very mysterious.

comment:2 by Klaus Espenlaub, 11 years ago

Reproduced it here, and the webservice definitely delivers the correct results (I have a large number of VMs, most PoweredOff, some Saved and so on), checked what was passed on the wire. Somehow the java client side makes garbage out of this.

comment:3 by Klaus Espenlaub, 11 years ago

Slowly starts making sense, this naming is used internally by the JAX-WS generated code (org.VirtualBox_4_3.jaxws.MachineState). The conversion to the actually used class (org.VirtualBox_4_3.MachineState) explodes because it doesn't understand the JAX-WS generated enum values.

I wonder why this shows up all of a sudden now - the very same issue should happen with all other enum conversions, which hints that somehow the safearray content conversion is special.

comment:4 by Klaus Espenlaub, 11 years ago

Fully understood the problem now, it's a bug in the array conversion for enum types, and it's broken for both the webservice and for the local API, in different ways. It's also clear now why no one noticed so far. There are extremely few places where this is needed. The webservice case is fixed, but now I'm struggling with the remaining NoSuchMethodException in the local API case.

comment:5 by Klaus Espenlaub, 11 years ago

What a mess (and in this case I mean how Java handles enums internally). It made fixing the never working enum array conversion very difficult, but of course the actual bug still was in our client side API wrapper code. First public "release" will most likely be 4.3.0_beta2, but later we'll of course also fix the relevant older versions.

comment:6 by Frank Mehnert, 11 years ago

Resolution: fixed
Status: newclosed

Fix is part of VBox 4.3.0.

Note: See TracTickets for help on using tickets.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette