mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
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:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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,10 +70,9 @@ 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
|
||||||
*/
|
*/
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
@@ -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 {
|
||||||
|
|||||||
@@ -44,10 +44,7 @@ import com.google.appengine.api.labs.taskqueue.TaskOptions;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
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,8 +138,8 @@ 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);
|
||||||
conn.setUseCaches(false);
|
conn.setUseCaches(false);
|
||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user