Changeset 19662 in josm
- Timestamp:
- 2026-10-24T13:43:40+02:00 (less than one hour ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java
r19651 r19662 2 2 package org.openstreetmap.josm.gui.preferences.server; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 8 9 import java.net.HttpURLConnection; 9 10 import java.net.MalformedURLException; 11 import java.net.URI; 10 12 import java.net.URL; 11 13 … … 38 40 private final Component parent; 39 41 private HttpClient connection; 42 43 private static final String CONNECTION_FAILED_MSG = marktr("Connection to API failed"); 40 44 41 45 /** … … 94 98 url 95 99 ), 96 tr( "Connection to API failed"),100 tr(CONNECTION_FAILED_MSG), 97 101 JOptionPane.ERROR_MESSAGE, 98 102 HelpUtil.ht("/Preferences/Connection#ConnectionToAPIFailed") … … 111 115 url 112 116 ), 113 tr( "Connection to API failed"),117 tr(CONNECTION_FAILED_MSG), 114 118 JOptionPane.ERROR_MESSAGE, 115 119 HelpUtil.ht("/Preferences/Connection#InvalidServerResult") … … 127 131 url 128 132 ), 129 tr( "Connection to API failed"),133 tr(CONNECTION_FAILED_MSG), 130 134 JOptionPane.ERROR_MESSAGE, 131 135 HelpUtil.ht("/Preferences/Connection#InvalidSettings") … … 152 156 try { 153 157 try { 154 new URL(url);155 } catch (MalformedURLException e) { 158 URI.create(url).toURL(); 159 } catch (IllegalArgumentException | MalformedURLException e) { 156 160 alertInvalidUrl(url); 157 161 return; 158 162 } 159 URL capabilitiesUrl; 160 String getCapabilitiesUrl = url + "/0.6/capabilities"; 163 final URL capabilitiesUrl; 164 final String getCapabilitiesUrl = url + "/0.6/capabilities"; 161 165 try { 162 capabilitiesUrl = new URL(getCapabilitiesUrl);163 } catch (MalformedURLException e) { 166 capabilitiesUrl = URI.create(getCapabilitiesUrl).toURL(); 167 } catch (IllegalArgumentException | MalformedURLException e) { 164 168 alertInvalidCapabilitiesUrl(getCapabilitiesUrl); 165 169 return; … … 171 175 } 172 176 173 if (connection.getResponse().getResponseCode() != HttpURLConnection.HTTP_OK) { 174 alertInvalidServerResult(connection.getResponse().getResponseCode()); 177 final int responseCode = connection.getResponse().getResponseCode(); 178 if (responseCode != HttpURLConnection.HTTP_OK) { 179 alertInvalidServerResult(responseCode ); 175 180 return; 176 181 } … … 185 190 success = true; 186 191 } catch (IOException e) { 187 if (canceled) 192 if (canceled) { 188 193 // ignore exceptions 189 194 return; 195 } 190 196 Logging.error(e); 191 197 alertConnectionFailed();
Note:
See TracChangeset
for help on using the changeset viewer.
