Brien Gerber
Brien Gerber

Reputation: 15

Adding parameters to Cloud Endpoint causes 404 GoogleJsonResponseException

I have am having an issue where I completed the sample GCM Messaging (https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints)

and everything works fine until I want to add additional parameters to the registerDevice method in the the RegistrationEndpoint class. I've made sure that I added the @Named in before.

Before the change it looks like this:

@ApiMethod(name = "register")
public void registerDevice(@Named("regId") String regId) {
    if (findRecord(regId) != null) {
        log.info("Device " + regId + " already registered, skipping register");
        return;
    }
    RegistrationRecord record = new RegistrationRecord();
    record.setRegId(regId);
    //record.setUserName(name);
    //record.setUserProfId(profId);
    ofy().save().entity(record).now();
}

And after the change it looks like this:

@ApiMethod(name = "register")
public void registerDevice(@Named("regId") String regId, @Named("name") String name, @Named("profId") String profId) {
    if (findRecord(regId) != null) {
        log.info("Device " + regId + " already registered, skipping register");
        return;
    }
    RegistrationRecord record = new RegistrationRecord();
    record.setRegId(regId);
    record.setUserName(name);
    record.setUserProfId(profId);
    ofy().save().entity(record).now();
}

Once I added those two parameters, the GCM request fails with the following error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found

at this line in my code (in an AsyncTask)

regService.register(Globals.REG_ID,"Test","Test").execute();

But when it the "Test","Test" is removed as in the original tutorial, it works fine!

In conclusion, I can't post to the datastore when I added my own parameters with fields I want. Any suggestions?

Upvotes: 0

Views: 249

Answers (1)

tomrozb
tomrozb

Reputation: 26261

When you introduce new method in Google Cloud Endpoints you have to do:

  1. Upload new version to App Engine
  2. If you've changed the version name, you have to make it default one in the Developer Console

404 means there's no such method, so I assume you've not done yet one of the steps mentioned above.

If you done above steps just check if the method works using API Explorer

https://apis-explorer.appspot.com/apis-explorer/?base=https://appname.appspot.com/_ah/api

One more thing. Remember to check the parameters order. From my experience it will rather be (name, profId, regId), but I could be wrong:

regService.register("Test", "Test", Globals.REG_ID).execute(); 

Upvotes: 1

Related Questions