### Eclipse Workspace Patch 1.0
#P josm
diff --git src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java
index ba6938d..0b84320 100644
|
|
|
|
| 6 | 6 | import java.awt.Component; |
| 7 | 7 | import java.io.IOException; |
| 8 | 8 | import java.net.HttpURLConnection; |
| | 9 | import java.net.URI; |
| 9 | 10 | import java.net.URL; |
| 10 | 11 | |
| 11 | 12 | import javax.swing.JOptionPane; |
| … |
… |
|
| 85 | 86 | protected UserInfo getUserDetails() throws OsmOAuthAuthorizationException, XmlParsingException, OsmTransferException { |
| 86 | 87 | boolean authenticatorEnabled = true; |
| 87 | 88 | try { |
| 88 | | URL url = new URL(apiUrl + "/0.6/user/details"); |
| | 89 | final URL url = URI.create(apiUrl + "/0.6/user/details").toURL(); |
| 89 | 90 | authenticatorEnabled = DefaultAuthenticator.getInstance().isEnabled(); |
| 90 | 91 | DefaultAuthenticator.getInstance().setEnabled(false); |
| 91 | 92 | |
| … |
… |
|
| 97 | 98 | } |
| 98 | 99 | |
| 99 | 100 | final String oauthKey = getAuthKey(); |
| 100 | | if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) |
| 101 | | throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, |
| | 101 | if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { |
| | 102 | throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, |
| 102 | 103 | tr("Retrieving user details with Access Token Key ''{0}'' was rejected.", |
| 103 | 104 | oauthKey), null); |
| | 105 | } |
| 104 | 106 | |
| 105 | | if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) |
| 106 | | throw new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, |
| | 107 | if (connection.getResponse().getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) { |
| | 108 | throw new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, |
| 107 | 109 | tr("Retrieving user details with Access Token Key ''{0}'' was forbidden.", oauthKey), null); |
| | 110 | } |
| 108 | 111 | |
| 109 | | if (connection.getResponse().getResponseCode() != HttpURLConnection.HTTP_OK) |
| 110 | | throw new OsmApiException(connection.getResponse().getResponseCode(), |
| | 112 | if (connection.getResponse().getResponseCode() != HttpURLConnection.HTTP_OK) { |
| | 113 | throw new OsmApiException(connection.getResponse().getResponseCode(), |
| 111 | 114 | connection.getResponse().getHeaderField("Error"), null); |
| 112 | | Document d = XmlUtils.parseSafeDOM(connection.getResponse().getContent()); |
| | 115 | } |
| | 116 | final Document d = XmlUtils.parseSafeDOM(connection.getResponse().getContent()); |
| 113 | 117 | return OsmServerUserInfoReader.buildFromXML(d); |
| 114 | 118 | } catch (SAXException | ParserConfigurationException e) { |
| 115 | 119 | throw new XmlParsingException(e); |
| … |
… |
|
| 233 | 237 | protected void realRun() throws SAXException, IOException, OsmTransferException { |
| 234 | 238 | try { |
| 235 | 239 | getProgressMonitor().indeterminateSubTask(tr("Retrieving user info...")); |
| 236 | | UserInfo userInfo = getUserDetails(); |
| 237 | | if (canceled) return; |
| | 240 | final UserInfo userInfo = getUserDetails(); |
| | 241 | if (canceled) { |
| | 242 | return; |
| | 243 | } |
| 238 | 244 | notifySuccess(userInfo); |
| 239 | 245 | } catch (OsmOAuthAuthorizationException e) { |
| 240 | | if (canceled) return; |
| | 246 | if (canceled) { |
| | 247 | return; |
| | 248 | } |
| 241 | 249 | Logging.error(e); |
| 242 | 250 | alertFailedSigning(); |
| 243 | 251 | } catch (OsmApiException e) { |
| 244 | | if (canceled) return; |
| | 252 | if (canceled) { |
| | 253 | return; |
| | 254 | } |
| 245 | 255 | Logging.error(e); |
| 246 | 256 | if (e.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { |
| 247 | 257 | alertInternalError(); |
| … |
… |
|
| 255 | 265 | } |
| 256 | 266 | alertFailedConnection(); |
| 257 | 267 | } catch (OsmTransferException e) { |
| 258 | | if (canceled) return; |
| | 268 | if (canceled) { |
| | 269 | return; |
| | 270 | } |
| 259 | 271 | Logging.error(e); |
| 260 | 272 | alertFailedConnection(); |
| 261 | 273 | } |