Allow customization of the C2DM URL. It is used for testing with a different server or to use HTTP or an intermediate server.

This commit is contained in:
costin
2010-08-24 20:39:32 +00:00
parent 9519e206bc
commit e4d848959b
3 changed files with 34 additions and 11 deletions

View File

@@ -35,6 +35,12 @@ public final class C2DMConfig {
@Persistent @Persistent
private String authToken; private String authToken;
public static final String DATAMESSAGING_SEND_ENDPOINT =
"https://android.clients.google.com/c2dm/send";
@Persistent
private String c2dmUrl;
public String getAuthToken() { public String getAuthToken() {
return (authToken == null) ? "" : authToken; return (authToken == null) ? "" : authToken;
} }
@@ -46,4 +52,16 @@ public final class C2DMConfig {
public void setKey(Key key) { public void setKey(Key key) {
this.key = key; this.key = key;
} }
public void setC2DMUrl(String url) {
this.c2dmUrl = url;
}
public String getC2DMUrl() {
if (c2dmUrl == null) {
return DATAMESSAGING_SEND_ENDPOINT;
} else {
return c2dmUrl;
}
}
} }

View File

@@ -38,6 +38,7 @@ class C2DMConfigLoader {
private static final Logger log = Logger.getLogger(C2DMConfigLoader.class.getName()); private static final Logger log = Logger.getLogger(C2DMConfigLoader.class.getName());
String currentToken; String currentToken;
String c2dmUrl;
C2DMConfigLoader(PersistenceManagerFactory pmf) { C2DMConfigLoader(PersistenceManagerFactory pmf) {
this.PMF = pmf; this.PMF = pmf;
@@ -69,9 +70,8 @@ class C2DMConfigLoader {
} }
/** /**
* Return the auth token. * Return the auth token from the database. Should be called
* * only if the old token expired.
* It'll first memcache, if not found will use the database.
* *
* @return * @return
*/ */
@@ -82,6 +82,13 @@ class C2DMConfigLoader {
return currentToken; return currentToken;
} }
public String getC2DMUrl() {
if (c2dmUrl == null) {
c2dmUrl = getDataMessagingConfig().getC2DMUrl();
}
return c2dmUrl;
}
public C2DMConfig getDataMessagingConfig() { public C2DMConfig getDataMessagingConfig() {
PersistenceManager pm = PMF.getPersistenceManager(); PersistenceManager pm = PMF.getPersistenceManager();
try { try {

View File

@@ -45,9 +45,6 @@ import com.google.appengine.api.labs.taskqueue.TaskOptions;
public class C2DMessaging { public class C2DMessaging {
private static final String UPDATE_CLIENT_AUTH = "Update-Client-Auth"; private static final String UPDATE_CLIENT_AUTH = "Update-Client-Auth";
public static final String DATAMESSAGING_SEND_ENDPOINT =
"https://android.clients.google.com/c2dm/send";
private static final Logger log = Logger.getLogger(C2DMessaging.class.getName()); private static final Logger log = Logger.getLogger(C2DMessaging.class.getName());
public static final String PARAM_REGISTRATION_ID = "registration_id"; public static final String PARAM_REGISTRATION_ID = "registration_id";
@@ -141,7 +138,7 @@ public class C2DMessaging {
byte[] postData = postDataBuilder.toString().getBytes(UTF8); byte[] postData = postDataBuilder.toString().getBytes(UTF8);
// Hit the dm URL. // Hit the dm URL.
URL url = new URL(DATAMESSAGING_SEND_ENDPOINT); URL url = new URL(serverConfig.getC2DMUrl());
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true); conn.setDoOutput(true);
@@ -185,8 +182,9 @@ public class C2DMessaging {
// return non-success error codes, this is not explicitly implemented here. // return non-success error codes, this is not explicitly implemented here.
// If we weren't using App Engine, we'd need to manually implement this. // If we weren't using App Engine, we'd need to manually implement this.
if (responseLine == null || responseLine.equals("")) { if (responseLine == null || responseLine.equals("")) {
log.info("Got " + responseCode + " response from Google datamessaging endpoint."); log.info("Got " + responseCode +
throw new IOException("Got empty response from Google datamessaging endpoint."); " response from Google AC2DM endpoint.");
throw new IOException("Got empty response from Google AC2DM endpoint.");
} }
String[] responseParts = responseLine.split("=", 2); String[] responseParts = responseLine.split("=", 2);