Ignore:
Timestamp:
2014-08-31T01:30:58+02:00 (10 years ago)
Author:
Don-vip
Message:

see #10441 - send capabilities request instead of changesets request when testing API url

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java

    r7466 r7473  
    1111
    1212import javax.swing.JOptionPane;
     13import javax.xml.parsers.ParserConfigurationException;
    1314
    1415import org.openstreetmap.josm.Main;
     
    1617import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1718import org.openstreetmap.josm.gui.help.HelpUtil;
    18 import org.openstreetmap.josm.io.IllegalDataException;
    19 import org.openstreetmap.josm.io.OsmChangesetParser;
     19import org.openstreetmap.josm.io.Capabilities;
    2020import org.openstreetmap.josm.io.OsmTransferException;
    2121import org.openstreetmap.josm.tools.CheckParameterUtil;
    2222import org.openstreetmap.josm.tools.Utils;
     23import org.xml.sax.InputSource;
    2324import org.xml.sax.SAXException;
    2425
    2526/**
    2627 * This is an asynchronous task for testing whether an URL points to an OSM API server.
    27  * It tries to retrieve a list of changesets from the given URL. If it succeeds, the method
     28 * It tries to retrieve capabilities from the given URL. If it succeeds, the method
    2829 * {@link #isSuccess()} replies true, otherwise false.
    29  *
    30  * Note: it fetches a list of changesets instead of the much smaller capabilities because - strangely enough -
    31  * an OSM server "https://x.y.y/api/0.6" not only responds to  "https://x.y.y/api/0.6/capabilities" but also
    32  * to "https://x.y.y/api/0/capabilities" or "https://x.y.y/a/capabilities" with valid capabilities. If we get
    33  * valid capabilities with an URL we therefore can't be sure that the base URL is valid API URL.
    3430 * @since 2745
    3531 */
     
    7167    }
    7268
    73     protected void alertInvalidChangesetUrl(String url) {
     69    protected void alertInvalidCapabilitiesUrl(String url) {
    7470        HelpAwareOptionPane.showMessageDialogInEDT(
    7571                parent,
     
    120116    }
    121117
    122     protected void alertInvalidChangesetList() {
     118    protected void alertInvalidCapabilities() {
    123119        HelpAwareOptionPane.showMessageDialogInEDT(
    124120                parent,
     
    150146
    151147    /**
    152      * Removes leading and trailing whitespace from the API URL and removes trailing
    153      * '/'.
     148     * Removes leading and trailing whitespace from the API URL and removes trailing '/'.
    154149     *
    155150     * @return the normalized API URL
     
    173168            }
    174169            URL capabilitiesUrl;
    175             String getChangesetsUrl = getNormalizedApiUrl() + "/0.6/changesets";
     170            String getCapabilitiesUrl = getNormalizedApiUrl() + "/0.6/capabilities";
    176171            try {
    177                 capabilitiesUrl = new URL(getChangesetsUrl);
     172                capabilitiesUrl = new URL(getCapabilitiesUrl);
    178173            } catch(MalformedURLException e) {
    179                 alertInvalidChangesetUrl(getChangesetsUrl);
     174                alertInvalidCapabilitiesUrl(getCapabilitiesUrl);
    180175                return;
    181176            }
     
    195190
    196191            try {
    197                 OsmChangesetParser.parse(connection.getInputStream(), progressMonitor.createSubTaskMonitor(1, true));
    198             } catch (IllegalDataException e) {
    199                 if (e.getCause() instanceof IOException) {
    200                     throw (IOException) e.getCause();
    201                 } else {
    202                     Main.warn(e.getMessage());
    203                     alertInvalidChangesetList();
    204                     return;
    205                 }
     192                Capabilities.CapabilitiesParser.parse(new InputSource(connection.getInputStream()));
     193            } catch (SAXException | ParserConfigurationException e) {
     194                Main.warn(e.getMessage());
     195                alertInvalidCapabilities();
     196                return;
    206197            }
    207198            success = true;
Note: See TracChangeset for help on using the changeset viewer.