Changeset 8606 in josm
- Timestamp:
- 2015-07-16T21:13:12+02:00 (10 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/org/openstreetmap/josm/data/cache/CacheEntryAttributes.java ¶
r8510 r8606 28 28 private static final String EXPIRATION_TIME = "expirationTime"; 29 29 private static final String HTTP_RESPONSE_CODE = "httpResponceCode"; 30 private static final String ERROR_MESSAGE = "errorMessage"; 30 31 // this contains all of the above 31 32 private static final Set<String> RESERVED_KEYS = new HashSet<>(Arrays.asList(new String[]{ … … 34 35 LAST_MODIFICATION, 35 36 EXPIRATION_TIME, 36 HTTP_RESPONSE_CODE 37 HTTP_RESPONSE_CODE, 38 ERROR_MESSAGE 37 39 })); 40 38 41 39 42 /** … … 176 179 return Collections.unmodifiableMap(attrs); 177 180 } 181 182 /** 183 * @return error message returned while retrieving this object 184 */ 185 public String getErrorMessage() { 186 return attrs.get(ERROR_MESSAGE); 187 } 188 189 /** 190 * @param message error message related to this object 191 */ 192 public void setErrorMessage(String message) { 193 attrs.put(ERROR_MESSAGE, message); 194 } 178 195 } -
TabularUnified trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java ¶
r8604 r8606 369 369 log.log(Level.FINE, "JCS - Caching empty object as server returned 404 for: {0}", getUrl()); 370 370 attributes.setResponseCode(404); 371 attributes.setErrorMessage(e.toString()); 371 372 boolean doCache = isResponseLoadable(null, 404, null) || cacheAsEmpty(); 372 373 if (doCache) { … … 377 378 } catch (IOException e) { 378 379 log.log(Level.FINE, "JCS - IOExecption during communication with server for: {0}", getUrl()); 379 380 attributes.setErrorMessage(e.toString()); 380 381 attributes.setResponseCode(499); // set dummy error code 381 382 boolean doCache = isResponseLoadable(null, 499, null) || cacheAsEmpty(); //generic 499 error code returned … … 386 387 return doCache; 387 388 } catch (Exception e) { 389 attributes.setErrorMessage(e.toString()); 388 390 log.log(Level.WARNING, "JCS - Exception during download {0}", getUrl()); 389 391 Main.warn(e); -
TabularUnified trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java ¶
r8598 r8606 188 188 } 189 189 int httpStatusCode = attributes.getResponseCode(); 190 if (!isNoTileAtZoom() && httpStatusCode >= 400) { 191 tile.setError(tr("HTTP error {0} when loading tiles", httpStatusCode)); 190 if (!isNoTileAtZoom() && httpStatusCode >= 400 && httpStatusCode != 499) { 191 if (attributes.getErrorMessage() == null) { 192 tile.setError(tr("HTTP error {0} when loading tiles", httpStatusCode)); 193 } else { 194 tile.setError(tr("Error downloading tiles: {0}", attributes.getErrorMessage())); 195 } 192 196 status = false; 193 197 } … … 209 213 } catch (IOException e) { 210 214 LOG.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()}); 211 tile.setError(e. getMessage());215 tile.setError(e.toString()); 212 216 tile.setLoaded(false); 213 217 if (listeners != null) { // listeners might be null, if some other thread notified already about success … … 285 289 tile.finishLoading(); 286 290 } 287 if (attributes.get ResponseCode() >= 400) {291 if (attributes.getErrorMessage() == null) { 288 292 tile.setError(tr("HTTP error {0} when loading tiles", attributes.getResponseCode())); 293 } else { 294 tile.setError(tr("Error downloading tiles: {0}", attributes.getErrorMessage())); 289 295 } 290 296 return tile; -
TabularUnified trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java ¶
r8604 r8606 15 15 public class JCSCachedTileLoaderJobTest { 16 16 private static class TestCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, CacheEntry> { 17 private String url; 17 18 18 private int responseCode; 19 20 public TestCachedTileLoaderJob(int responseCode) throws IOException { 19 public TestCachedTileLoaderJob(String url) throws IOException { 21 20 super(getCache(), 30000, 30000, null); 22 this. responseCode = responseCode;21 this.url = url; 23 22 } 24 23 … … 35 34 public URL getUrl() { 36 35 try { 37 return new URL( "http://httpstat.us/" + Integer.toString(responseCode));36 return new URL(url); 38 37 } catch (MalformedURLException e) { 39 38 throw new RuntimeException(e); … … 86 85 } 87 86 87 @Test 88 public void testUnkownHost() throws Exception { 89 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown"); 90 Listener listener = new Listener(); 91 job.submit(listener, true); 92 synchronized (listener) { 93 if (!listener.ready) { 94 listener.wait(); 95 } 96 } 97 assertEquals("java.net.UnknownHostException: unkownhost.unkownhost", listener.attributes.getErrorMessage()); 98 } 99 88 100 public void testStatusCode(int responseCode) throws Exception { 89 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(responseCode);101 TestCachedTileLoaderJob job = getStatusLoaderJob(responseCode); 90 102 Listener listener = new Listener(); 91 103 job.submit(listener, true); … … 98 110 99 111 } 112 113 private static TestCachedTileLoaderJob getStatusLoaderJob(int responseCode) throws IOException { 114 return new TestCachedTileLoaderJob("http://httpstat.us/" + responseCode); 115 } 116 100 117 } 101 118
Note:
See TracChangeset
for help on using the changeset viewer.