2016-06-09 24 views
0
  1. 我可以列出所有包並使用packageId縮小包對象的範圍。

ApiClient client = new RestApiClient().withCredentials(username, apikey); Package.Service service = Package.service(client); List<Package> packages = service.getAllObjects(); chosenPackage = pkg;Java客戶端com.softlayer.api.service.product.Package getItemPrices(),getConfiguration()爲空

  • 的chosenPackage,示出了一個有效的地址chosenPackage:[email protected]
  • 現在,我想列出selectedPackage.getItemPrices(),chosenPackage.getConfiguration()等,所有這些值都是空的。
  • 我沒有找到com.softlayer.api.service.product.Package的任何方法setMask()或withMask()方法。如果我可以設置面罩,我可能會工作。
  • 你可以提供一些小代碼,以獲得itemPrices?我正在使用SoftLayer Java客戶端。
  • 回答

    0

    試試這個例子,請:

    package com.softlayer.api.Package; 
    
    import com.google.gson.Gson; 
    import com.softlayer.api.ApiClient; 
    import com.softlayer.api.RestApiClient; 
    import com.softlayer.api.service.product.Package; 
    
    /** 
    * This script retrieves a all packages from SoftLayer_Product_Package::getAllObjects method 
    * and their item prices and configuration 
    * 
    * Important Manual Page: 
    * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getAllObjects 
    * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package 
    * 
    * @license <http://sldn.softlayer.com/article/License> 
    * @authon SoftLayer Technologies, Inc. <[email protected]> 
    * @version 0.2.2 
    */ 
    public class GetPackages { 
        /** 
        * This is the constructor, is used to get all packages and their item prices 
        */ 
        public GetPackages() { 
         // Declare your SoftLayer username and apiKey 
         String username = "set me"; 
         String apiKey = "set me"; 
    
         // Create client 
         ApiClient client = new RestApiClient().withCredentials(username, apiKey); 
    
         // Define SoftLayer_Product_Package service 
         Package.Service packageService = Package.service(client); 
    
         // Declare and object mask 
         packageService.withMask().itemPrices(); 
         packageService.withMask().configuration(); 
    
         Gson gson = new Gson(); 
    
         try { 
          for(Package pack : packageService.getAllObjects()) 
          { 
           System.out.println(gson.toJson(pack.getItemPrices())); 
           System.out.println(gson.toJson(pack.getConfiguration())); 
          } 
         } catch (Exception e) { 
          System.out.println("Error: " + e); 
         } 
        } 
    
        /** 
        * This is the main method which makes use of GetPackages method. 
        * 
        * @param args 
        * @return Nothing 
        */ 
        public static void main(String[] args) { 
         new GetPackages(); 
        } 
    
    
    } 
    

    請讓我知道你有關於它的任何疑問或問題。

    參考

    +0

    謝謝!我使用這個鏈接取得了一些進展:https://github.com/softlayer/softlayer-java/issues/22 – CSN

    0

    你也可以嘗試這個例子。

    package SoftLayer_Java_Scripts.Examples; 
    
    import java.util.List; 
    
    import com.softlayer.api.ApiClient; 
    import com.softlayer.api.RestApiClient; 
    import com.softlayer.api.service.product.Package; 
    import com.softlayer.api.service.product.Item; 
    
    public class GetProductItemsById { 
    
        public static void main(String[] args){ 
        String username = "set me"; 
        String apikey = "set me"; 
        ApiClient client = new RestApiClient().withCredentials(username, apikey); 
    
        Package.Service service = Package.service(client); 
    
        try 
        { 
         List<Package> packageList = service.getAllObjects(); 
    
         for(Package pack : packageList){ 
         System.out.println("------- Package: " + pack.getName() + " - Id: " + pack.getId()); 
    
         service = Package.service(client, pack.getId()); 
         List<Item> itemList = service.getItems(); 
    
         for(Item item : itemList){ 
          System.out.println("Item description: " + item.getDescription()); 
          System.out.println("Item Id: " + item.getId()); 
         } 
         } 
        } 
        catch(Exception e) 
        { 
         System.out.println("Script failed, review the next message for further details: " + e); 
        } 
        } 
    }