Changeset 2035 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-09-03T13:02:19+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2025 r2035 157 157 * @exception OsmApiInitializationException thrown, if an exception occurs 158 158 */ 159 public void initialize() throws OsmApiInitializationException { 159 public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException { 160 160 if (initialized) 161 161 return; 162 162 initAuthentication(); 163 163 try { 164 String s = sendRequest("GET", "capabilities", null); 164 String s = sendRequest("GET", "capabilities", null,monitor); 165 165 InputSource inputSource = new InputSource(new StringReader(s)); 166 166 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser()); … … 227 227 * @throws OsmTransferException if something goes wrong 228 228 */ 229 public void createPrimitive(OsmPrimitive osm) throws OsmTransferException { 230 initialize(); 229 public void createPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 230 initialize(monitor); 231 231 String ret = ""; 232 232 try { 233 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true)); 233 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true),monitor); 234 234 osm.id = Long.parseLong(ret.trim()); 235 235 osm.version = 1; … … 247 247 * @throws OsmTransferException if something goes wrong 248 248 */ 249 public void modifyPrimitive(OsmPrimitive osm) throws OsmTransferException { 250 initialize(); 249 public void modifyPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 250 initialize(monitor); 251 251 if (version.equals("0.5")) { 252 252 // legacy mode does not return the new object version. 253 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true)); 253 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true),monitor); 254 254 } else { 255 255 String ret = null; 256 256 // normal mode (0.6 and up) returns new object version. 257 257 try { 258 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true)); 258 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor); 259 259 osm.version = Integer.parseInt(ret.trim()); 260 260 } catch(NumberFormatException e) { … … 270 270 */ 271 271 public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 272 initialize(); 272 initialize(monitor); 273 273 // can't use a the individual DELETE method in the 0.6 API. Java doesn't allow 274 274 // submitting a DELETE request with content, the 0.6 API requires it, however. Falling back … … 291 291 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 292 292 changeset.put("comment", comment); 293 createPrimitive(changeset); 293 createPrimitive(changeset, progressMonitor); 294 294 } finally { 295 295 progressMonitor.finishTask(); … … 305 305 progressMonitor.beginTask(tr("Closing changeset {0}...", changeset.getId())); 306 306 try { 307 initialize(); 308 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null); 307 initialize(progressMonitor); 308 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor); 309 309 changeset = null; 310 310 } finally { … … 327 327 throw new OsmTransferException(tr("No changeset present for diff upload")); 328 328 329 initialize(); 329 initialize(progressMonitor); 330 330 final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>(); 331 331 … … 341 341 String diff = duv.getDocument(); 342 342 try { 343 String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff); 343 String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff,progressMonitor); 344 344 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), 345 345 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); … … 358 358 359 359 360 private void sleepAndListen() throws OsmTransferCancelledException { 360 private void sleepAndListen(int retry, ProgressMonitor monitor) throws OsmTransferCancelledException { 361 361 System.out.print(tr("Waiting 10 seconds ... ")); 362 362 for(int i=0; i < 10; i++) { 363 if (monitor != null) { 364 monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry,getMaxRetries(), 10-i)); 365 } 363 366 if (cancel || isAuthCancelled()) 364 367 throw new OsmTransferCancelledException(); … … 395 398 * been exhausted), or rewrapping a Java exception. 396 399 */ 397 private String sendRequest(String requestMethod, String urlSuffix, 398 String requestBody) throws OsmTransferException { 400 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException { 399 401 400 402 StringBuffer responseBody = new StringBuffer(); … … 436 438 if (retCode >= 500) { 437 439 if (retries-- > 0) { 438 sleepAndListen(); 439 int maxRetries = getMaxRetries(); 440 System.out.println(tr("Starting retry {0} of {1}.", maxRetries - retries,maxRetries)); 440 sleepAndListen(retries, monitor); 441 System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries,getMaxRetries())); 441 442 continue; 442 443 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r1875 r2035 40 40 protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 41 41 try { 42 api.initialize(); 42 api.initialize(progressMonitor); 43 43 urlStr = api.getBaseUrl() + urlStr; 44 44 return getInputStreamRaw(urlStr, progressMonitor); -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r2025 r2035 125 125 } 126 126 } catch(Exception e) { 127 Changeset changeset = api.getCurrentChangeset(); 128 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.getId())); 129 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}", 130 changesetId, e.toString())); 127 OsmChangesetCloseException closeException = new OsmChangesetCloseException(e); 128 closeException.setChangeset(api.getCurrentChangeset()); 129 throw closeException; 131 130 } 132 131 } … … 154 153 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 155 154 } catch (Exception ee) { 156 Changeset changeset = api.getCurrentChangeset(); 157 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.getId())); 158 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}", 159 changesetId, ee.toString())); 155 OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee); 156 closeException.setChangeset(api.getCurrentChangeset()); 157 throw closeException; 160 158 } 161 159 } … … 171 169 processed = new LinkedList<OsmPrimitive>(); 172 170 173 api.initialize(); 171 api.initialize(progressMonitor); 174 172 175 173 try { … … 199 197 api.deletePrimitive(osm, progressMonitor); 200 198 } else if (osm.getId() == 0) { 201 api.createPrimitive(osm); 199 api.createPrimitive(osm, progressMonitor); 202 200 } else { 203 api.modifyPrimitive(osm); 201 api.modifyPrimitive(osm,progressMonitor); 204 202 } 205 203 }
Note:
See TracChangeset
for help on using the changeset viewer.