我在與客戶的Restlet調用工作休息服務問題:使用的Restlet ClientResource不能發送實體的Restlet服務
final ClientResource resource = new ClientResource(Routes.PUBLIC_STORE_API);
resource.setOnResponse(new Uniform() {
public void handle(Request request, Response response) {
try {
Status status = response.getStatus();
if(!Status.isError(status.getCode())){
String jsonResponse = response.getEntity().getText();
} else {
// Handle error
}
} catch (Exception e){
callback.failure(new Throwable(e.getMessage()));
}
}
});
JsniHelper.consoleLog("Adding object id=" + id + " type=" + type + " data=" + jsonObject);
resource.getReference().addQueryParameter("type", type);
resource.getReference().addQueryParameter("id",id);
resource.post(jsonObject, MediaType.APPLICATION_JSON);
在日誌中的對象上的點是有效的JSON字符串。
的的Restlet ServerResource
能夠同時獲得id
和type
絃樂但是實體總是null
:
@Post("json")
public Representation add(Representation entity){ // omitted }
我試圖用捲曲和REST服務能夠正確處理JSON字符串。
GWT中我的代碼有什麼問題?
更新:我在POM
<dependency>
<groupId>org.restlet.gae</groupId>
<artifactId>org.restlet.ext.gwt</artifactId>
<version>2.2-RC3</version>
</dependency>
你能分享你所用的'curl'命令,所以我們可以看到,它與上面列出的Java相匹配? –
我在這裏做了另一個測試:'curl -H「Content-Type:application/json」-d'{「username」:「xyz」,「password」:「xyz」}'http:// localhost:8888/publicstore ?id = null&type = user' – xybrek
上面的一個工作並能夠保存到數據存儲中,GWT的後調用(使用Restlet GWT)總是失敗。然而,我有另一個調用get調用類似的代碼,並且工作正常。此外,查詢參數可以,服務器獲取它,只有表示實體爲空。 – xybrek