<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/com/jbidwatcher/util/http/HttpInterface.java</filename>
    </added>
    <added>
      <filename>src/com/jbidwatcher/util/http/HttpMock.java</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -15,6 +15,7 @@ import com.jbidwatcher.util.xml.XMLElement;
 import com.jbidwatcher.util.xml.XMLInterface;
 import com.jbidwatcher.util.http.Http;
 import com.jbidwatcher.util.http.ClientHttpRequest;
+import com.jbidwatcher.util.http.HttpInterface;
 import com.jbidwatcher.auction.AuctionEntry;
 import com.jbidwatcher.auction.EntryCorral;
 
@@ -35,7 +36,7 @@ import java.util.Date;
  */
 public class MyJBidwatcher {
   private static MyJBidwatcher sInstance = null;
-  private Http mNet = null;
+  private HttpInterface mNet = null;
   private static String LOG_UPLOAD_URL =  &quot;my.jbidwatcher.com/upload/log&quot;;
   private static String ITEM_UPLOAD_URL = &quot;my.jbidwatcher.com/upload/listing&quot;;
   private static String SYNC_UPLOAD_URL = &quot;my.jbidwatcher.com/upload/sync&quot;;
@@ -53,7 +54,7 @@ public class MyJBidwatcher {
     return &quot;http://&quot; + url;
   }
 
-  private Http http() {
+  private HttpInterface http() {
     if(mNet == null) {
       mNet = new Http();
     }</diff>
      <filename>src/com/jbidwatcher/my/MyJBidwatcher.java</filename>
    </modified>
    <modified>
      <diff>@@ -12,22 +12,22 @@ import java.util.*;
 import java.io.IOException;
 
 public class CookieJar {
-  private Map&lt;String, Cookie&gt; _cookies;
-  private boolean m_ignore_redirect_cookies = false;
-  private final static boolean do_uber_debug = false;
+  private Map&lt;String, Cookie&gt; mCookies;
+  private boolean mIgnoreRedirectCookies = false;
+  private final static boolean sUberDebug = false;
 
   public CookieJar() {
-    _cookies = new TreeMap&lt;String, Cookie&gt;();
+    mCookies = new TreeMap&lt;String, Cookie&gt;();
   }
 
   public Cookie getCookie(String keyName) {
-    return _cookies.get(keyName);
+    return mCookies.get(keyName);
   }
 
   public String dump() {
     StringBuffer rval = new StringBuffer();
-    for(String cookieName : _cookies.keySet()) {
-      Cookie value = _cookies.get(cookieName);
+    for(String cookieName : mCookies.keySet()) {
+      Cookie value = mCookies.get(cookieName);
       rval.append(cookieName).append(&quot;: &quot;).append(value.getValue()).append('\n');
     }
     return rval.toString();
@@ -163,7 +163,7 @@ public class CookieJar {
     do {
       nextKey = uc.getHeaderFieldKey(i);
       if(nextKey != null) {
-        if(do_uber_debug) {
+        if(sUberDebug) {
           JConfig.log().logDebug(nextKey+&quot;: &quot; + uc.getHeaderField(i));
         }
         //  If we're redirected, shortcut to loading the new page.
@@ -179,7 +179,7 @@ public class CookieJar {
         if(nextKey.startsWith(&quot;Set-Cookie&quot;) ||
            nextKey.startsWith(&quot;Set-cookie&quot;)) {
           Cookie newCookie = new Cookie(uc.getHeaderField(i));
-          _cookies.put(newCookie.getKey(), newCookie);
+          mCookies.put(newCookie.getKey(), newCookie);
         }
       }
       i++;
@@ -215,29 +215,23 @@ public class CookieJar {
   }
 
   private HttpURLConnection initiateRequest(boolean post, String sendRequest, String cgi, String referer) {
-    HttpURLConnection uc;
+    URLConnection uc;
+    String cookies = mCookies.isEmpty() ? null : this.toString();
 
-    if(!_cookies.isEmpty()) {
-      if(post) {
-        uc = (HttpURLConnection)Http.net().postFormPage(sendRequest, cgi, this.toString(), referer, m_ignore_redirect_cookies);
-      } else {
-        uc = (HttpURLConnection)Http.net().getPage(sendRequest, this.toString(), referer, m_ignore_redirect_cookies);
-      }
+    if(post) {
+      uc = Http.net().postFormPage(sendRequest, cgi, cookies, referer, mIgnoreRedirectCookies);
     } else {
-      if(post) {
-        uc = (HttpURLConnection)Http.net().postFormPage(sendRequest, cgi, null, referer, m_ignore_redirect_cookies);
-      } else {
-        uc = (HttpURLConnection)Http.net().getPage(sendRequest, null, referer, m_ignore_redirect_cookies);
-      }
+      uc = Http.net().getPage(sendRequest, cookies, referer, mIgnoreRedirectCookies);
     }
-    return uc;
+
+    return (HttpURLConnection)uc;
   }
 
   public String toString() {
     boolean firstThrough = true;
     StringBuffer outBuf = null;
 
-    for (Cookie cookie : _cookies.values()) {
+    for (Cookie cookie : mCookies.values()) {
       if (cookie.getValue().length() != 0) {
         if (!firstThrough) {
           outBuf.append(&quot;; &quot;);</diff>
      <filename>src/com/jbidwatcher/util/http/CookieJar.java</filename>
    </modified>
    <modified>
      <diff>@@ -16,12 +16,12 @@ import java.net.*;
 import java.io.*;
 import java.util.Map;
 
-public class Http {
+public class Http implements HttpInterface {
   private String mUsername = null;
   private String mPassword = null;
 
-  private static Http sInstance = new Http();
-  public static Http net() { return sInstance; }
+  private static HttpInterface sInstance = new Http();
+  public static HttpInterface net() { return sInstance; }
 
   public void setAuthInfo(String user, String pass) {
     mUsername = user;
@@ -54,14 +54,14 @@ public class Http {
     }
   }
 
-  public URLConnection postFormPage(String urlToPost, String cgiData, String cookie, String referer, boolean follow_redirects) {
+  public URLConnection postFormPage(String url, String cgiData, String cookie, String referer, boolean followRedirects) {
     URLConnection huc;
 
     try {
       if(JConfig.queryConfiguration(&quot;debug.urls&quot;, &quot;false&quot;).equals(&quot;true&quot;)) {
-        JConfig.log().logDebug(&quot;postFormPage: &quot; + urlToPost);
+        JConfig.log().logDebug(&quot;postFormPage: &quot; + url);
       }
-      URL authURL = new URL(urlToPost);
+      URL authURL = new URL(url);
 
       huc = authURL.openConnection();
       setConnectionInfo(huc);
@@ -70,7 +70,7 @@ public class Http {
       if(huc instanceof HttpURLConnection) {
         HttpURLConnection conn = (HttpURLConnection)huc;
         conn.setRequestMethod(&quot;POST&quot;);
-        if(!follow_redirects) conn.setInstanceFollowRedirects(false);
+        if(!followRedirects) conn.setInstanceFollowRedirects(false);
       }
       if(JConfig.queryConfiguration(&quot;debug.uber&quot;, &quot;false&quot;).equals(&quot;true&quot;) &amp;&amp; JConfig.debugging) {
         dumpFormHeaders(System.err, cgiData, cookie);
@@ -124,32 +124,32 @@ public class Http {
     return uc;
   }
 
-  public ByteBuffer getURL(URL dataURL) {
-    return getURL(dataURL, null);
+  public ByteBuffer getURL(URL url) {
+    return getURL(url, null);
   }
 
   /** 
    * @brief Retrieve data from HTTP in raw byte form.
    * 
-   * @param dataURL - The URL of the raw data to retrieve.
+   * @param url - The URL of the raw data to retrieve.
    * @param inCookie - Any cookie needed to be passed along.
    * 
    * @return - A result with raw data and the length.
    */
-  private ByteBuffer getURL(URL dataURL, String inCookie) {
+  private ByteBuffer getURL(URL url, String inCookie) {
     ByteBuffer rval;
 
     try {
-      rval = receiveData(makeRequest(dataURL, inCookie));
+      rval = receiveData(makeRequest(url, inCookie));
     } catch(FileNotFoundException fnfe) {
       //  It'd be great if we could pass along something that said, 'not here, never will be'.
       rval = null;
     } catch(IOException e) {
       //  Mostly ignore HTTP 504 error, it's just a temporary 'gateway down' error.
       if(e.getMessage().indexOf(&quot;HTTP response code: 504&quot;)==-1) {
-        JConfig.log().handleException(&quot;Error loading data URL (&quot; + dataURL.toString() + ')', e);
+        JConfig.log().handleException(&quot;Error loading data URL (&quot; + url.toString() + ')', e);
       } else {
-        JConfig.log().logMessage(&quot;HTTP 504 error loading URL (&quot; + dataURL.toString() + ')');
+        JConfig.log().logMessage(&quot;HTTP 504 error loading URL (&quot; + url.toString() + ')');
       }
       rval = null;
     }
@@ -227,27 +227,27 @@ public class Http {
   /**
    * Simplest request, load a URL, no cookie, no referer, follow redirects blindly.
    *
-   * @param urlToGet - The URL to load.
+   * @param url - The URL to load.
    * @return - A URLConnection usable to retrieve the page requested.
    */
-  public URLConnection getPage(String urlToGet) {
-    return(getPage(urlToGet, null, null, true));
+  public URLConnection getPage(String url) {
+    return(getPage(url, null, null, true));
   }
 
-  public URLConnection getPage(String urlToGet, String cookie, String referer, boolean redirect) {
+  public URLConnection getPage(String url, String cookie, String referer, boolean followRedirects) {
     HttpURLConnection huc;
 
     try {
       if(JConfig.queryConfiguration(&quot;debug.urls&quot;, &quot;false&quot;).equals(&quot;true&quot;)) {
-        JConfig.log().logDebug(&quot;getPage: &quot; + urlToGet);
+        JConfig.log().logDebug(&quot;getPage: &quot; + url);
       }
-      URL authURL = new URL(urlToGet);
+      URL authURL = new URL(url);
       URLConnection uc = authURL.openConnection();
       if(!(uc instanceof HttpURLConnection)) {
         return uc;
       }
       huc = (HttpURLConnection)uc;
-      huc.setInstanceFollowRedirects(redirect);
+      huc.setInstanceFollowRedirects(followRedirects);
       setConnectionInfo(huc);
 
       huc.setRequestProperty(&quot;User-Agent&quot;, Constants.FAKE_BROWSER);</diff>
      <filename>src/com/jbidwatcher/util/http/Http.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>93d2bb2d4b52649f9be6ba257a04e8359339f102</id>
    </parent>
  </parents>
  <author>
    <name>Morgan Schweers</name>
    <email>cyberfox@jbidwatcher.com</email>
  </author>
  <url>http://github.com/cyberfox/jbidwatcher/commit/08dd44d2cc28b87cd6375856b48e8f8a3cce8f92</url>
  <id>08dd44d2cc28b87cd6375856b48e8f8a3cce8f92</id>
  <committed-date>2009-11-08T01:24:25-08:00</committed-date>
  <authored-date>2009-11-08T01:24:25-08:00</authored-date>
  <message>Support mocking HTTP requests out for testing.  Essentially you register URLs to mock, and the URL to direct to instead.  (Generally this would be a local HTTP server.)  It can't be mocked to a file URL because we cast to HttpURLConnection in places, but it can be built to not hit eBay.

git-svn-id: svn://svn.jbidwatcher.com/jbidwatcher/trunk@1032 b1acfa68-eb39-11db-b167-a3a8cd6b847e</message>
  <tree>99cefe566bf274df0ddf5dd3b7ed0122e105ee9b</tree>
  <committer>
    <name>Morgan Schweers</name>
    <email>cyberfox@jbidwatcher.com</email>
  </committer>
</commit>
