2015-04-03 111 views
2

嘗試使用android客戶端訪問我的服務器上的自定義方法創建錯誤的請求錯誤。Strongloop android sdk自定義方法錯誤

這裏是服務器上的自定義方法(與strongloop探險測試):在Android問題庫

Question.remoteMethod(
    'top', { 
     http: {path: '/top', verb: 'get'}, 
     accepts: [ 
        {arg : 'start', type: 'number'}, 
        {arg: 'pagination', type: 'number'} 

       ], 
     returns: {arg: 'questions', type: 'array'}, 
     description: ['Returns an array obj the latest added questions'] 
    } 
); 

代碼:

@Override 
public RestContract createContract() { 

    RestContract contract = super.createContract(); 

    contract.addItem(
     new RestContractItem("/" + getNameForRestUrl() + "/top?" + 
      "start=" + ":start" + "&pagination=" + ":pagination", "GET"), 
     getClassName() + ".top"); 

    return contract; 
} 

public void top(int start, int pagination, ListCallback<Question> cb) { 
    Map<String, Integer> params = new HashMap<String, Integer>(); 
    params.put("start", start); 
    params.put("pagination", pagination); 
    invokeStaticMethod("top", params, 
      new JsonArrayParser<Question>(this, cb)); 
} 

當我使用這下面的代碼來測試創建請求的網址:

RestContract contract = this.createContract(); 
Map<String, Integer> params = new HashMap<String, Integer>(); 
     params.put("start", 0); 
     params.put("pagination", 2); 
     String t = contract.getUrl("/" + getNameForRestUrl() + "/top?" + 
       "start=" + ":start" + "&pagination=" + ":pagination", params); 

t是:「/Questions/top?st藝術= 0 &分頁= 2「這是正確的網址(根據強大的資源管理器)。 但是,使用函數TOP會返回錯誤的請求錯誤。

你知道我爲什麼出現錯誤,以及如何修改函數以獲得結果嗎?

回答

2

終於得到了答案。錯誤在問題庫中。

這裏是代碼右邊的和平:

@Override 
public RestContract createContract() { 

    RestContract contract = super.createContract(); 

    contract.addItem(
     new RestContractItem("/" + getNameForRestUrl() + "/top", "GET"), 
     getClassName() + ".top"); 
} 

public void top(int start, int pagination, ListCallback<Question> cb) { 
    Map<String, Integer> params = new HashMap<String, Integer>(); 
    params.put("start", start); 
    params.put("pagination", pagination); 
    invokeStaticMethod("top", params, 
     new JsonResponseParser<Question>(this, cb, "questions")); 
} 

當你作爲使用下面的頂方法機器會自動添加賦予參數映射爲一個過濾器參數創建其餘合同不得指定過濾器形式爲: http://serverip:port/api/Questions/top?filter=value1&filter2=value2