Changeset 14311 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2018-10-09T20:04:07+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16824 - better display of WMS errors

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

Legend:

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

    r14273 r14311  
    360360                        String data = urlConn.fetchContent();
    361361                        if (!data.isEmpty()) {
    362                             Matcher m = HttpClient.getTomcatErrorMatcher(data);
    363                             if (m.matches()) {
    364                                 attributes.setErrorMessage(m.group(1).replace("'", "''"));
     362                            String detectErrorMessage = detectErrorMessage(data);
     363                            if (detectErrorMessage != null) {
     364                                attributes.setErrorMessage(detectErrorMessage);
    365365                            }
    366366                        }
     
    418418        Logging.warn("JCS - Silent failure during download: {0}", getUrlNoException());
    419419        return false;
     420    }
     421
     422    protected String detectErrorMessage(String data) {
     423        Matcher m = HttpClient.getTomcatErrorMatcher(data);
     424        return m.matches() ? m.group(1).replace("'", "''") : null;
    420425    }
    421426
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r14270 r14311  
    5050    public static final LongProperty MINIMUM_EXPIRES = new LongProperty("imagery.generic.minimum_expires", TimeUnit.HOURS.toMillis(1));
    5151    static final Pattern SERVICE_EXCEPTION_PATTERN = Pattern.compile("(?s).+<ServiceException[^>]*>(.+)</ServiceException>.+");
     52    static final Pattern CDATA_PATTERN = Pattern.compile("(?s)\\s*<!\\[CDATA\\[(.+)\\]\\]>\\s*");
    5253    protected final Tile tile;
    5354    private volatile URL url;
     
    318319        return true;
    319320    }
     321
     322    @Override
     323    protected String detectErrorMessage(String data) {
     324        Matcher m = SERVICE_EXCEPTION_PATTERN.matcher(data);
     325        return m.matches() ? removeCdata(Utils.strip(m.group(1))) : super.detectErrorMessage(data);
     326    }
     327
     328    private static String removeCdata(String msg) {
     329        Matcher m = CDATA_PATTERN.matcher(msg);
     330        return m.matches() ? Utils.strip(m.group(1)) : msg;
     331    }
    320332}
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r14288 r14311  
    11671167
    11681168        if (tile.hasError() && getDisplaySettings().isShowErrors()) {
    1169             myDrawString(g, tr("Error") + ": " + tr(tile.getErrorMessage()), x + 2, texty);
     1169            String errorMessage = tr(tile.getErrorMessage());
     1170            if (errorMessage != null && !errorMessage.startsWith("Error") && !errorMessage.startsWith(tr("Error"))) {
     1171                errorMessage = tr("Error") + ": " + errorMessage;
     1172            }
     1173            myDrawString(g, errorMessage, x + 2, texty);
    11701174            //texty += 1 + fontHeight;
    11711175        }
Note: See TracChangeset for help on using the changeset viewer.