### Eclipse Workspace Patch 1.0
#P josm
diff --git src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java
index 9681092..ab63828 100644
|
|
|
|
| 7 | 7 | import java.io.IOException; |
| 8 | 8 | import java.net.HttpURLConnection; |
| 9 | 9 | import java.net.MalformedURLException; |
| | 10 | import java.net.URI; |
| 10 | 11 | import java.net.URL; |
| 11 | 12 | |
| 12 | 13 | import javax.swing.JOptionPane; |
| … |
… |
|
| 37 | 38 | private boolean success; |
| 38 | 39 | private final Component parent; |
| 39 | 40 | private HttpClient connection; |
| | 41 | |
| | 42 | private static final String CONNECTION_FAILED_MSG = "Connection to API failed"; |
| 40 | 43 | |
| 41 | 44 | /** |
| 42 | 45 | * Constructs a new {@code ApiUrlTestTask}. |
| … |
… |
|
| 93 | 96 | url, |
| 94 | 97 | url |
| 95 | 98 | ), |
| 96 | | tr("Connection to API failed"), |
| | 99 | tr(CONNECTION_FAILED_MSG), |
| 97 | 100 | JOptionPane.ERROR_MESSAGE, |
| 98 | 101 | HelpUtil.ht("/Preferences/Connection#ConnectionToAPIFailed") |
| 99 | 102 | ); |
| … |
… |
|
| 110 | 113 | retCode, |
| 111 | 114 | url |
| 112 | 115 | ), |
| 113 | | tr("Connection to API failed"), |
| | 116 | tr(CONNECTION_FAILED_MSG), |
| 114 | 117 | JOptionPane.ERROR_MESSAGE, |
| 115 | 118 | HelpUtil.ht("/Preferences/Connection#InvalidServerResult") |
| 116 | 119 | ); |
| … |
… |
|
| 126 | 129 | + "</html>", |
| 127 | 130 | url |
| 128 | 131 | ), |
| 129 | | tr("Connection to API failed"), |
| | 132 | tr(CONNECTION_FAILED_MSG), |
| 130 | 133 | JOptionPane.ERROR_MESSAGE, |
| 131 | 134 | HelpUtil.ht("/Preferences/Connection#InvalidSettings") |
| 132 | 135 | ); |
| … |
… |
|
| 151 | 154 | protected void realRun() throws SAXException, IOException, OsmTransferException { |
| 152 | 155 | try { |
| 153 | 156 | try { |
| 154 | | new URL(url); |
| 155 | | } catch (MalformedURLException e) { |
| | 157 | URI.create(url).toURL(); |
| | 158 | } catch (IllegalArgumentException | MalformedURLException e) { |
| 156 | 159 | alertInvalidUrl(url); |
| 157 | 160 | return; |
| 158 | 161 | } |
| 159 | | URL capabilitiesUrl; |
| 160 | | String getCapabilitiesUrl = url + "/0.6/capabilities"; |
| | 162 | final URL capabilitiesUrl; |
| | 163 | final String getCapabilitiesUrl = url + "/0.6/capabilities"; |
| 161 | 164 | try { |
| 162 | | capabilitiesUrl = new URL(getCapabilitiesUrl); |
| 163 | | } catch (MalformedURLException e) { |
| | 165 | capabilitiesUrl = URI.create(getCapabilitiesUrl).toURL(); |
| | 166 | } catch (IllegalArgumentException | MalformedURLException e) { |
| 164 | 167 | alertInvalidCapabilitiesUrl(getCapabilitiesUrl); |
| 165 | 168 | return; |
| 166 | 169 | } |
| … |
… |
|
| 170 | 173 | connection.connect(); |
| 171 | 174 | } |
| 172 | 175 | |
| 173 | | if (connection.getResponse().getResponseCode() != HttpURLConnection.HTTP_OK) { |
| 174 | | alertInvalidServerResult(connection.getResponse().getResponseCode()); |
| | 176 | final int responseCode = connection.getResponse().getResponseCode(); |
| | 177 | if (responseCode != HttpURLConnection.HTTP_OK) { |
| | 178 | alertInvalidServerResult(responseCode ); |
| 175 | 179 | return; |
| 176 | 180 | } |
| 177 | 181 | |
| … |
… |
|
| 184 | 188 | } |
| 185 | 189 | success = true; |
| 186 | 190 | } catch (IOException e) { |
| 187 | | if (canceled) |
| 188 | | // ignore exceptions |
| | 191 | if (canceled) { |
| | 192 | // ignore exceptions |
| 189 | 193 | return; |
| | 194 | } |
| 190 | 195 | Logging.error(e); |
| 191 | 196 | alertConnectionFailed(); |
| 192 | 197 | } |