4
我已經編寫了一個Web應用程序,使用Restlet框架在Google AppEngine上運行,並使用json與Web客戶端進行通信。那些按預期工作。但是,通過Android訪問時,編寫的一個用於響應Android客戶端的特定資源不起作用。但是,它通過網絡瀏覽器訪問時可以正常工作(我不會從瀏覽器發送請求參數,因此在這種情況下可以獲得400這是可以的)。在Google AppEngine上運行已部署的應用程序的問題
public class PlayResource extends ServerResource {
private final float SCOREBASE = 1000.0F;
@Get
@Post
public JsonRepresentation play() {
try {
JsonRepresentation rep = new JsonRepresentation(getRequestEntity());
JSONObject inputJson = rep.getJsonObject();
JSONObject outputJson = new JSONObject();
String country = inputJson.optString("country");
outputJson.put("country", doSomething("country",country));
......
......
return new JsonRepresentation(outputJson);
} catch (IOException e) {
try {
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new JsonRepresentation(
new JSONObject()
.put(Messages.TYPE_ERROR, Messages.BAD_REQUEST));
} catch (JSONException e2) {
setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
}
} catch (JSONException e) {
try {
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new JsonRepresentation(
new JSONObject()
.put(Messages.TYPE_ERROR, Messages.BAD_FORMAT));
} catch (JSONException e2) {
setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
}
}
}
}
和客戶端的Android設備運行驗證碼:
此代碼對DevAppServer運行時,工作
Client client = new Client(Protocol.HTTP);
try {
JsonRepresentation requestJSON = new JsonRepresentation(new JSONObject()
.put("country", country.trim())
);
Request req = new Request(Method.GET,"http://****.appspot.com/resource/play",requestJSON);
Response resp = client.handle(req);
String res = resp.getEntity().getText();
JSONObject resultJSON = new JSONObject(res);
運行這一要求只是掛了Android客戶端,服務器沒有按」不要寫任何建議請求沒有到達的日誌消息。
無響應的App Engine應用程序通常是由錯誤配置的app.yaml描述和/或缺少的處理程序引起的。你可以在這裏包括這兩個?這將有助於診斷問題。 – Greg 2011-04-11 19:18:44
您是否嘗試過我的測試? – Panthro 2011-05-06 21:57:57