Skip to content

Commit

Permalink
fix: add etag to batch upload payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mchuangatmp committed Mar 8, 2022
1 parent 0f4446d commit b58fc16
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public interface MessageKey {
String ACCURACY = "acc";
// batch details
String MPARTICLE_VERSION = "sdk";
String MPARTICLE_CONFIG_VERSION = "mpcv";
String APP_INFO = "ai";
String DEVICE_INFO = "di";
String USER_ATTRIBUTES = "ua";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void fetchConfig(boolean force) throws IOException, MPConfigException {
String newModified = connection.getHeaderField("Last-Modified");

mConfigManager.updateConfig(response, newEtag, newModified);
}else if (connection.getResponseCode() == 400) {
} else if (connection.getResponseCode() == 400) {
throw new MPConfigException();
} else if (connection.getResponseCode() == 304) {
Logger.verbose("Config request deferred, configuration already up-to-date.");
Expand Down
39 changes: 13 additions & 26 deletions android-core/src/main/java/com/mparticle/internal/MessageBatch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.mparticle.internal;

import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_CONTEXT;
import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_ID;
import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_KEY;
import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_VERSION;

import com.mparticle.BuildConfig;
import com.mparticle.MParticle;
import com.mparticle.consent.CCPAConsent;
Expand All @@ -11,15 +16,9 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_CONTEXT;
import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_ID;
import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_KEY;
import static com.mparticle.internal.Constants.MessageKey.DATA_PLAN_VERSION;

public class MessageBatch extends JSONObject {
private long messageLengthBytes;

Expand All @@ -38,6 +37,7 @@ public static MessageBatch create(boolean history, ConfigManager configManager,
uploadMessage.put(Constants.MessageKey.MPARTICLE_VERSION, Constants.MPARTICLE_VERSION);
uploadMessage.put(Constants.MessageKey.OPT_OUT_HEADER, configManager.getOptedOut());
uploadMessage.put(Constants.MessageKey.CONFIG_UPLOAD_INTERVAL, configManager.getUploadInterval()/1000);
uploadMessage.put(Constants.MessageKey.MPARTICLE_CONFIG_VERSION, configManager.getEtag());
uploadMessage.put(Constants.MessageKey.CONFIG_SESSION_TIMEOUT, configManager.getSessionTimeout()/1000);
uploadMessage.put(Constants.MessageKey.MPID, String.valueOf(batchId.getMpid()));
uploadMessage.put(Constants.MessageKey.SANDBOX, configManager.getEnvironment().equals(MParticle.Environment.Development));
Expand Down Expand Up @@ -83,8 +83,6 @@ public void addConsentState(ConsentState consentState) {
state.put(Constants.MessageKey.CONSENT_STATE_CCPA, ccpa);
addConsentStateJSON(ccpa, Constants.MessageKey.CCPA_CONSENT_KEY, ccpaConsent);
}


} catch (JSONException ignored) { }
}
}
Expand All @@ -107,8 +105,7 @@ public void addSessionHistoryMessage(JSONObject message) {
put(Constants.MessageKey.HISTORY, new JSONArray());
}
getJSONArray(Constants.MessageKey.HISTORY).put(message);
} catch (JSONException e) {
}
} catch (JSONException ignored) { }
}

public void addMessage(JSONObject message) {
Expand All @@ -117,8 +114,7 @@ public void addMessage(JSONObject message) {
put(Constants.MessageKey.MESSAGES, new JSONArray());
}
getJSONArray(Constants.MessageKey.MESSAGES).put(message);
} catch (JSONException e) {
}
} catch (JSONException ignored) { }
}

public void addReportingMessage(JSONObject reportingMessage) {
Expand All @@ -127,24 +123,19 @@ public void addReportingMessage(JSONObject reportingMessage) {
put(Constants.MessageKey.REPORTING, new JSONArray());
}
getJSONArray(Constants.MessageKey.REPORTING).put(reportingMessage);
} catch (JSONException e) {
}
} catch (JSONException ignored) { }
}

public void setAppInfo(JSONObject appInfo) {
try {
put(Constants.MessageKey.APP_INFO, appInfo);
} catch (JSONException e) {

}
} catch (JSONException ignored) { }
}

public void setDeviceInfo(JSONObject deviceInfo) {
try {
put(Constants.MessageKey.DEVICE_INFO, deviceInfo);
} catch (JSONException e) {

}
} catch (JSONException ignored) { }
}

public JSONObject getAppInfo() {
Expand Down Expand Up @@ -182,17 +173,13 @@ public JSONArray getMessages() {
public void setIdentities(JSONArray identities) {
try {
put(Constants.MessageKey.USER_IDENTITIES, identities);
} catch (JSONException e) {

}
} catch (JSONException ignored) { }
}

public void setUserAttributes(JSONObject userAttributes) {
try {
put(Constants.MessageKey.USER_ATTRIBUTES, userAttributes);
} catch (JSONException e) {

}
} catch (JSONException ignored) { }
}

public long getMessageLengthBytes() {
Expand Down
2 changes: 1 addition & 1 deletion release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
{
assets: ["CHANGELOG.md", "build.gradle", "README.md"],
message:
"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
"chore(release): ${nextRelease.version} \n\n${nextRelease.notes}",
},
],
],
Expand Down

0 comments on commit b58fc16

Please sign in to comment.