Changeset 8389 in josm


Ignore:
Timestamp:
2015-05-17T22:48:00+02:00 (9 years ago)
Author:
wiktorn
Message:

addresses #11437 - properly pass information about errors during load from cache to upper layers

Location:
trunk/src/org/openstreetmap/josm/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/CacheEntryAttributes.java

    r8318 r8389  
    2020    private static final String LAST_MODIFICATION = "lastModification";
    2121    private static final String EXPIRATION_TIME = "expirationTime";
     22    private static final String HTTP_RESPONSE_CODE = "httpResponceCode";
    2223
    2324    /**
     
    3031        attrs.put(LAST_MODIFICATION, "0");
    3132        attrs.put(EXPIRATION_TIME, "0");
     33        attrs.put(HTTP_RESPONSE_CODE, "200");
    3234    }
    3335
     
    4648
    4749    private long getLongAttr(String key) {
     50        String val = attrs.get(key);
     51        if (val == null) {
     52            attrs.put(key,  "0");
     53            return 0;
     54        }
    4855        try {
    49             return Long.parseLong(attrs.get(key));
     56            return Long.parseLong(val);
    5057        } catch (NumberFormatException e) {
    5158            attrs.put(key, "0");
     
    6774    }
    6875
     76    public void setResponseCode(int responseCode) {
     77        attrs.put(HTTP_RESPONSE_CODE, Integer.toString(responseCode));
     78    }
     79
     80    public int getResponseCode() {
     81        return (int) getLongAttr(HTTP_RESPONSE_CODE);
     82    }
     83
    6984}
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r8345 r8389  
    364364                    continue;
    365365                }
     366
     367                attributes.setResponseCode(urlConn.getResponseCode());
    366368                byte[] raw = read(urlConn);
    367369
    368370                if (!cacheAsEmpty(urlConn.getHeaderFields(), urlConn.getResponseCode(), raw) &&
    369371                        raw != null && raw.length > 0) {
     372                    // we need to check cacheEmpty, so for cases, when data is returned, but we want to store
     373                    // as empty (eg. empty tile images) to save some space
    370374                    cacheData = createCacheEntry(raw);
    371375                    cache.put(getCacheKey(), cacheData, attributes);
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r8344 r8389  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.imagery;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.io.ByteArrayInputStream;
     
    273275                        }
    274276                    }
     277                    int httpStatusCode = attributes.getResponseCode();
     278                    if (!isNoTileAtZoom() && httpStatusCode >= 400) {
     279                        tile.setError(tr("HTTP error {0} when loading tiles", httpStatusCode));
     280                    }
    275281                    // no break intentional here
    276282                case REJECTED:
     
    313319                    tile.finishLoading();
    314320                }
     321                if (attributes.getResponseCode() >= 400) {
     322                    tile.setError(tr("HTTP error {0} when loading tiles", attributes.getResponseCode()));
     323                }
    315324                return tile;
    316325            } catch (IOException e) {
Note: See TracChangeset for help on using the changeset viewer.