Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sending api key to headers and hashing the stacktrace

  • Loading branch information...
commit 02bf35f5b3b8331e9bece2a4dcde09df64bfba05 1 parent 79bbd7f
Jon Vlachoyiannis authored
1  src/com/sfalma/trace/G.java
View
@@ -42,6 +42,7 @@
public static String TAG = "SfalmaHandler";
public static String ANDROID_VERSION = null;
public static String PHONE_MODEL = null;
+ public static String API_KEY = null;
public static String TraceVersion = "0.6.0";
}
1  src/com/sfalma/trace/G.template
View
@@ -42,6 +42,7 @@ public class G {
public static String TAG = "SfalmaHandler";
public static String ANDROID_VERSION = null;
public static String PHONE_MODEL = null;
+ public static String API_KEY = null;
public static String TraceVersion = "@__TRACEVERSION__@";
}
12 src/com/sfalma/trace/Sfalma.java
View
@@ -29,7 +29,9 @@
package com.sfalma.trace;
import java.io.IOException;
-
+import java.security.*;
+import java.math.*;
+
import org.apache.http.NameValuePair;
import org.json.JSONArray;
@@ -66,5 +68,13 @@ public static String createJSON(String app_package, String version, String phone
return json.toString();
}
+
+ public static String MD5 (String data) throws Exception {
+ MessageDigest m = MessageDigest.getInstance("MD5");
+
+ m.update(data.getBytes(), 0, data.length());
+ return new BigInteger(1, m.digest()).toString(16);
+ }
+
}
30 src/com/sfalma/trace/SfalmaHandler.java
View
@@ -61,7 +61,6 @@
/**
* Usage:
*
- * SfalmaHandler.setUrl('http://myserver.com/bugs')
* SfalmaHandler.setup(new SfalmaHandler.Processor() {
* boolean beginSubmit() {
* showDialog(DIALOG_SUBMITTING_CRASH);
@@ -101,8 +100,10 @@
* @param context
* @param processor
*/
- public static boolean setup(Context context, final Processor processor) {
+ public static boolean setup(Context context, final Processor processor, String apiKey) {
// Make sure this is only called once.
+ G.API_KEY = apiKey;
+
if (sSetupCalled) {
// Tell the task that it now has a new context.
if (sTask != null && !sTask.postProcessingDone()) {
@@ -169,12 +170,12 @@ public static boolean setup(Context context, final Processor processor) {
*
* @param context
*/
- public static boolean setup(Context context) {
+ public static boolean setup(Context context, String apiKey) {
return setup(context, new Processor() {
public boolean beginSubmit() { return true; }
public void submitDone() {}
public void handlerInstalled() {}
- });
+ }, apiKey);
}
/**
@@ -464,12 +465,15 @@ private static void submitStackTraces(ArrayList<String[]> list) {
Log.d(G.TAG, "Transmitting stack trace: " + stacktrace);
// Transmit stack trace with POST request
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ DefaultHttpClient httpClient = new DefaultHttpClient();
HttpParams params = httpClient.getParams();
+
+
// Lighty 1.4 has trouble with the expect header
// (http://redmine.lighttpd.net/issues/1017), and a
// potential workaround is only included in 1.4.21
// (http://www.lighttpd.net/2009/2/16/1-4-21-yes-we-can-do-another-release).
+ // : bla
HttpProtocolParams.setUseExpectContinue(params, false);
if (sTimeout != null) {
HttpConnectionParams.setConnectionTimeout(params, sTimeout);
@@ -477,19 +481,13 @@ private static void submitStackTraces(ArrayList<String[]> list) {
}
HttpPost httpPost = new HttpPost(G.URL);
- /*
- List <NameValuePair> nvps = new ArrayList <NameValuePair>();
- nvps.add(new BasicNameValuePair("package_name", G.APP_PACKAGE));
- nvps.add(new BasicNameValuePair("package_version", version));
- nvps.add(new BasicNameValuePair("phone_model", phoneModel));
- nvps.add(new BasicNameValuePair("android_version", androidVersion));
- nvps.add(new BasicNameValuePair("stacktrace", stacktrace));
- */
- List <NameValuePair> nvps_sfalma = new ArrayList <NameValuePair>();
+ httpPost.addHeader("X-Sfalma-Api-Key", G.API_KEY);
- nvps_sfalma.add(new BasicNameValuePair("sfalma", Sfalma.createJSON(G.APP_PACKAGE, version, phoneModel, androidVersion, stacktrace)));
+ List <NameValuePair> nvps = new ArrayList <NameValuePair>();
+ nvps.add(new BasicNameValuePair("data", Sfalma.createJSON(G.APP_PACKAGE, version, phoneModel, androidVersion, stacktrace)));
+ nvps.add(new BasicNameValuePair("hash", Sfalma.MD5(stacktrace)));
- httpPost.setEntity(new UrlEncodedFormEntity(nvps_sfalma, HTTP.UTF_8));
+ httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
// We don't care about the response, so we just hope it
// went well and on with it.
httpClient.execute(httpPost);
Please sign in to comment.
Something went wrong with that request. Please try again.