From 782d3e4e84a75671698e44259796346c12df6f10 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 23 Mar 2007 21:46:54 +0000 Subject: [PATCH] A bit of rearrangement. Let's have all the actual tracking logic take place in the launcher and let the Application continue to serve largely as an interface to our configuration information. --- .../threerings/getdown/data/Application.java | 21 ++++++++++--------- .../threerings/getdown/launcher/Getdown.java | 13 +++++++++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index fc8780d..19d3ad2 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -43,7 +43,6 @@ import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.net.URLConnection; import java.util.ArrayList; import java.util.HashMap; @@ -353,17 +352,19 @@ public class Application } /** - * Sets a cookie for a tracking URL if we have an appropriate property to fetch it from, - * an appropriate cookie name to assign, and the property is set to non-null. + * Returns the name of our tracking cookie or null if it was not set. */ - public void maybeSetTrackingCookie (URLConnection conn) + public String getTrackingCookieName () { - if (_trackingCookieName != null && _trackingCookieProperty != null) { - String val = System.getProperty(_trackingCookieProperty); - if (val != null) { - conn.setRequestProperty("Cookie", _trackingCookieName + "=" + val); - } - } + return _trackingCookieName; + } + + /** + * Returns the name of our tracking cookie system property or null if it was not set. + */ + public String getTrackingCookieProperty () + { + return _trackingCookieProperty; } /** diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 9d2220a..1617e20 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -853,7 +853,17 @@ public abstract class Getdown extends Thread public void run () { try { HttpURLConnection ucon = (HttpURLConnection)_url.openConnection(); - _app.maybeSetTrackingCookie(ucon); + + // if we have a tracking cookie configured, configure the request with it + if (_app.getTrackingCookieName() != null && + _app.getTrackingCookieProperty() != null) { + String val = System.getProperty(_app.getTrackingCookieProperty()); + if (val != null) { + ucon.setRequestProperty("Cookie", _app.getTrackingCookieName() + "=" + val); + } + } + + // now request our tracking URL and ensure that we get a non-error response ucon.connect(); try { if (ucon.getResponseCode() != HttpURLConnection.HTTP_OK) { @@ -863,6 +873,7 @@ public abstract class Getdown extends Thread } finally { ucon.disconnect(); } + } catch (IOException ioe) { Log.warning("Failed to report tracking event [url=" + _url + ", error=" + ioe + "].");