Changeset 13274 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r13260 r13274 4 4 import java.awt.HeadlessException; 5 5 import java.io.IOException; 6 import java.io.InputStream; 6 7 import java.io.StringReader; 7 8 import java.io.StringWriter; … … 235 236 236 237 final Response response = HttpClient.create(getCapabilitiesUrl).connect(); 237 String incomingData = null;238 238 239 239 if (response.getResponseCode() >= 400) { … … 241 241 } 242 242 243 parseCapabilities(serviceUrlStr, response.getContent()); 244 } 245 246 void parseCapabilities(String serviceUrlStr, InputStream contentStream) throws IOException, WMSGetCapabilitiesException { 247 String incomingData = null; 243 248 try { 244 249 DocumentBuilder builder = Utils.newSafeDOMBuilder(); … … 247 252 return new InputSource(new StringReader("")); 248 253 }); 249 Document document = builder.parse( response.getContent());254 Document document = builder.parse(contentStream); 250 255 Element root = document.getDocumentElement(); 251 256 … … 369 374 getChildrenStream(element) 370 375 .filter(child -> "CRS".equals(child.getNodeName()) || "SRS".equals(child.getNodeName())) 371 .map(child -> (String)getContent(child))376 .map(child -> getContent(child)) 372 377 .filter(crs -> !crs.isEmpty()) 373 378 .map(crs -> crs.trim().toUpperCase(Locale.ENGLISH)) … … 421 426 return missing; 422 427 else { 423 String content = (String)getContent(child);428 String content = getContent(child); 424 429 return (!content.isEmpty()) ? content : empty; 425 430 } 426 431 } 427 432 428 private static ObjectgetContent(Element element) {433 private static String getContent(Element element) { 429 434 NodeList nl = element.getChildNodes(); 430 435 StringBuilder content = new StringBuilder(); … … 433 438 switch (node.getNodeType()) { 434 439 case Node.ELEMENT_NODE: 435 return node; 440 content.append(getContent((Element) node)); 441 break; 436 442 case Node.CDATA_SECTION_NODE: 437 443 case Node.TEXT_NODE: -
trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java
r11974 r13274 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertTrue; 6 7 import java.io.IOException; 8 import java.io.InputStream; 5 9 6 10 import org.junit.Rule; 7 11 import org.junit.Test; 12 import org.openstreetmap.josm.TestUtils; 8 13 import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException; 9 14 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 36 41 assertEquals("bar", exc.getIncomingData()); 37 42 } 43 44 /** 45 * Non-regression test for bug #15730. 46 * @throws IOException if any I/O error occurs 47 * @throws WMSGetCapabilitiesException never 48 */ 49 @Test 50 public void testTicket15730() throws IOException, WMSGetCapabilitiesException { 51 try (InputStream is = TestUtils.getRegressionDataStream(15730, "capabilities.xml")) { 52 WMSImagery wms = new WMSImagery(); 53 wms.parseCapabilities(null, is); 54 assertEquals(1, wms.getLayers().size()); 55 assertTrue(wms.getLayers().get(0).abstr.startsWith("South Carolina NAIP Imagery 2017 Resolution: 100CM ")); 56 } 57 } 38 58 }
Note:
See TracChangeset
for help on using the changeset viewer.