avatar

940

Properly support https/http mode.

by mrs, 03 Jun, 2009 11:12 AM
938 940  
3535 public class MyJBidwatcher {
3636   private static MyJBidwatcher sInstance = null;
3737   private Http mNet = null;
38   private static final String LOG_UPLOAD_URL =  "http://my.jbidwatcher.com/upload/log";
39   private static final String ITEM_UPLOAD_URL = "http://my.jbidwatcher.com/upload/listing";
38   private static String LOG_UPLOAD_URL =  "my.jbidwatcher.com/upload/log";
39   private static String ITEM_UPLOAD_URL = "my.jbidwatcher.com/upload/listing";
4040   private String mSyncQueueURL = null;
4141   private String mReportQueueURL = null;
4242   private boolean mUseSSL = false;
------
4646   private boolean mReadSnipesFromServer = false;
4747   private ZoneDate mExpiry;
4848 
49   private String url(String url) {
50     if(mUseSSL) return "https://" + url;
51     return "http://" + url;
52   }
53 
4954   private Http http() {
5055     if(mNet == null) {
5156       mNet = new Http();
------
5863 
5964   public String sendLogFile(String email, String desc) {
6065     File fp = JConfig.log().closeLog();
61     return sendFile(fp, LOG_UPLOAD_URL, email, desc);
66     return sendFile(fp, url(LOG_UPLOAD_URL), email, desc);
6267   }
6368 
6469   private String createFormSource(String formBase, String email, String desc) {
------
116121     Parameters p = new Parameters();
117122     if(identifier != null) p.put("item", identifier);
118123     p.put("body", page);
119     String url = "http://my.jbidwatcher.com/services/recognize";
124     String url = url("my.jbidwatcher.com/services/recognize");
120125     return http().postTo(url, p);
121126   }
122127 
123128   public String reportException(String sb) {
124129     Parameters p = new Parameters();
125130     p.put("body", sb);
126     String url = "http://my.jbidwatcher.com/services/report_exception";
131     String url = url("my.jbidwatcher.com/services/report_exception");
127132     return http().postTo(url, p);
128133   }
129134 
------
133138   }
134139 
135140   private void getSQSURL() {
136     StringBuffer sb = http().get("http://my.jbidwatcher.com/services/syncq");
141     StringBuffer sb = http().get(url("my.jbidwatcher.com/services/syncq"));
137142     mSyncQueueURL = (sb == null) ? null : sb.toString();
138     sb = http().get("http://my.jbidwatcher.com/services/reportq");
143     sb = http().get(url("my.jbidwatcher.com/services/reportq"));
139144     mReportQueueURL = (sb == null) ? null : sb.toString();
140145   }
141146 
------
178183       MQFactory.getConcrete("report").registerListener(new MessageQueue.Listener() {
179184         public void messageAction(Object deQ) {
180185           AuctionEntry ae = EntryCorral.getInstance().takeForRead((String)deQ);
181           String s3Result = sendFile(ae.getContentFile(), ITEM_UPLOAD_URL, JConfig.queryConfiguration("my.jbidwatcher.id"), ae.getLastStatus());
186           String s3Result = sendFile(ae.getContentFile(), url(ITEM_UPLOAD_URL), JConfig.queryConfiguration("my.jbidwatcher.id"), ae.getLastStatus());
182187           XMLElement root = new XMLElement("report");
183188           XMLElement s3Key = new XMLElement("s3");
184189           s3Key.setContents(s3Result);
------
203208   }
204209 
205210   public boolean getAccountInfo() {
206     StringBuffer sb = http().get("http://my.jbidwatcher.com/services/account");
211     StringBuffer sb = http().get("https://my.jbidwatcher.com/services/account");
207212     if(sb == null) return false;
208213     XMLElement xml = new XMLElement();
209214     xml.parseString(sb.toString());
------
257262     //  If 200 OK, the body contains the my.jbidwatcher.id
258263     return false;
259264   }
260 
261   public boolean updateAccount(String email, String password) {
262     //  TODO - Must be logged in first?
263     String user = JConfig.queryConfiguration("my.jbidwatcher.id");
264     if(user == null) return false;
265 
266     String old_key = JConfig.queryConfiguration("my.jbidwatcher.key");
267     //  TODO - PUT (!) http://my.jbidwatcher.com/users/update with user[email]={email}&user[password]={key}&old_password={old_key}
268     //  TODO - Write server side for update.
269 
270     return false;
271   }
272 
273   public boolean login(String email, String password) {
274     //  TODO - GET http://my.jbidwatcher.com/login
275     //  Fill in email and password & submit
276     //  Get back a session key/cookie?
277     return false;
278   }
279265 }