From 849c1192273dc9a800c1d34deff05b1cf7dde431 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Fri, 23 Mar 2007 16:57:04 +0000 Subject: [PATCH] Allow the specification of a cookie name and property to fetch its value from for tracking URLs. Clientstep needs this so we can identify the user and correlate with their other events. --- .../threerings/getdown/data/Application.java | 21 +++++++++++++++++++ .../threerings/getdown/launcher/Getdown.java | 7 ++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index e8bf6d1..fc8780d 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -43,6 +43,7 @@ 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; @@ -351,6 +352,20 @@ public class Application return getTrackingURL("pct" + percent); } + /** + * 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. + */ + public void maybeSetTrackingCookie (URLConnection conn) + { + if (_trackingCookieName != null && _trackingCookieProperty != null) { + String val = System.getProperty(_trackingCookieProperty); + if (val != null) { + conn.setRequestProperty("Cookie", _trackingCookieName + "=" + val); + } + } + } + /** * Instructs the application to parse its getdown.txt configuration and prepare * itself for operation. The application base URL will be parsed first so that if there are @@ -452,6 +467,10 @@ public class Application _trackingPcts = new ArrayIntSet(new int[] { 50 }); } + // Check for tracking cookie configuration + _trackingCookieName = (String)cdata.get("tracking_cookie_name"); + _trackingCookieProperty = (String)cdata.get("tracking_cookie_property"); + // clear our arrays as we may be reinitializing _codes.clear(); _resources.clear(); @@ -1089,6 +1108,8 @@ public class Application protected String _trackingURL; protected ArrayIntSet _trackingPcts; + protected String _trackingCookieName; + protected String _trackingCookieProperty; protected int _javaVersion; protected String _javaLocation; diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 1ff2499..9d2220a 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -691,7 +691,7 @@ public abstract class Getdown extends Thread EventQueue.invokeLater(new Runnable() { public void run () { if (_status == null) { - _container = createContainer(); + _container = createContainer(); _status = new StatusPanel(_msgs); _container.add(_status, BorderLayout.CENTER); } @@ -784,7 +784,7 @@ public abstract class Getdown extends Thread if (StringUtil.isBlank(path)) { return null; } - + File imgpath = null; try { // First try for a localized image. @@ -843,7 +843,7 @@ public abstract class Getdown extends Thread protected abstract void exit (int exitCode); /** Used to fetch a progress report URL. */ - protected static class ProgressReporter extends Thread + protected class ProgressReporter extends Thread { public ProgressReporter (URL url) { setDaemon(true); @@ -853,6 +853,7 @@ public abstract class Getdown extends Thread public void run () { try { HttpURLConnection ucon = (HttpURLConnection)_url.openConnection(); + _app.maybeSetTrackingCookie(ucon); ucon.connect(); try { if (ucon.getResponseCode() != HttpURLConnection.HTTP_OK) {