Changeset 7473 in josm for trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java
- Timestamp:
- 2014-08-31T01:30:58+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java
r7466 r7473 11 11 12 12 import javax.swing.JOptionPane; 13 import javax.xml.parsers.ParserConfigurationException; 13 14 14 15 import org.openstreetmap.josm.Main; … … 16 17 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 17 18 import org.openstreetmap.josm.gui.help.HelpUtil; 18 import org.openstreetmap.josm.io.IllegalDataException; 19 import org.openstreetmap.josm.io.OsmChangesetParser; 19 import org.openstreetmap.josm.io.Capabilities; 20 20 import org.openstreetmap.josm.io.OsmTransferException; 21 21 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 22 import org.openstreetmap.josm.tools.Utils; 23 import org.xml.sax.InputSource; 23 24 import org.xml.sax.SAXException; 24 25 25 26 /** 26 27 * 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 method28 * It tries to retrieve capabilities from the given URL. If it succeeds, the method 28 29 * {@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 also32 * to "https://x.y.y/api/0/capabilities" or "https://x.y.y/a/capabilities" with valid capabilities. If we get33 * valid capabilities with an URL we therefore can't be sure that the base URL is valid API URL.34 30 * @since 2745 35 31 */ … … 71 67 } 72 68 73 protected void alertInvalidC hangesetUrl(String url) {69 protected void alertInvalidCapabilitiesUrl(String url) { 74 70 HelpAwareOptionPane.showMessageDialogInEDT( 75 71 parent, … … 120 116 } 121 117 122 protected void alertInvalidC hangesetList() {118 protected void alertInvalidCapabilities() { 123 119 HelpAwareOptionPane.showMessageDialogInEDT( 124 120 parent, … … 150 146 151 147 /** 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 '/'. 154 149 * 155 150 * @return the normalized API URL … … 173 168 } 174 169 URL capabilitiesUrl; 175 String getC hangesetsUrl = getNormalizedApiUrl() + "/0.6/changesets";170 String getCapabilitiesUrl = getNormalizedApiUrl() + "/0.6/capabilities"; 176 171 try { 177 capabilitiesUrl = new URL(getC hangesetsUrl);172 capabilitiesUrl = new URL(getCapabilitiesUrl); 178 173 } catch(MalformedURLException e) { 179 alertInvalidC hangesetUrl(getChangesetsUrl);174 alertInvalidCapabilitiesUrl(getCapabilitiesUrl); 180 175 return; 181 176 } … … 195 190 196 191 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; 206 197 } 207 198 success = true;
Note:
See TracChangeset
for help on using the changeset viewer.