Ticket #11548: HttpURL.patch

File HttpURL.patch, 2.5 KB (added by akks, 9 years ago)
  • src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

     
    318318                return true;
    319319            }
    320320
    321             HttpURLConnection urlConn = getURLConnection();
     321            URLConnection urlConn = getURLConnection();
    322322
    323323            if (isObjectLoadable()  &&
    324324                    (now - attributes.getLastModification()) <= ABSOLUTE_EXPIRE_TIME_LIMIT) {
     
    327327            if (isObjectLoadable() && attributes.getEtag() != null) {
    328328                urlConn.addRequestProperty("If-None-Match", attributes.getEtag());
    329329            }
    330             if (urlConn.getResponseCode() == 304) {
     330            if (responseCode(urlConn) == 304) {
    331331                // If isModifiedSince or If-None-Match has been set
    332332                // and the server answers with a HTTP 304 = "Not Modified"
    333333                log.log(Level.FINE, "JCS - IfModifiedSince/Etag test: local version is up to date: {0}", getUrl());
     
    348348            attributes = parseHeaders(urlConn);
    349349
    350350            for (int i = 0; i < 5; ++i) {
    351                 if (urlConn.getResponseCode() == 503) {
     351                if (responseCode(urlConn) == 503) {
    352352                    Thread.sleep(5000+(new Random()).nextInt(5000));
    353353                    continue;
    354354                }
    355355
    356                 attributes.setResponseCode(urlConn.getResponseCode());
     356                attributes.setResponseCode(responseCode(urlConn));
    357357                byte[] raw = read(urlConn);
    358358
    359                 if (isResponseLoadable(urlConn.getHeaderFields(), urlConn.getResponseCode(), raw)) {
     359                if (isResponseLoadable(urlConn.getHeaderFields(), responseCode(urlConn), raw)) {
    360360                    // we need to check cacheEmpty, so for cases, when data is returned, but we want to store
    361361                    // as empty (eg. empty tile images) to save some space
    362362                    cacheData = createCacheEntry(raw);
     
    521521    public void handleJobCancellation() {
    522522        finishLoading(LoadResult.CANCELED);
    523523    }
     524
     525    private int responseCode(URLConnection urlConn) throws IOException {
     526        if (urlConn instanceof HttpURLConnection) {
     527            return ((HttpURLConnection) urlConn).getResponseCode();
     528        } else {
     529            return 500;
     530        }
     531    }
    524532}