Changeset 14311 in josm
- Timestamp:
- 2018-10-09T20:04:07+02:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r14273 r14311 360 360 String data = urlConn.fetchContent(); 361 361 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); 365 365 } 366 366 } … … 418 418 Logging.warn("JCS - Silent failure during download: {0}", getUrlNoException()); 419 419 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; 420 425 } 421 426 -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r14270 r14311 50 50 public static final LongProperty MINIMUM_EXPIRES = new LongProperty("imagery.generic.minimum_expires", TimeUnit.HOURS.toMillis(1)); 51 51 static final Pattern SERVICE_EXCEPTION_PATTERN = Pattern.compile("(?s).+<ServiceException[^>]*>(.+)</ServiceException>.+"); 52 static final Pattern CDATA_PATTERN = Pattern.compile("(?s)\\s*<!\\[CDATA\\[(.+)\\]\\]>\\s*"); 52 53 protected final Tile tile; 53 54 private volatile URL url; … … 318 319 return true; 319 320 } 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 } 320 332 } -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r14288 r14311 1167 1167 1168 1168 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); 1170 1174 //texty += 1 + fontHeight; 1171 1175 } -
trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java
r13742 r14311 14 14 import java.util.concurrent.TimeUnit; 15 15 import java.util.regex.Matcher; 16 import java.util.regex.Pattern; 16 17 17 18 import org.apache.commons.jcs.access.behavior.ICacheAccess; … … 145 146 @Test 146 147 public void testServiceExceptionPattern() { 147 test("missing parameters ['version', 'format']", 148 testServiceException("missing parameters ['version', 'format']", 148 149 "<?xml version=\"1.0\"?>\n" + 149 150 "<!DOCTYPE ServiceExceptionReport SYSTEM \"http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd\">\n" + … … 151 152 " <ServiceException>missing parameters ['version', 'format']</ServiceException>\n" + 152 153 "</ServiceExceptionReport>"); 153 test("Parameter 'layers' contains unacceptable layer names.", 154 testServiceException("Parameter 'layers' contains unacceptable layer names.", 154 155 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\r\n" + 155 156 "<!DOCTYPE ServiceExceptionReport SYSTEM \"http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd\">\r\n" + … … 162 163 } 163 164 164 private static void test(String expected, String xml) { 165 Matcher m = TMSCachedTileLoaderJob.SERVICE_EXCEPTION_PATTERN.matcher(xml); 165 /** 166 * Tests that {@code TMSCachedTileLoaderJob#CDATA_PATTERN} is correct. 167 */ 168 @Test 169 public void testCdataPattern() { 170 testCdata("received unsuitable wms request: no <grid> with suitable srs found for layer capitais", 171 "<![CDATA[\r\n" + 172 "received unsuitable wms request: no <grid> with suitable srs found for layer capitais\r\n" + 173 "]]>"); 174 } 175 176 private static void testServiceException(String expected, String xml) { 177 test(TMSCachedTileLoaderJob.SERVICE_EXCEPTION_PATTERN, expected, xml); 178 } 179 180 private static void testCdata(String expected, String xml) { 181 test(TMSCachedTileLoaderJob.CDATA_PATTERN, expected, xml); 182 } 183 184 private static void test(Pattern pattern, String expected, String xml) { 185 Matcher m = pattern.matcher(xml); 166 186 assertTrue(xml, m.matches()); 167 187 assertEquals(expected, Utils.strip(m.group(1)));
Note:
See TracChangeset
for help on using the changeset viewer.