So I have an application which uses C2DM messaging. It's working perfectly in the local server mode when it's hosted on my computer. When I deploy the application to app engine, however, it no longer works! I've been pulling my hair out and can't figure out why this is.
I've tried using the 1.5.2 and 1.5.3 App Engine SDKs and building against 2.3 and 2.4 GWT plugins on Eclipse. None of those seem to work. I can register the phone just fine, but no C2DM messages seem to be arriving to the phone.
Okay, so I've dug around and I've found out that there is a bug with the code as supplied by Google. On the local server, it stores the registration data username with all lowercase (MyEmail@bomb.com -> myemail@bomb.com). On the production server it does NOT use all lowercase to store the email. The following method queries the datastore, providing the email as an argument in all lower case.
Solution, comment out the indicated line or find a way to use all lower case when saving the email to the datastore upon registration.
/**
* Helper function - will query all registrations for a user.
*/
@SuppressWarnings("unchecked")
public static List<DeviceInfo> getDeviceInfoForUser(String user) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
// Canonicalize user name
-----> user = user.toLowerCase(Locale.ENGLISH);
Query query = pm.newQuery(DeviceInfo.class);
query.setFilter("key >= '" +
user + "' && key < '" + user + "$'");
List<DeviceInfo> qresult = (List<DeviceInfo>) query.execute();
// Copy to array - we need to close the query
List<DeviceInfo> result = new ArrayList<DeviceInfo>();
for (DeviceInfo di : qresult) {
result.add(di);
}
query.closeAll();
log.info("Return " + result.size() + " devices for user " + user);
return result;
} finally {
pm.close();
}
}