Question

Given the api endpoint

@ApiMethod(name = "sendChallenge", httpMethod = HttpMethod.POST)
public ExchangeList sendChallenge(ChallengeData request) throws Exception {
  return getFromDBThenProcess(request);
}

And the front end (android) call to endpoint

ExchangeList transfers = service.sendChallenge(request).execute();

I get the following stack trace from the LogCat.

Note: I am monitoring my server console (localhost) and no call came in.

Stacktrace:

04-08 14:58:53.261: D/dalvikvm(940): GC_CONCURRENT freed 1394K, 15% free 12495K/14599K, paused 15ms+15ms, total 75ms
… //[many of those `freed` lines]
04-08 14:58:54.742: D/dalvikvm(940): GC_CONCURRENT freed 1394K, 15% free 12506K/14599K, paused 15ms+16ms, total 85ms
04-08 14:58:55.562: W/System.err(940): com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
04-08 14:58:55.562: W/System.err(940): {
04-08 14:58:55.562: W/System.err(940):   "code": 0,
04-08 14:58:55.562: W/System.err(940):   "message": "com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.myapi.games.message.ChallengeData]: can not instantiate from JSON object (need to add/enable type information?)\n at [Source: N/A; line: -1, column: -1]"
04-08 14:58:55.572: W/System.err(940): }
04-08 14:58:55.572: W/System.err(940):  at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
04-08 14:58:55.572: W/System.err(940):  at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
04-08 14:58:55.572: W/System.err(940):  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:314)
04-08 14:58:55.572: W/System.err(940):  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1060)
04-08 14:58:55.572: W/System.err(940):  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
04-08 14:58:55.572: W/System.err(940):  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
04-08 14:58:55.572: W/System.err(940):  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
04-08 14:58:55.572: W/System.err(940):  at com.myapi.games.utils.sendChallenge.doInBackground(sendChallenge.java:70)
04-08 14:58:55.582: W/System.err(940):  at com.myapi.games.utils.sendChallenge.doInBackground(sendChallenge.java:1)
04-08 14:58:55.582: W/System.err(940):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-08 14:58:55.582: W/System.err(940):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-08 14:58:55.582: W/System.err(940):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-08 14:58:55.582: W/System.err(940):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-08 14:58:55.592: W/System.err(940):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-08 14:58:55.592: W/System.err(940):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-08 14:58:55.592: W/System.err(940):  at java.lang.Thread.run(Thread.java:856)

This is about an appengine connected android project. Everything compiles without errors, etc. Also the POJO ChallengeData is made of three other POJOs similar to:

public class ChallengeData{

  Credit credit;
  Coin  coin;
  Friend friend;

  //getters and setters
}

Then both Credit and Coin only contain simple fields (i.e. int and String) but Friend contains some simple fields and a further POJO.

I really don't think the depth of the JSON (i.e. POJO relations) should matter. But I include the details all the same.

Was it helpful?

Solution

You may be getting this error because you are sending images through your endpoint api AND you forgot to encode them in Base64. You must encode all images into a base64 string. Here is a link with code snippet showing how to do this. Rememeber you are encoding from byte to String. The reason I guess thus is because you mention your server is not getting any hit and yet you are getting a 400 Bad Request error, which means google is intercepting your call and is not able to parse the request. So try it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top