avatar

48

First set of changes towards a massive refactoring of the AuctionServer class, to be more specific, more testable, and more sane.

by cyberfox, 21 Feb, 2007 03:16 AM
24 48  
99 import com.jbidwatcher.util.Currency;
1010 import com.jbidwatcher.FilterManager;
1111 import com.jbidwatcher.auction.server.AuctionServer;
12 import com.jbidwatcher.auction.server.AuctionServerInterface;
1213 
1314 /**
1415  * Created by IntelliJ IDEA.
------
5960   public Currency getAmount() { return m_amount; }
6061   public int getQuantity() { return m_quant; }
6162   public boolean isSuccessful() {
62     return (m_result == AuctionServer.BID_WINNING ||
63             m_result == AuctionServer.BID_DUTCH_CONFIRMED ||
64             m_result == AuctionServer.BID_SELFWIN);
63     return (m_result == AuctionServerInterface.BID_WINNING ||
64             m_result == AuctionServerInterface.BID_DUTCH_CONFIRMED ||
65             m_result == AuctionServerInterface.BID_SELFWIN);
6566   }
6667 
6768   public String getBidResult(Currency bidAmount, int bidResult) {
6869     String bidResultString;
6970 
7071     switch (bidResult) {
71       case AuctionServer.BID_ERROR_UNKNOWN:
72       case AuctionServerInterface.BID_ERROR_UNKNOWN:
7273         bidResultString = "Bidding " + bidAmount + " apparently failed for an unknown reason.  Check the auction in the browser, to see if the bid went through anyway.";
7374         break;
74       case AuctionServer.BID_ERROR_ENDED:
75       case AuctionServer.BID_ERROR_CANNOT:
75       case AuctionServerInterface.BID_ERROR_ENDED:
76       case AuctionServerInterface.BID_ERROR_CANNOT:
7677         bidResultString = "Bidding apparently failed, as the auction cannot be bid on anymore (probably ended)!";
7778         break;
78       case AuctionServer.BID_DUTCH_CONFIRMED:
79       case AuctionServerInterface.BID_DUTCH_CONFIRMED:
7980         bidResultString = "Your dutch bid was confirmed, and you are in the list of high bidders!";
8081         break;
81       case AuctionServer.BID_ERROR_BANNED:
82       case AuctionServerInterface.BID_ERROR_BANNED:
8283         bidResultString = "Your bid failed, as you are disallowed from bidding on this seller's items.";
8384         break;
84       case AuctionServer.BID_ERROR_TOO_LOW:
85       case AuctionServerInterface.BID_ERROR_TOO_LOW:
8586         bidResultString = "Your bid was too low, and was not accepted.";
8687         break;
87       case AuctionServer.BID_ERROR_TOO_LOW_SELF:
88       case AuctionServerInterface.BID_ERROR_TOO_LOW_SELF:
8889           bidResultString = "Your bid was below or equal to your previous high bid, and was not accepted.";
8990           break;
90       case AuctionServer.BID_ERROR_RESERVE_NOT_MET:
91       case AuctionServerInterface.BID_ERROR_RESERVE_NOT_MET:
9192         bidResultString = "Your bid was successful, but it did not meet the reserve price.";
9293         break;
93       case AuctionServer.BID_ERROR_AMOUNT:
94       case AuctionServerInterface.BID_ERROR_AMOUNT:
9495         bidResultString = "Bidding apparently failed, because of an an invalid amount (" + bidAmount + ").";
9596         break;
96       case AuctionServer.BID_ERROR_OUTBID:
97       case AuctionServerInterface.BID_ERROR_OUTBID:
9798         bidResultString = "Your bid for " + bidAmount + " was submitted, but someone else's bid is still higher.";
9899         break;
99       case AuctionServer.BID_ERROR_CONNECTION:
100       case AuctionServerInterface.BID_ERROR_CONNECTION:
100101         bidResultString = "Bid failed due to connection problem.  Probably a timeout trying to reach eBay.";
101102         break;
102103       case AuctionServer.BID_ERROR_AUCTION_GONE:
103104         bidResultString = "Your bid failed because the item was removed from JBidwatcher before the bid executed.";
104105         break;
105       case AuctionServer.BID_WINNING:
106       case AuctionServer.BID_SELFWIN:
106       case AuctionServerInterface.BID_WINNING:
107       case AuctionServerInterface.BID_SELFWIN:
107108         bidResultString = "Congratulations!  You have the high bid with " + bidAmount + '.';
108109         break;
109110       case AuctionServer.BID_ERROR_ACCOUNT_SUSPENDED:
24 48  
88 
99 import com.jbidwatcher.util.Currency;
1010 import com.jbidwatcher.auction.server.AuctionServer;
11 import com.jbidwatcher.auction.server.AuctionServerInterface;
1112 
1213 public class AuctionBuy extends AuctionActionImpl {
1314   public AuctionBuy(String id, Currency amount, int quantity) {
------
2627     String bidResultString;
2728 
2829     switch (bidResult) {
29       case AuctionServer.BID_ERROR_UNKNOWN:
30       case AuctionServerInterface.BID_ERROR_UNKNOWN:
3031         bidResultString = "Purchasing " + bidAmount + " apparently failed for an unknown reason.  Check the auction in the browser, to see if it went through anyway.";
3132         break;
32       case AuctionServer.BID_ERROR_ENDED:
33       case AuctionServer.BID_ERROR_CANNOT:
33       case AuctionServerInterface.BID_ERROR_ENDED:
34       case AuctionServerInterface.BID_ERROR_CANNOT:
3435         bidResultString = "Purchasing apparently failed, as the auction cannot be bought from anymore (probably ended)!";
3536         break;
36       case AuctionServer.BID_ERROR_BANNED:
37       case AuctionServerInterface.BID_ERROR_BANNED:
3738         bidResultString = "Your purchase failed, as you are disallowed from buying this seller's items.";
3839         break;
39       case AuctionServer.BID_ERROR_CONNECTION:
40       case AuctionServerInterface.BID_ERROR_CONNECTION:
4041         bidResultString = "Purchase failed due to connection problem.  Probably a timeout trying to reach eBay.";
4142         break;
4243       case AuctionServer.BID_ERROR_AUCTION_GONE:
24 48  
2222 import com.jbidwatcher.*;
2323 import com.jbidwatcher.auction.server.AuctionServerManager;
2424 import com.jbidwatcher.auction.server.AuctionServer;
25 import com.jbidwatcher.auction.server.AuctionServerInterface;
2526 import com.jbidwatcher.util.ErrorManagement;
2627 
2728 import java.io.*;
------
321322   public static String stripId(String id) {
322323     String strippedId = id;
323324     if(id.startsWith("http")) {
324       AuctionServer aucServ = AuctionServerManager.getInstance().getServerForUrlString(id);
325       AuctionServerInterface aucServ = AuctionServerManager.getInstance().getServerForUrlString(id);
325326       strippedId = aucServ.extractIdentifierFromURLString(id);
326327     }
327328 
47 48  
1515 import com.jbidwatcher.util.http.CookieJar;
1616 import com.jbidwatcher.util.ErrorManagement;
1717 import com.jbidwatcher.auction.server.AuctionServer;
18 import com.jbidwatcher.auction.server.AuctionServerInterface;
1819 import com.jbidwatcher.auction.Auctions;
1920 import com.jbidwatcher.auction.AuctionEntry;
2021 
------
124125 
125126   public static String getSnipeResult(int snipeResult, String aucTitle, AuctionEntry aeFire) {
126127     String snipeOutput;
127     if(snipeResult == AuctionServer.BID_WINNING || snipeResult == AuctionServer.BID_SELFWIN) {
128     if(snipeResult == AuctionServerInterface.BID_WINNING || snipeResult == AuctionServerInterface.BID_SELFWIN) {
128129       snipeOutput = "Successfully sniped a high bid on " + aucTitle + '!';
129     } else if(snipeResult == AuctionServer.BID_DUTCH_CONFIRMED) {
130     } else if(snipeResult == AuctionServerInterface.BID_DUTCH_CONFIRMED) {
130131       snipeOutput = "Successfully sniped a high dutch bid on " + aucTitle + '!';
131132     } else {
132133       switch(snipeResult) {
133         case AuctionServer.BID_ERROR_UNKNOWN:
134         case AuctionServerInterface.BID_ERROR_UNKNOWN:
134135           snipeOutput = "Unknown error sniping on " + aucTitle;
135136           break;
136         case AuctionServer.BID_ERROR_ENDED:
137         case AuctionServer.BID_ERROR_CANNOT:
137         case AuctionServerInterface.BID_ERROR_ENDED:
138         case AuctionServerInterface.BID_ERROR_CANNOT:
138139           snipeOutput = "Snipe apparently failed, as the auction cannot be bid on anymore: " + aucTitle;
139140           break;
140         case AuctionServer.BID_ERROR_BANNED:
141         case AuctionServerInterface.BID_ERROR_BANNED:
141142           snipeOutput = "Snipe failed, as you are disallowed from bidding on " + aeFire.getSeller() + "'s items.";
142143           break;
143         case AuctionServer.BID_ERROR_TOO_LOW:
144         case AuctionServerInterface.BID_ERROR_TOO_LOW:
144145           snipeOutput = "Snipe was too low, and was not accepted.";
145146           break;
146         case AuctionServer.BID_ERROR_TOO_LOW_SELF:
147         case AuctionServerInterface.BID_ERROR_TOO_LOW_SELF:
147148           snipeOutput = "Your bid was below or equal to your previous high bid, and was not accepted.";
148149           break;
149         case AuctionServer.BID_ERROR_RESERVE_NOT_MET:
150         case AuctionServerInterface.BID_ERROR_RESERVE_NOT_MET:
150151           snipeOutput = "Your snipe was successful, but it did not meet the reserve price.";
151152           break;
152         case AuctionServer.BID_ERROR_AMOUNT:
153         case AuctionServerInterface.BID_ERROR_AMOUNT:
153154           snipeOutput = "There is an error with the amount for the snipe on " + aucTitle + " (Probably snipe too low vs. current bids).";
154155           break;
155         case AuctionServer.BID_ERROR_OUTBID:
156         case AuctionServerInterface.BID_ERROR_OUTBID:
156157           snipeOutput = "You have been outbid in your snipe on " + aucTitle;
157158           break;
158         case AuctionServer.BID_ERROR_CONNECTION:
159         case AuctionServerInterface.BID_ERROR_CONNECTION:
159160           snipeOutput = "Snipe failed due to connection problem.  Probably a timeout trying to reach eBay.";
160161           break;
161162         case AuctionServer.BID_ERROR_AUCTION_GONE:
------
173174         case AuctionServer.BID_ERROR_REQUIREMENTS_NOT_MET:
174175           snipeOutput = "You don't meet some requirement the seller has set for the item.  Check the item details for more information.";
175176           break;
176         case AuctionServer.BID_ERROR_MULTI:
177         case AuctionServerInterface.BID_ERROR_MULTI:
177178           snipeOutput = "There is a problem with the multisnipe, an earlier entry hasn't finished updating.  Trying again shortly.";
178179           break;
179180         default:
24 48  
4040 import java.text.SimpleDateFormat;
4141 
4242 
43 public abstract class AuctionServer implements XMLSerialize {
44   public static final int BID_ERROR_UNKNOWN=-1;
45   public static final int BID_ERROR_CANNOT=1;
46   public static final int BID_ERROR_AMOUNT=2;
47   public static final int BID_ERROR_OUTBID=3;
48   public static final int BID_WINNING=4;
49   public static final int BID_SELFWIN=5;
50   public static final int BID_DUTCH_CONFIRMED=6;
51   public static final int BID_ERROR_MULTI=7;
52   public static final int BID_ERROR_TOO_LOW=8;
53   public static final int BID_ERROR_ENDED=9;
54   public static final int BID_ERROR_BANNED=10;
55   public static final int BID_ERROR_RESERVE_NOT_MET=11;
56   public static final int BID_ERROR_CONNECTION=12;
57   public static final int BID_ERROR_TOO_LOW_SELF = 13; // You can't bid that low against yourself...
58   public static final int BID_ERROR_AUCTION_GONE = 14; // Auction vanished between bid creation and submission.
59   public static final int BID_ERROR_NOT_BIN = 15; // Trying to 'Buy' an item that isn't a BIN/Fixed Price listing.
60   public static final int BID_BOUGHT_ITEM = 16; //  Successfully bought an item via BIN.
61   public static final int BID_ERROR_ACCOUNT_SUSPENDED = 17; //  Your account has been (!) suspended, you can't bid.
62   public static final int BID_ERROR_CANT_SIGN_IN = 18; //  We tried to get bid pages, but it kept asking for login.
63   public static final int BID_ERROR_WONT_SHIP = 19; //  You are registered in a country to which the seller doesn't ship.
64   public static final int BID_ERROR_REQUIREMENTS_NOT_MET = 20; //  This seller has set buyer requirements for this item and only sells to buyers who meet those requirements.
43 public abstract class AuctionServer implements XMLSerialize, AuctionServerInterface {
6544 
6645   protected String siteId = null; /**< The human-readable name of an auction server. */
6746   private String userCfgString=null;
------
7251   private static final int YEAR_BASE = 1990;
7352   private static GregorianCalendar midpointDate = new GregorianCalendar(YEAR_BASE, Calendar.JANUARY, 1);
7453   private static final int HIGHBIT_ASCII = 0x80;
75   public static final String UPDATE_LOGIN_COOKIE = "Update login cookie";
7654 
77   public abstract StringBuffer getAuctionViaAffiliate(CookieJar cj, AuctionEntry ae, String id) throws CookieJar.CookieException;
78   public abstract int buy(AuctionEntry ae, int quantity);
55   protected abstract StringBuffer getAuction(AuctionEntry ae, String id);
56 
7957   public abstract long getSnipePadding();
8058 
8159   /*!@class BadBidException
------
10280     }
10381   }
10482 
105   protected final Set<AuctionEntry> _aucList = new TreeSet<AuctionEntry>(new AuctionEntry.AuctionComparator()); /**< The list of auctions that this server is holding onto. */
106 
107   protected long _pageRequestTime=0; /**< The full amount of time it takes to request a single page from this site. */
108   protected long _affRequestTime=0;  /**< The amount of time it takes to request an item via their affiliate program. */
83   protected final Set<AuctionEntry> _aucList = new TreeSet<AuctionEntry>(new AuctionEntry.AuctionComparator());
84   /**< The amount of time it takes to request an item via their affiliate program. */
10985   protected long _officialServerTimeDelta=0;
11086   protected TimeZone _officialServerTimeZone = null;
111   public abstract String extractIdentifierFromURLString(String urlStyle);
87 
11288   public abstract CookieJar getNecessaryCookie(boolean force);
11389   public abstract CookieJar getSignInCookie(CookieJar old_cj);
11490   public abstract void safeGetAffiliate(CookieJar cj, AuctionEntry inEntry) throws CookieJar.CookieException;
11591   public abstract JHTML.Form getBidForm(CookieJar cj, AuctionEntry inEntry, com.jbidwatcher.util.Currency inCurr, int inQuant) throws BadBidException;
116   public abstract int bid(AuctionEntry inEntry, Currency inBid, int inQuantity);
92 
11793   public abstract int placeFinalBid(CookieJar cj, JHTML.Form bidForm, AuctionEntry inEntry, Currency inBid, int inQuantity);
118   public abstract boolean checkIfIdentifierIsHandled(String auctionId);
94 
11995   public abstract void establishMenu();
12096   public abstract JConfigTab getConfigurationTab();
12197   public abstract void cancelSearches();
12298   public abstract void addSearches(SearchManagerInterface searchManager);
123   public abstract Currency getMinimumBidIncrement(Currency currentBid, int bidCount);
99 
124100   public abstract boolean isHighDutch(AuctionEntry inAE);
125101   public abstract void updateHighBid(AuctionEntry ae);
126102 
------
131107    */
132108   protected abstract Date getOfficialTime();
133109 
134   /** 
135    * @brief Get the URL (in String form that a browser can view with) for a given item ID on this auction server.
136    * 
137    * @param itemID - The item to retrieve the URL for.
138    * 
139    * @return - A String with the full URL of the item description on the auction server.
140    */
141   public abstract String getBrowsableURLFromItem(String itemID);
142 
143   /** 
110   /**
144111    * @brief Get the string-form URL for a given item ID on this
145112    * auction server, for when we aren't browsing.
146113    * 
------
268235   //  Generalized logic
269236   //  -----------------
270237 
271   /** 
272    * @brief Add an auction to this server, based on item ID.
273    * 
274    * @param itemId - The auction item to add.
275    * 
276    * @return - The underlying 'AuctionInfo' object that contains all
277    * the basic accessors for auction data.
278    */
279238   public AuctionInfo addAuction(String itemId) {
280239     URL auctionURL = getURLFromItem(itemId);
281240     return( addAuction(auctionURL, itemId));
------
292251     }
293252   }
294253 
295   /** 
296    * @brief Get the human-readable auction site name for this server.
297    * 
298    * @return - A String with the human-readable auction site name.
299    */
300254   public String getName() {
301255     return siteId;
302256   }
------
505459     }
506460   }
507461 
508   /**
509    * @brief Returns the amount of time it takes to retrieve a page
510    * from the auction server.
511    * 
512    * @return The amount of milliseconds it takes to get a simple page
513    * from the auction server.
514    */
515   public long getPageRequestTime() {
516     return _pageRequestTime;
517   }
518 
519   /**
520    * @brief Returns the amount of time it takes to retrieve an item
521    * from the auction server via their affiliate program.
522    *
523    * @return The amount of milliseconds it takes to get an item
524    * from the auction server via their affiliate server.
525    */
526   public long getAffiliateRequestTime() {
527     return _affRequestTime;
528   }
529 
530   /**
531    * @brief Returns the difference in time between the local machine's
532    * normalized time, and the auction site's normalized time.
533    * 
534    * @return The amount of milliseconds off the server time is from
535    * local time.
536    */
537462   public long getOfficialServerTimeDelta() {
538463     return _officialServerTimeDelta;
539464   }
540465 
541   /** 
542    * @brief Retrieve what time zone the server is in.
543    * 
544    * @return - The time zone of the auction server.
545    */
546466   public TimeZone getOfficialServerTimeZone() {
547467     return _officialServerTimeZone;
548468   }
549469 
550   /** 
551    * @brief Load an auction, and return it.  It really doesn't 'add'
552    * anything...
553    * 
554    * @param auctionURL - The URL to the item description to add.
555    * @param item_id - The item ID to add.
556    * 
557    * @return - An AuctionInfo low-level generic Auction object.
558    */
559470   public AuctionInfo addAuction(URL auctionURL, String item_id) {
560     SpecificAuction newAuction = (SpecificAuction) loadAuction(auctionURL, item_id, null, true);
471     SpecificAuction newAuction = (SpecificAuction) loadAuction(auctionURL, item_id, null);
561472 
562473     return(newAuction);
563474   }
------
595506 
596507   static long s_last_updated = 0;
597508 
598   public AuctionInfo loadAuction(URL auctionURL, String item_id, AuctionEntry ae) {
599     return loadAuction(auctionURL, item_id, ae, false);
600   }
601 
602509   private void markCommunicationError(AuctionEntry ae) {
603510     if (ae != null) {
604511       MQFactory.getConcrete("Swing").enqueue("LINK DOWN Communications failure talking to the server during item #" + ae.getIdentifier() + "( " + ae.getTitle() + " )");
------
615522    * @param auctionURL - The URL to load the auction from.
616523    * @param item_id - The item # to associate this returned info with.
617524    * @param ae - An object to notify when an error occurs.
618    * @param viaAffiliate - Whether to load via an affiliate link or not.
619    * 
620525    * @return - An object containing the information extracted from the auction.
621526    */
622   public AuctionInfo loadAuction(URL auctionURL, String item_id, AuctionEntry ae, boolean viaAffiliate) {
623     SpecificAuction curAuction = getNewSpecificAuction();
527   public AuctionInfo loadAuction(URL auctionURL, String item_id, AuctionEntry ae) {
528     StringBuffer sb = getAuction(ae, item_id);
624529 
625     if(item_id != null) {
626       curAuction.setIdentifier(item_id);
627     }
628     StringBuffer sb = null;
629 
630     if(viaAffiliate) {
530     if (sb == null) {
631531       try {
632         long pre = System.currentTimeMillis();
633         sb = getAuctionViaAffiliate(getNecessaryCookie(false), ae, item_id);
634         long post = System.currentTimeMillis();
635         _affRequestTime = (post - pre);
636         if(sb == null) viaAffiliate = false;
637       } catch (CookieJar.CookieException e) {
638         //  This failed...  Let's retry with a normal get...
639         viaAffiliate = false;
532         sb = getAuction(auctionURL);
533       } catch (FileNotFoundException ignored) {
534         //  Just get out.  The item no longer exists on the auction
535         //  server, so we shouldn't be trying any of the rest.  The
536         //  Error should have been logged at the lower level, so just
537         //  punt.  It's not a communications error, either.
538         return null;
539       } catch (Exception catchall) {
540         if (JConfig.debugging()) {
541           ErrorManagement.handleException("Some unexpected error occurred during loading the auction.", catchall);
542         }
640543       }
641544     }
642545 
643     try {
644       if(!viaAffiliate) {
645         if (JConfig.queryConfiguration("timesync.enabled", "true").equals("true")) {
646           long pre = System.currentTimeMillis();
647           sb = getAuction(auctionURL);
648           long post = System.currentTimeMillis();
649           _pageRequestTime = (post - pre);
650         } else /* TimeSync disabled */
651           sb = getAuction(auctionURL);
652       }
653       if(sb != null) {
654         curAuction.setContent(sb, false);
655       }
656     } catch(FileNotFoundException ignored) {
657       //  Just get out.  The item no longer exists on the auction
658       //  server, so we shouldn't be trying any of the rest.  The
659       //  Error should have been logged at the lower level, so just
660       //  punt.  It's not a communications error, either.
661       return null;
662     } catch(Exception catchall) {
663       if(JConfig.debugging()) ErrorManagement.handleException("Some unexpected error occurred during loading the auction.", catchall);
664       sb = null;
546     SpecificAuction curAuction = null;
547     if(sb != null) {
548       curAuction = doParse(sb, ae, item_id);
665549     }
666     boolean successfulParse = true;
667550 
668     if(sb == null) {
669       checkLogError(ae);
670       successfulParse = false;
551     if(curAuction == null) {
552       noteRetrieveError(ae);
671553     }
554     return curAuction;
555   }
672556 
673     if(successfulParse) {
674       successfulParse = curAuction.preParseAuction();
675       if(successfulParse) {
676         successfulParse = curAuction.parseAuction(ae);
677       } else {
678         ErrorManagement.logMessage("Bad Parse!");
679         checkLogError(ae);
680       }
557   private SpecificAuction doParse(StringBuffer sb, AuctionEntry ae, String item_id) {
558     SpecificAuction curAuction = getNewSpecificAuction();
559 
560     if (item_id != null) {
561       curAuction.setIdentifier(item_id);
681562     }
563     curAuction.setContent(sb, false);
564     String error = null;
565     if (curAuction.preParseAuction()) {
566       if (curAuction.parseAuction(ae)) {
567         curAuction.save();
568       } else error = "Bad Parse!";
569     } else error = "Bad pre-parse!";
682570 
683     if(!successfulParse) {
684       //  Whoops!  Bad thing happened on the way to loading the auction!
685       ErrorManagement.logDebug("Failed to parse auction!  Bad return result from auction server.");
686       //  Only retry the login cookie once every ten minutes of these errors.
687       if( (s_last_updated + Constants.ONE_MINUTE * 10) > System.currentTimeMillis()) {
688         s_last_updated = System.currentTimeMillis();
689         MQFactory.getConcrete(siteId).enqueue(new AuctionQObject(AuctionQObject.MENU_CMD, UPDATE_LOGIN_COOKIE, null)); //$NON-NLS-1$ //$NON-NLS-2$
690       }
691       curAuction = null;
571     if(error != null) {
572       ErrorManagement.logMessage(error);
573       checkLogError(ae);
692574     }
575       return curAuction;
576   }
693577 
694     if(curAuction != null) {
695       curAuction.save();
578   private void noteRetrieveError(AuctionEntry ae) {
579     checkLogError(ae);
580     //  Whoops!  Bad thing happened on the way to loading the auction!
581     ErrorManagement.logDebug("Failed to parse auction!  Bad return result from auction server.");
582     //  Only retry the login cookie once every ten minutes of these errors.
583     if ((s_last_updated + Constants.ONE_MINUTE * 10) > System.currentTimeMillis()) {
584       s_last_updated = System.currentTimeMillis();
585       MQFactory.getConcrete(siteId).enqueue(new AuctionQObject(AuctionQObject.MENU_CMD, UPDATE_LOGIN_COOKIE, null)); //$NON-NLS-1$ //$NON-NLS-2$
696586     }
697     return(curAuction);
698587   }
699588 
700589   private void checkLogError(AuctionEntry ae) {
------
800689     } else {
801690       //  This is bad...
802691       ErrorManagement.logMessage(siteId + ": Error, can't accurately set delta to server's official time.");
803       //  This should be LOGGED!  -- FIXME  -- mrs: 13-February-2001 19:59
804       _pageRequestTime = 0;
805692       _officialServerTimeDelta = 0;
806693       return false;
807694     }
24 48  
123123     String cmd = (String)deQ;
124124 
125125     if(cmd.equals("TIMECHECK")) {
126       AuctionServer defaultServer = getDefaultServer();
126       AuctionServerInterface defaultServer = getDefaultServer();
127127 
128128       defaultServer.reloadTimeNow();
129129 
------
150150   }
151151 
152152   public String getDefaultServerTime() {
153     AuctionServer defaultServer = getDefaultServer();
153     AuctionServerInterface defaultServer = getDefaultServer();
154154     return defaultServer.getTime();
155155   }
156156 
37 48  
3131 import com.jbidwatcher.auction.*;
3232 import com.jbidwatcher.auction.server.AuctionServerManager;
3333 import com.jbidwatcher.auction.server.AuctionServer;
34 import com.jbidwatcher.auction.server.AuctionServerInterface;
3435 import com.jbidwatcher.TimerHandler;
3536 import com.jbidwatcher.Constants;
3637 import com.jbidwatcher.auction.ThumbnailManager;
------
124125   private Map<String, AuctionQObject> snipeMap = new HashMap<String, AuctionQObject>();
125126   private String mBadPassword = null;
126127   private String mBadUsername = null;
128   /**< The full amount of time it takes to request a single page from this site. */
129   protected long _affRequestTime=0;
130   /**< The list of auctions that this server is holding onto. */
127131 
132   protected long _pageRequestTime=0;
133 
128134   {
129135     loadStrings();
130136   }
------
857863     }
858864 
859865     Auctions.endBlocking();
866 
867     //  If we couldn't get a number, clear the page request time.
868     if(result == null) _pageRequestTime = 0;
860869     return result;
861870   }
862871 
------
10561065     return 1;
10571066   }
10581067 
1059   public StringBuffer getAuctionViaAffiliate(CookieJar cj, AuctionEntry ae, String id) throws CookieJar.CookieException {
1068   public StringBuffer getAuction(AuctionEntry ae, String id) {
1069     CookieJar cj = getCookie();
10601070     long end_time = 1;
1071     //  TODO -- Replace with a global lookup for auction entry by id.
10611072     if(ae != null) {
10621073       Date end = ae.getEndDate();
10631074       if(end != null) end_time = end.getTime();
10641075     }
10651076     StringBuffer sb = null;
1066     if(JBConfig.doAffiliate(end_time)) {
1067       sb = AffiliateRetrieve.getAuctionViaAffiliate(cj, id);
1077     if(cj != null && allowAffiliate() && JBConfig.doAffiliate(end_time)) {
1078       try {
1079         long pre = System.currentTimeMillis();
1080         sb = AffiliateRetrieve.getAuctionViaAffiliate(cj, id);
1081         long post = System.currentTimeMillis();
1082         _affRequestTime = (post - pre);
1083       } catch(CookieJar.CookieException cje) {
1084         //  Cookie failure...  Ignore it and do a regular get.
1085       }
10681086     }
10691087 
10701088     if(sb == null || sb.indexOf("eBay item") == -1) {
10711089       try {
1090         long pre = System.currentTimeMillis();
10721091         sb = getAuction(getURLFromItem(id));
1092         long post = System.currentTimeMillis();
1093         if (JConfig.queryConfiguration("timesync.enabled", "true").equals("true")) {
1094           _pageRequestTime = (post - pre);
1095         }
10731096       } catch (FileNotFoundException ignored) {
10741097         sb = null;
10751098       }
------
10781101     return sb;
10791102   }
10801103 
1104   public long getPageRequestTime() {
1105     return _pageRequestTime;
1106   }
1107 
1108   private boolean allowAffiliate() {
1109     ErrorManagement.logDebug("NOT allowing affiliate mode.");
1110     return false;
1111   }
1112 
1113   private CookieJar getCookie() {
1114     ErrorManagement.logDebug("NOT getting cookie.");
1115     return null;
1116   }
1117 
10811118   public int buy(AuctionEntry ae, int quantity) {
10821119     String buyRequest = "http://offer.ebay.com/ws/eBayISAPI.dll?MfcISAPICommand=BinConfirm&fb=1&co_partnerid=&item=" + ae.getIdentifier() + "&quantity=" + quantity;
10831120 
10841121     //  This updates the cookies with the affiliate information, if it's not a test auction.
10851122     if(ae.getTitle().toLowerCase().indexOf("test") == -1) {
10861123       if(JBConfig.doAffiliate(ae.getEndDate().getTime())) {
1087         try {
1088           getAuctionViaAffiliate(getNecessaryCookie(false), ae, ae.getIdentifier());
1089         } catch (CookieJar.CookieException ignore) {
1090           //  Ignore, it doesn't matter for this call.
1091         }
1124         //  Ignoring the result as it's just called to trigger affiliate mode.
1125         getAuction(ae, ae.getIdentifier());
10921126       }
10931127     }
10941128 
------
11911225     if(inEntry.getTitle().toLowerCase().indexOf("test") == -1) {
11921226       if(JBConfig.doAffiliate(inEntry.getEndDate().getTime())) {
11931227         if(JConfig.debugging) inEntry.setLastStatus("Loading item...");
1194         getAuctionViaAffiliate(cj, inEntry, inEntry.getIdentifier());
1228         getAuction(inEntry, inEntry.getIdentifier());
11951229         if(JConfig.debugging) inEntry.setLastStatus("Done loading item...");
11961230       }
11971231     }
------
15581592           /**
15591593            * Does this look like an auction server item URL?
15601594            */
1561           AuctionServer aucServ = AuctionServerManager.getInstance().getServerForUrlString(url);
1595           AuctionServerInterface aucServ = AuctionServerManager.getInstance().getServerForUrlString(url);
15621596           String hasId = aucServ.extractIdentifierFromURLString(url);
15631597 
15641598           if (hasId != null) {
------
27782812       }
27792813     }
27802814   }
2815 
2816   /**
2817    * @brief Returns the amount of time it takes to retrieve an item
2818    * from the auction server via their affiliate program.
2819    *
2820    * @return The amount of milliseconds it takes to get an item
2821    * from the auction server via their affiliate server.
2822    */
2823   public long getAffiliateRequestTime() {
2824     return _affRequestTime;
2825   }
27812826 }
39 48  
341341       try {
342342         boolean got = false;
343343         if(JConfig.queryConfiguration("server.browseAffiliate", "true").equals("true")) {
344           try {
345             StringBuffer sb = aucServ.getAuctionViaAffiliate(aucServ.getNecessaryCookie(false), ae, ae.getIdentifier());
346             if(sb != null) {
347               sbOut.append(sb);
348               got = true;
349             }
350           } catch (CookieJar.CookieException ignored) {
351             //  Ignore it, because 'got' will be false, and the right thing will happen.
344           StringBuffer sb = aucServ.getAuction(AuctionServer.getURLFromString(aucServ.getStringURLFromItem(ae.getIdentifier())));
345           if (sb != null) {
346             sbOut.append(sb);
347             got = true;
352348           }
353349         }
354350         if(!got) {
28 48  
1616 import java.io.FileNotFoundException;
1717 
1818 public class MockAuctionServer extends AuctionServer {
19   /**< The full amount of time it takes to request a single page from this site. */
20   protected long _affRequestTime=0;
21   /**< The list of auctions that this server is holding onto. */
22 
23   protected long _pageRequestTime=0;
24 
1925   public MockAuctionServer() {
2026     siteId = "testBay";
2127   }
------
4147     }
4248   }
4349 
44   public StringBuffer getAuctionViaAffiliate(CookieJar cj, AuctionEntry ae, String id) throws CookieJar.CookieException {
45     addCall("getAuctionViaAffiliate");
50   public StringBuffer getAuction(AuctionEntry ae, String id) {
51     addCall("getAuction");
4652     StringBuffer sb = null;
4753     try {
4854       sb = getAuction(getURLFromItem(id));
------
142148     return "http://www.jbidwatcher.com";
143149   }
144150 
151   public long getPageRequestTime() {
152     return 0;  //To change body of implemented methods use File | Settings | File Templates.
153   }
154 
145155   public String getStringURLFromItem(String itemID) {
146156     TestCase.fail("Unexpected function called!");
147157     return "http://www.jbidwatcher.com";
------
172182     addCall("checkIfSiteNameHandled");
173183     return true;
174184   }
185 
186   /**
187    * @brief Returns the amount of time it takes to retrieve an item
188    * from the auction server via their affiliate program.
189    *
190    * @return The amount of milliseconds it takes to get an item
191    * from the auction server via their affiliate server.
192    */
193   public long getAffiliateRequestTime() {
194     return _affRequestTime;
195   }
175196 }