Changeset 1169 in josm for trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
- Timestamp:
- 2008-12-23T15:07:05+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1137 r1169 79 79 80 80 long uploadStartTime; 81 81 82 82 public String timeLeft(int progress, int list_size) { 83 83 long now = System.currentTimeMillis(); … … 96 96 return time_left_str; 97 97 } 98 98 99 99 public void uploadOsm(Collection<OsmPrimitive> list) throws SAXException { 100 100 processed = new LinkedList<OsmPrimitive>(); … … 103 103 Main.pleaseWaitDlg.progress.setMaximum(list.size()); 104 104 Main.pleaseWaitDlg.progress.setValue(0); 105 105 106 106 // controls whether or not we open and close a changeset. API 0.6 requires changesets. 107 107 boolean useChangesets = Main.pref.get("osm-server.version", "0.5").equals("0.6"); 108 108 109 109 // controls whether or not we try and uplaod the whole bunch in one go 110 boolean useDiffUploads = Main.pref.getBoolean("osm-server.atomic-upload", 110 boolean useDiffUploads = Main.pref.getBoolean("osm-server.atomic-upload", 111 111 Main.pref.get("osm-server.version", "0.5").equals("0.6")); 112 112 113 113 String comment = null; 114 114 while (useChangesets && comment == null) { 115 comment = JOptionPane.showInputDialog(Main.parent, 115 comment = JOptionPane.showInputDialog(Main.parent, 116 116 tr("Provide a brief comment as to the changes to you are uploading:"), 117 117 tr("Commit comment"), JOptionPane.QUESTION_MESSAGE); … … 131 131 return; 132 132 } 133 133 134 134 try { 135 135 if (useDiffUploads) { … … 166 166 } 167 167 catch (OsmTransferException ex) { 168 dealWithTransferException(ex); 168 dealWithTransferException(ex); 169 169 } 170 170 dealWithTransferException(e); 171 171 } 172 172 } 173 173 174 174 /* FIXME: This code is terrible, please fix it!!!! */ 175 175 … … 183 183 * can fix the issue where hitting cancel doesn't do anything while 184 184 * retrying. - Mv0 Apr 2008 185 * 185 * 186 186 * Cancelling has an effect now, maybe it does not always catch on. Florian Heer, Aug 08 187 187 */ … … 198 198 Main.pref.get("osm-server.url") + 199 199 "/" + version + 200 "/" + "changeset" + 200 "/" + "changeset" + 201 201 "/" + "create"); 202 202 System.out.print("upload to: "+url+ "..." ); … … 205 205 activeConnection.setRequestMethod("PUT"); 206 206 addAuth(activeConnection); 207 207 208 208 activeConnection.setDoOutput(true); 209 209 OutputStream out = activeConnection.getOutputStream(); 210 210 OsmWriter.output(out, changeset); 211 211 out.close(); 212 212 213 213 activeConnection.connect(); 214 214 System.out.println("connected"); … … 224 224 } 225 225 if (retCode != 200 && retCode != 412) { 226 226 227 227 if (retries >= 0) { 228 228 retries--; … … 232 232 return startChangeset(retries, comment); 233 233 } 234 234 235 235 // Look for a detailed error message from the server 236 236 retMsg += "\n" + readString(activeConnection.getInputStream()); … … 262 262 throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 263 263 } 264 264 265 265 catch (Exception e) { 266 266 if (cancel) … … 274 274 return true; 275 275 } 276 276 277 277 private void uploadDiff(int retries, Collection<OsmPrimitive> list) throws OsmTransferException { 278 278 279 279 CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset); 280 280 … … 290 290 String diff = duv.getDocument(); 291 291 System.out.println(diff); 292 292 293 293 Main.pleaseWaitDlg.currentAction.setText(tr("Uploading...")); 294 294 try { … … 299 299 Main.pref.get("osm-server.url") + 300 300 "/" + version + 301 "/" + "changeset" + 301 "/" + "changeset" + 302 302 "/" + changeset.id + 303 303 "/upload" ); … … 307 307 activeConnection.setRequestMethod("POST"); 308 308 addAuth(activeConnection); 309 309 310 310 activeConnection.setDoOutput(true); 311 311 PrintWriter out; … … 317 317 out.print(diff); 318 318 out.close(); 319 319 320 320 activeConnection.connect(); 321 321 System.out.println("connected"); … … 323 323 int retCode = activeConnection.getResponseCode(); 324 324 String retMsg = ""; 325 325 326 326 if (retCode == 200) { 327 327 DiffResultReader.parseDiffResult(activeConnection.getInputStream(), list, processed, duv.getNewIdMap(), Main.pleaseWaitDlg); … … 333 333 System.out.println("retrying ("+retries+" left)"); 334 334 stopChangeset(retries); 335 } else { 335 } else { 336 336 // Look for a detailed error message from the server 337 337 retMsg += "\n" + readString(activeConnection.getInputStream()); … … 372 372 } 373 373 } 374 375 374 375 376 376 private void stopChangeset(int retries) throws OsmTransferException { 377 377 Main.pleaseWaitDlg.currentAction.setText(tr("Closing changeset...")); … … 383 383 Main.pref.get("osm-server.url") + 384 384 "/" + version + 385 "/" + "changeset" + 385 "/" + "changeset" + 386 386 "/" + changeset.id + 387 387 "/close" ); … … 391 391 activeConnection.setRequestMethod("PUT"); 392 392 addAuth(activeConnection); 393 393 394 394 activeConnection.setDoOutput(true); 395 395 OutputStream out = activeConnection.getOutputStream(); 396 396 OsmWriter.output(out, changeset); 397 397 out.close(); 398 398 399 399 activeConnection.connect(); 400 400 System.out.println("connected"); … … 415 415 System.out.println("retrying ("+retries+" left)"); 416 416 stopChangeset(retries); 417 } else { 417 } else { 418 418 // Look for a detailed error message from the server 419 419 retMsg += readString(activeConnection.getInputStream()); 420 420 421 421 // Report our error 422 422 ByteArrayOutputStream o = new ByteArrayOutputStream(); … … 490 490 processed.add(e); 491 491 } 492 492 493 493 /** 494 494 * Read a long from the input stream and return it. … … 540 540 new URL(Main.pref.get("osm-server.url") + 541 541 "/" + version + "/"), 542 urlSuffix + 542 urlSuffix + 543 543 "/" + (osm.id==0 ? "create" : osm.id), 544 544 new MyHttpHandler()); … … 622 622 } 623 623 } 624 624 625 625 private void sendRequest(String requestMethod, String urlSuffix, 626 626 OsmPrimitive osm, boolean addBody) { … … 636 636 } 637 637 } 638 638 639 639 private void dealWithTransferException (OsmTransferException e) { 640 640 Main.pleaseWaitDlg.currentAction.setText(tr("Transfer aborted due to error (will wait for 5 seconds):") + e.getMessage());
Note:
See TracChangeset
for help on using the changeset viewer.
