softlayer-java
softlayer-java copied to clipboard
ID is required to invoke public resource.Metadata$Service.getId()
The Metadata service returns IllegalStateException error when calling to the methods getId(), getHostname(), etc.
java.lang.IllegalStateException: ID is required to invoke public abstract java.lang.Long com.softlayer.api.service.resource.Metadata$Service.getId()
Following code can be used to reproduce the issue.
public class TestMetadata {
public static void main(String arg[]){
String privateEndPoint = "https://api.service.softlayer.com/rest/v3/";
ApiClient client = new RestApiClient(privateEndPoint);
Metadata.Service metadataService = Metadata.service(client);
try {
long id = metadataService.getId();
System.out.println("This VSI ID is " + id);
} catch (Exception e) {
System.out.println("SoftlayerMetadata error in " + e);
}
}
}
The problem is because the Metadata java class has set instanceRequired = true in all methods.
@ApiMethod(instanceRequired = true)
public Long getId();
Workaround I created my own Metadata java class and I set instanceRequired = false
The better fix is probably to update the metadata generator that dumps https://api.softlayer.com/metadata/v3.1 (careful, big JSON) to set static to true on methods for SoftLayer_Resource_Metadata.