Skip to content

Commit

Permalink
Merge pull request #3 from kissmetrics/EOFException-fix
Browse files Browse the repository at this point in the history
Fix for URL connections in SDK 13+
  • Loading branch information
willrust committed May 12, 2014
2 parents 7b554b9 + 5fbf6ea commit 42baea7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
12 changes: 6 additions & 6 deletions KISSmetricsAPI/src/com/kissmetrics/sdk/ConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

import android.os.Build;
import android.util.Log;


Expand Down Expand Up @@ -75,21 +75,21 @@ public void sendRecord(final String urlString, final ConnectionDelegate delegate
connection = createHttpURLConnection(url);
connection.setUseCaches(false);
connection.setRequestMethod("GET");
connection.setConnectTimeout(CONNECTION_TIMEOUT*1000);
connection.setRequestProperty("User-Agent", "KISSmetrics-Android/2.0");
// TODO: Apply any easily obtainable device/OS info to the user agent value

connection.setConnectTimeout(CONNECTION_TIMEOUT*1000);
// addressing java.io.EOFException
if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) {
connection.setRequestProperty("Connection", "close");
}

responseCode = connection.getResponseCode();
connection.connect();

} catch (MalformedURLException e) {
Log.w("KISSmetricsAPI", "Connection URL was malformed: " + e);
malformed = true;
} catch (ProtocolException e) {
Log.w("KISSmetricsAPI", "Connection experienced a ProtocolException: " + e);
} catch (IOException e) {
Log.w("KISSmetricsAPI", "Connection experienced an IOException: " + e);
} catch (Exception e) {
Log.w("KISSmetricsAPI", "Connection experienced an Exception: " + e);
} finally {
Expand Down
21 changes: 8 additions & 13 deletions KISSmetricsAPI/src/com/kissmetrics/sdk/VerificationImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Build;
import android.util.Log;


Expand Down Expand Up @@ -76,7 +74,7 @@ public void verifyTracking(String productKey, String installUuid, VerificationDe
URL url = null;
connection = null;

long currentTime = System.currentTimeMillis();;
long currentTime = System.currentTimeMillis();

boolean success = false;
long expirationDate = 0;
Expand All @@ -93,6 +91,11 @@ public void verifyTracking(String productKey, String installUuid, VerificationDe
connection.setRequestMethod("GET");
connection.setConnectTimeout(CONNECTION_TIMEOUT * 1000);
connection.setRequestProperty("User-Agent", "KISSmetrics-Android/2.0");

// addressing java.io.EOFException
if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) {
connection.setRequestProperty("Connection", "close");
}

// TODO: Apply any easily obtainable device/OS info
//setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
Expand Down Expand Up @@ -131,17 +134,9 @@ public void verifyTracking(String productKey, String installUuid, VerificationDe
// We want to continue to track as we do not want to lose data
// over this. It will however not be sent or deleted until we
// have a confirmed successful instruction to track or not.
} catch (MalformedURLException e) {
} catch (Exception e) {
// The KISSmetrics SDK should not cause a customer's app to crash.
// Log a warning and continue.
Log.w("KISSmetricsAPI", "Verification URL was malformed: " + e);
} catch (ProtocolException e) {
Log.w("KISSmetricsAPI", "Verification experienced a ProtocolException: " + e);
} catch (IOException e) {
Log.w("KISSmetricsAPI", "Verification experienced an IOException: " + e);
} catch (JSONException e) {
Log.w("KISSmetricsAPI", "Verification experienced a JSONException: " + e);
} catch (Exception e) {
Log.w("KISSmetricsAPI", "Verification experienced an Exception: " + e);
} finally {

Expand Down
Binary file modified KISSmetricsSDK.jar
Binary file not shown.

0 comments on commit 42baea7

Please sign in to comment.