Changeset 13260 in josm


Ignore:
Timestamp:
2017-12-29T16:18:37+01:00 (7 years ago)
Author:
Don-vip
Message:

Correctly handle WMS capabilities encoding. Do not assume every server replies in UTF-8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r13228 r13260  
    55import java.io.IOException;
    66import java.io.StringReader;
     7import java.io.StringWriter;
    78import java.net.MalformedURLException;
    89import java.net.URL;
     
    2425import javax.xml.parsers.DocumentBuilder;
    2526import javax.xml.parsers.ParserConfigurationException;
     27import javax.xml.transform.TransformerException;
     28import javax.xml.transform.TransformerFactory;
     29import javax.xml.transform.TransformerFactoryConfigurationError;
     30import javax.xml.transform.dom.DOMSource;
     31import javax.xml.transform.stream.StreamResult;
    2632
    2733import org.openstreetmap.josm.data.Bounds;
     
    229235
    230236        final Response response = HttpClient.create(getCapabilitiesUrl).connect();
    231         final String incomingData = response.fetchContent();
    232         Logging.debug("Server response to Capabilities request:");
    233         Logging.debug(incomingData);
     237        String incomingData = null;
    234238
    235239        if (response.getResponseCode() >= 400) {
    236             throw new WMSGetCapabilitiesException(response.getResponseMessage(), incomingData);
     240            throw new WMSGetCapabilitiesException(response.getResponseMessage(), response.fetchContent());
    237241        }
    238242
     
    243247                return new InputSource(new StringReader(""));
    244248            });
    245             Document document = builder.parse(new InputSource(new StringReader(incomingData)));
     249            Document document = builder.parse(response.getContent());
    246250            Element root = document.getDocumentElement();
     251
     252            try {
     253                StringWriter writer = new StringWriter();
     254                TransformerFactory.newInstance().newTransformer().transform(new DOMSource(document), new StreamResult(writer));
     255                incomingData = writer.getBuffer().toString();
     256                Logging.debug("Server response to Capabilities request:");
     257                Logging.debug(incomingData);
     258            } catch (TransformerFactoryConfigurationError | TransformerException e) {
     259                Logging.warn(e);
     260            }
    247261
    248262            // Check if the request resulted in ServiceException
Note: See TracChangeset for help on using the changeset viewer.