views:

33

answers:

0

Hello, I have written a web application to run on Google AppEngine using the Restlet framework, communicating using json with web clients. Those work as expected. However, one specific resource written to provide response to an Android client doesn't work when accessed through Android. However, it does work when accessed through a web browser (I do not send the request parameters from the browser and thus get a 400 which is ok in this case).

This code works when running on the DevAppServer:

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;
        }
    }
}

}

and the client Android device is running this code:

  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);

Running this request just hangs the Android client, the server doesn't write any log messages whatsoever suggesting the request doesn't arrive there.