Properly support https/http mode.
| 938 | 940 | |
|---|---|---|
| 35 | 35 | public class MyJBidwatcher { |
| 36 | 36 | private static MyJBidwatcher sInstance = null; |
| 37 | 37 | 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"; | |
| 40 | 40 | private String mSyncQueueURL = null; |
| 41 | 41 | private String mReportQueueURL = null; |
| 42 | 42 | private boolean mUseSSL = false; |
| --- | --- | |
| 46 | 46 | private boolean mReadSnipesFromServer = false; |
| 47 | 47 | private ZoneDate mExpiry; |
| 48 | 48 | |
| 49 | private String url(String url) { | |
| 50 | if(mUseSSL) return "https://" + url; | |
| 51 | return "http://" + url; | |
| 52 | } | |
| 53 | ||
| 49 | 54 | private Http http() { |
| 50 | 55 | if(mNet == null) { |
| 51 | 56 | mNet = new Http(); |
| --- | --- | |
| 58 | 63 | |
| 59 | 64 | public String sendLogFile(String email, String desc) { |
| 60 | 65 | File fp = JConfig.log().closeLog(); |
| 61 | return sendFile(fp, LOG_UPLOAD_URL, email, desc); | |
| 66 | return sendFile(fp, url(LOG_UPLOAD_URL), email, desc); | |
| 62 | 67 | } |
| 63 | 68 | |
| 64 | 69 | private String createFormSource(String formBase, String email, String desc) { |
| --- | --- | |
| 116 | 121 | Parameters p = new Parameters(); |
| 117 | 122 | if(identifier != null) p.put("item", identifier); |
| 118 | 123 | p.put("body", page); |
| 119 | String url = "http://my.jbidwatcher.com/services/recognize"; | |
| 124 | String url = url("my.jbidwatcher.com/services/recognize"); | |
| 120 | 125 | return http().postTo(url, p); |
| 121 | 126 | } |
| 122 | 127 | |
| 123 | 128 | public String reportException(String sb) { |
| 124 | 129 | Parameters p = new Parameters(); |
| 125 | 130 | p.put("body", sb); |
| 126 | String url = "http://my.jbidwatcher.com/services/report_exception"; | |
| 131 | String url = url("my.jbidwatcher.com/services/report_exception"); | |
| 127 | 132 | return http().postTo(url, p); |
| 128 | 133 | } |
| 129 | 134 | |
| --- | --- | |
| 133 | 138 | } |
| 134 | 139 | |
| 135 | 140 | 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")); | |
| 137 | 142 | 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")); | |
| 139 | 144 | mReportQueueURL = (sb == null) ? null : sb.toString(); |
| 140 | 145 | } |
| 141 | 146 | |
| --- | --- | |
| 178 | 183 | MQFactory.getConcrete("report").registerListener(new MessageQueue.Listener() { |
| 179 | 184 | public void messageAction(Object deQ) { |
| 180 | 185 | 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()); | |
| 182 | 187 | XMLElement root = new XMLElement("report"); |
| 183 | 188 | XMLElement s3Key = new XMLElement("s3"); |
| 184 | 189 | s3Key.setContents(s3Result); |
| --- | --- | |
| 203 | 208 | } |
| 204 | 209 | |
| 205 | 210 | 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"); | |
| 207 | 212 | if(sb == null) return false; |
| 208 | 213 | XMLElement xml = new XMLElement(); |
| 209 | 214 | xml.parseString(sb.toString()); |
| --- | --- | |
| 257 | 262 | // If 200 OK, the body contains the my.jbidwatcher.id |
| 258 | 263 | return false; |
| 259 | 264 | } |
| 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 | } | |
| 279 | 265 | } |
