- Timestamp:
- 2008-08-15T20:50:36+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r763 r784 10 10 import java.io.InputStreamReader; 11 11 import java.io.OutputStream; 12 import java.net.ConnectException; 12 13 import java.net.HttpURLConnection; 13 14 import java.net.URL; … … 109 110 comment = null; 110 111 } 111 if( useChangesets && !startChangeset(10, comment) ) 112 try { 113 if( useChangesets && !startChangeset(10, comment) ) 114 return; 115 } 116 catch (OsmTransferException ex) { 117 dealWithTransferException (ex); 112 118 return; 119 } 113 120 114 121 NameVisitor v = new NameVisitor(); … … 127 134 Main.pleaseWaitDlg.progress.setValue(progress+1); 128 135 } 129 if( useChangesets ) stopChangeset(10); 136 if( useChangesets ) 137 stopChangeset(10); 130 138 } catch (RuntimeException e) { 131 if( useChangesets ) stopChangeset(10); 139 try { 140 if( useChangesets ) stopChangeset(10); 141 } 142 catch (OsmTransferException ex) { 143 dealWithTransferException(ex); 144 } 132 145 e.printStackTrace(); 133 146 throw new SAXException(tr("An error occoured: {0}",e.getMessage())); 147 } 148 catch (OsmTransferException e) { 149 try { 150 if( useChangesets ) stopChangeset(10); 151 } 152 catch (OsmTransferException ex) { 153 dealWithTransferException(ex); 154 } 155 dealWithTransferException(e); 134 156 } 135 157 } … … 146 168 * can fix the issue where hitting cancel doesn't do anything while 147 169 * retrying. - Mv0 Apr 2008 148 */ 149 private boolean startChangeset(int retries, String comment) { 170 * 171 * Cancelling has an effect now, maybe it does not always catch on. Florian Heer, Aug 08 172 */ 173 private boolean startChangeset(int retries, String comment) throws OsmTransferException { 150 174 Main.pleaseWaitDlg.currentAction.setText(tr("Opening changeset...")); 151 175 changeset = new Changeset(); … … 202 226 OsmWriter.output(o, changeset); 203 227 System.out.println(new String(o.toByteArray(), "UTF-8").toString()); 204 throw new RuntimeException(retCode+" "+retMsg); 228 //throw new RuntimeException(retCode+" "+retMsg); 229 throw new OsmTransferException (retCode + " " + retMsg); 205 230 } 206 231 } 207 232 } catch (UnknownHostException e) { 208 throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e); 233 //throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e); 234 throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e); 209 235 } catch(SocketTimeoutException e) { 210 236 System.out.println(" timed out, retries left: " + retries); … … 214 240 startChangeset(retries, comment); 215 241 else 216 throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 217 } catch (Exception e) { 242 // throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 243 throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 244 } 245 catch (ConnectException e) { 246 System.out.println(" timed out, retries left: " + retries); 218 247 if (cancel) 219 248 return false; // assume cancel 249 if (retries-- > 0) 250 startChangeset(retries, comment); 251 else 252 // throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 253 throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 254 } 255 256 catch (Exception e) { 257 if (cancel) 258 return false; // assume cancel 259 if (e instanceof OsmTransferException) 260 throw (OsmTransferException)e; 220 261 if (e instanceof RuntimeException) 221 262 throw (RuntimeException)e; … … 225 266 } 226 267 227 private void stopChangeset(int retries) {268 private void stopChangeset(int retries) throws OsmTransferException { 228 269 Main.pleaseWaitDlg.currentAction.setText(tr("Closing changeset...")); 229 270 try { … … 278 319 OsmWriter.output(o, changeset); 279 320 System.out.println(new String(o.toByteArray(), "UTF-8").toString()); 280 throw new RuntimeException(retCode+" "+retMsg); 321 //throw new RuntimeException(retCode+" "+retMsg); 322 throw new OsmTransferException(retCode+" "+retMsg); 281 323 } 282 324 } 283 325 } catch (UnknownHostException e) { 284 throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e); 326 //throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e); 327 throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e); 285 328 } catch(SocketTimeoutException e) { 286 329 System.out.println(" timed out, retries left: " + retries); … … 290 333 stopChangeset(retries); 291 334 else 292 throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 335 //throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 336 throw new OsmTransferException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 337 } catch(ConnectException e) { 338 System.out.println(" timed out, retries left: " + retries); 339 if (cancel) 340 return; // assume cancel 341 if (retries-- > 0) 342 stopChangeset(retries); 343 else 344 //throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 345 throw new OsmTransferException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 293 346 } catch (Exception e) { 294 347 if (cancel) 295 348 return; // assume cancel 349 if (e instanceof OsmTransferException) 350 throw (OsmTransferException)e; 296 351 if (e instanceof RuntimeException) 297 352 throw (RuntimeException)e; … … 361 416 */ 362 417 private void sendRequestRetry(String requestMethod, String urlSuffix, 363 OsmPrimitive osm, OsmWriterInterface body, int retries) {418 OsmPrimitive osm, OsmWriterInterface body, int retries) throws OsmTransferException { 364 419 try { 365 420 if (cancel) … … 371 426 urlSuffix + 372 427 "/" + (osm.id==0 ? "create" : osm.id), 373 (java.net.URLStreamHandler)new MyHttpHandler());428 new MyHttpHandler()); 374 429 System.out.print("upload to: "+url+ "..." ); 375 430 activeConnection = (HttpURLConnection)url.openConnection(); … … 421 476 OsmWriter.output(o, body); 422 477 System.out.println(new String(o.toByteArray(), "UTF-8").toString()); 423 throw new RuntimeException(retCode+" "+retMsg); 478 //throw new RuntimeException(retCode+" "+retMsg); 479 throw new OsmTransferException(retCode+" "+retMsg); 424 480 } 425 481 } 426 482 } catch (UnknownHostException e) { 427 throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e); 483 //throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e); 484 throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e); 428 485 } catch(SocketTimeoutException e) { 429 486 System.out.println(" timed out, retries left: " + retries); … … 433 490 sendRequestRetry(requestMethod, urlSuffix, osm, body, retries); 434 491 else 435 throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 492 //throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 493 throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 494 } catch(ConnectException e) { 495 System.out.println(" timed out, retries left: " + retries); 496 if (cancel) 497 return; // assume cancel 498 if (retries-- > 0) 499 sendRequestRetry(requestMethod, urlSuffix, osm, body, retries); 500 else 501 //throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 502 throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e); 436 503 } catch (Exception e) { 437 504 if (cancel) 438 505 return; // assume cancel 506 if (e instanceof OsmTransferException) 507 throw (OsmTransferException)e; 439 508 if (e instanceof RuntimeException) 440 509 throw (RuntimeException)e; … … 442 511 } 443 512 } 513 444 514 private void sendRequest(String requestMethod, String urlSuffix, 445 OsmPrimitive osm, boolean addBody) {515 OsmPrimitive osm, boolean addBody) { 446 516 XmlWriter.OsmWriterInterface body = null; 447 517 if (addBody) { 448 518 body = new OsmWriter.Single(osm, true, changeset); 449 519 } 450 sendRequestRetry(requestMethod, urlSuffix, osm, body, 10); 520 try { 521 sendRequestRetry(requestMethod, urlSuffix, osm, body, 10); 522 } 523 catch (OsmTransferException e) { 524 dealWithTransferException (e); 525 } 526 } 527 528 private void dealWithTransferException (OsmTransferException e) { 529 Main.pleaseWaitDlg.currentAction.setText(tr("Transfer aborted due to error (will wait now 5 seconds):") + e.getMessage()); 530 cancel = true; 531 try { 532 Thread.sleep(5000); 533 } 534 catch (InterruptedException ex) {} 451 535 } 452 536 }
Note:
See TracChangeset
for help on using the changeset viewer.