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.
This commit is contained in:
Michael Bayne
2007-03-23 21:46:54 +00:00
parent 849c119227
commit 782d3e4e84
2 changed files with 23 additions and 11 deletions
@@ -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;
}
/**
@@ -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 + "].");