Ignore:
Timestamp:
2018-02-22T20:40:18+01:00 (6 years ago)
Author:
Don-vip
Message:

see #15992 - display and log ServiceException error messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r13029 r13449  
    77import java.io.IOException;
    88import java.net.URL;
     9import java.nio.charset.StandardCharsets;
    910import java.util.HashSet;
    1011import java.util.List;
     
    1718import java.util.concurrent.ThreadPoolExecutor;
    1819import java.util.concurrent.TimeUnit;
     20import java.util.regex.Matcher;
     21import java.util.regex.Pattern;
    1922
    2023import org.apache.commons.jcs.access.behavior.ICacheAccess;
     
    4245    private static final LongProperty MAXIMUM_EXPIRES = new LongProperty("imagery.generic.maximum_expires", TimeUnit.DAYS.toMillis(30));
    4346    private static final LongProperty MINIMUM_EXPIRES = new LongProperty("imagery.generic.minimum_expires", TimeUnit.HOURS.toMillis(1));
     47    private static final Pattern SERVICE_EXCEPTION_PATTERN = Pattern.compile("(?s).+<ServiceException>(.+)</ServiceException>.+");
    4448    protected final Tile tile;
    4549    private volatile URL url;
     
    270274            byte[] content = object.getContent();
    271275            if (content.length > 0) {
    272                 try {
    273                     tile.loadImage(new ByteArrayInputStream(content));
     276                try (ByteArrayInputStream in = new ByteArrayInputStream(content)) {
     277                    tile.loadImage(in);
     278                    if (tile.getImage() == null) {
     279                        String s = new String(content, StandardCharsets.UTF_8);
     280                        Matcher m = SERVICE_EXCEPTION_PATTERN.matcher(s);
     281                        if (m.matches()) {
     282                            tile.setError(m.group(1));
     283                            Logging.error(m.group(1));
     284                            Logging.debug(s);
     285                        } else {
     286                            tile.setError(tr("Could not load image from tile server"));
     287                        }
     288                        return false;
     289                    }
    274290                } catch (UnsatisfiedLinkError e) {
    275291                    throw new IOException(e);
    276292                }
    277                 if (tile.getImage() == null) {
    278                     tile.setError(tr("Could not load image from tile server"));
    279                     return false;
    280                 }
    281293            }
    282294        }
Note: See TracChangeset for help on using the changeset viewer.