softlayer-java icon indicating copy to clipboard operation
softlayer-java copied to clipboard

ID is required to invoke public resource.Metadata$Service.getId()

Open acamacho82 opened this issue 7 years ago • 1 comments

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

acamacho82 avatar May 25 '18 16:05 acamacho82

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.

cretz avatar Jun 21 '18 21:06 cretz