Question

I am creating an android application with an app engine back end. I used the google app engine plugin to create an android connected app. Here is my entity.

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id;
@Persistent
String email;
@Persistent
String password;

I used the plugin to generate my endpoint. To test it, I run the app engine as a web application and I can use every method successfully. I navigate to

 http://localhost:8888/_ah/admin/datastore 

and I can see the records that I entered. To be sure the generated getUser method works I go to the API explorer and retrieve user with id = 1 and I get

{ "id": "1", "email": "this@that.com", "password": "1234" }

So I know it works. In my android app I connect to the endpoint like this:

User user = new User();
        Userendpoint.Builder endpointBuilder = new Userendpoint.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), new HttpRequestInitializer() {
            public void initialize(HttpRequest httpRequest) {
            }
        });
        Userendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
        try {

            User result = endpoint.getUser(1L).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }

And I get the following error

com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service Unavailable { "code" : 503, "errors" : [ { "domain" : "global", "message" : "javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of kind User with key User(1)\nNestedThrowables:\norg.datanucleus.exceptions.NucleusObjectNotFoundException: Could not retrieve entity of kind User with key User(1)", "reason" : "backendError" } ],

Any advice or ideas would be greatly appreciated!

Was it helpful?

Solution

The error was that I was connecting to the development server from my laptop, but I was connecting to the production server on my device.

Change

// For development server
protected static final String LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = "http://<Your IP>:<your port>/_ah/api";

// For production server
protected static final String LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = "https://<your version>-<your project ID>.appspot.com/_ah/api/";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top