Changeset 8485 in josm
- Timestamp:
- 2015-06-11T00:31:44+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r8462 r8485 90 90 t.setName(name); 91 91 return t; 92 92 } 93 93 }; 94 94 } … … 319 319 } 320 320 321 HttpURLConnection urlConn = getURLConnection();321 URLConnection urlConn = getURLConnection(); 322 322 323 323 if (isObjectLoadable() && … … 328 328 urlConn.addRequestProperty("If-None-Match", attributes.getEtag()); 329 329 } 330 if ( urlConn.getResponseCode() == 304) {330 if (responseCode(urlConn) == 304) { 331 331 // If isModifiedSince or If-None-Match has been set 332 332 // and the server answers with a HTTP 304 = "Not Modified" … … 349 349 350 350 for (int i = 0; i < 5; ++i) { 351 if ( urlConn.getResponseCode() == 503) {351 if (responseCode(urlConn) == 503) { 352 352 Thread.sleep(5000+(new Random()).nextInt(5000)); 353 353 continue; 354 354 } 355 355 356 attributes.setResponseCode( urlConn.getResponseCode());356 attributes.setResponseCode(responseCode(urlConn)); 357 357 byte[] raw = read(urlConn); 358 358 359 if (isResponseLoadable(urlConn.getHeaderFields(), urlConn.getResponseCode(), raw)) {359 if (isResponseLoadable(urlConn.getHeaderFields(), responseCode(urlConn), raw)) { 360 360 // we need to check cacheEmpty, so for cases, when data is returned, but we want to store 361 361 // as empty (eg. empty tile images) to save some space … … 386 386 } catch (IOException e) { 387 387 log.log(Level.FINE, "JCS - IOExecption during communication with server for: {0}", getUrl()); 388 388 389 attributes.setResponseCode(499); // set dummy error code 389 390 boolean doCache = isResponseLoadable(null, 499, null) || cacheAsEmpty(); //generic 499 error code returned … … 448 449 } 449 450 450 private HttpURLConnection getURLConnection() throws IOException {451 HttpURLConnection urlConn = (HttpURLConnection)getUrl().openConnection();451 private URLConnection getURLConnection() throws IOException { 452 URLConnection urlConn = getUrl().openConnection(); 452 453 urlConn.setRequestProperty("Accept", "text/html, image/png, image/jpeg, image/gif, */*"); 453 454 urlConn.setReadTimeout(readTimeout); // 30 seconds read timeout … … 463 464 464 465 private boolean isCacheValidUsingHead() throws IOException { 465 HttpURLConnection urlConn = (HttpURLConnection) getUrl().openConnection(); 466 urlConn.setRequestMethod("HEAD"); 467 long lastModified = urlConn.getLastModified(); 468 return (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getRequestProperty("ETag"))) || 469 (lastModified != 0 && lastModified <= attributes.getLastModification()); 466 URLConnection urlConn = getUrl().openConnection(); 467 if(urlConn instanceof HttpURLConnection) { 468 ((HttpURLConnection)urlConn).setRequestMethod("HEAD"); 469 long lastModified = urlConn.getLastModified(); 470 return (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getRequestProperty("ETag"))) || 471 (lastModified != 0 && lastModified <= attributes.getLastModification()); 472 } 473 // for other URL connections, do not use HEAD requests for cache validation 474 return false; 470 475 } 471 476 … … 522 527 finishLoading(LoadResult.CANCELED); 523 528 } 529 530 /* 531 * Temporary fix for file URLs. Returns response code for HttpURLConnections or 200 for all other 532 */ 533 private int responseCode(URLConnection urlConn) throws IOException { 534 if (urlConn instanceof HttpURLConnection) { 535 return ((HttpURLConnection) urlConn).getResponseCode(); 536 } else { 537 return 200; 538 } 539 } 524 540 }
Note:
See TracChangeset
for help on using the changeset viewer.