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 Metadata service returns IllegalStateException error when calling to the methods getId(), getHostname(), etc.
Following code can be used to reproduce the issue.
The problem is because the Metadata java class has set instanceRequired = true in all methods.
Workaround
I created my own Metadata java class and I set instanceRequired = false