- Timestamp:
- 2014-01-06T15:57:41+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r6565 r6642 23 23 import java.util.Arrays; 24 24 import java.util.Collection; 25 import java.util.HashMap; 25 26 import java.util.Iterator; 26 27 import java.util.List; … … 202 203 */ 203 204 public OsmValidator validator; 205 204 206 /** 205 207 * The MOTD Layer. … … 208 210 209 211 private static final Collection<MapFrameListener> mapFrameListeners = new ArrayList<MapFrameListener>(); 212 213 protected static final Map<String, Throwable> networkErrors = new HashMap<String, Throwable>(); 210 214 211 215 /** … … 303 307 */ 304 308 public static void error(Throwable t) { 305 error(getErrorMessage(t)); 306 t.printStackTrace(); 309 error(t, true); 307 310 } 308 311 … … 313 316 */ 314 317 public static void warn(Throwable t) { 318 warn(t, true); 319 } 320 321 /** 322 * Prints an error message for the given Throwable. 323 * @param t The throwable object causing the error 324 * @param stackTrace {@code true}, if the stacktrace should be displayed 325 * @since 6442 326 */ 327 public static void error(Throwable t, boolean stackTrace) { 328 error(getErrorMessage(t)); 329 if (stackTrace) { 330 t.printStackTrace(); 331 } 332 } 333 334 /** 335 * Prints a warning message for the given Throwable. 336 * @param t The throwable object causing the error 337 * @param stackTrace {@code true}, if the stacktrace should be displayed 338 * @since 6442 339 */ 340 public static void warn(Throwable t, boolean stackTrace) { 315 341 warn(getErrorMessage(t)); 316 t.printStackTrace(); 317 } 318 319 private static String getErrorMessage(Throwable t) { 342 if (stackTrace) { 343 t.printStackTrace(); 344 } 345 } 346 347 /** 348 * Returns a human-readable message of error, also usable for developers. 349 * @param t The error 350 * @return The human-readable error message 351 * @since 6642 352 */ 353 public static String getErrorMessage(Throwable t) { 354 if (t == null) { 355 return null; 356 } 320 357 StringBuilder sb = new StringBuilder(t.getClass().getName()); 321 358 String msg = t.getMessage(); … … 455 492 try { 456 493 OsmApi.getOsmApi().initialize(null, true); 457 } catch (Exception x) {458 // ignore any exception here.494 } catch (Exception e) { 495 Main.warn(getErrorMessage(Utils.getRootCause(e))); 459 496 } 460 497 return null; … … 722 759 panel.updateUI(); 723 760 } catch (final Exception e) { 724 e .printStackTrace();761 error(e); 725 762 } 726 763 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); … … 1350 1387 return listener != null ? mapFrameListeners.remove(listener) : false; 1351 1388 } 1389 1390 /** 1391 * Adds a new network error that occur to give a hint about broken Internet connection. 1392 * Do not use this method for errors known for sure thrown because of a bad proxy configuration. 1393 * 1394 * @param url The accessed URL that caused the error 1395 * @param t The network error 1396 * @return The previous error associated to the given resource, if any. Can be {@code null} 1397 * @since 6639 1398 */ 1399 public static Throwable addNetworkError(URL url, Throwable t) { 1400 if (url != null && t != null) { 1401 Throwable old = addNetworkError(url.toExternalForm(), t); 1402 if (old != null) { 1403 Main.warn("Already here "+old); 1404 } 1405 return old; 1406 } 1407 return null; 1408 } 1409 1410 /** 1411 * Adds a new network error that occur to give a hint about broken Internet connection. 1412 * Do not use this method for errors known for sure thrown because of a bad proxy configuration. 1413 * 1414 * @param url The accessed URL that caused the error 1415 * @param t The network error 1416 * @return The previous error associated to the given resource, if any. Can be {@code null} 1417 * @since 6639 1418 */ 1419 public static Throwable addNetworkError(String url, Throwable t) { 1420 if (url != null && t != null) { 1421 return networkErrors.put(url, t); 1422 } 1423 return null; 1424 } 1425 1426 /** 1427 * Returns the network errors that occured until now. 1428 * @return the network errors that occured until now, indexed by URL 1429 * @since 6639 1430 */ 1431 public static Map<String, Throwable> getNetworkErrors() { 1432 return new HashMap<String, Throwable>(networkErrors); 1433 } 1352 1434 } -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r6316 r6642 81 81 } catch (IOException ex) { 82 82 Utils.close(stream); 83 ex.printStackTrace();83 Main.error(ex, false); 84 84 continue; 85 } catch (SAXException sex) {85 } catch (SAXException ex) { 86 86 Utils.close(stream); 87 sex.printStackTrace();87 Main.error(ex); 88 88 continue; 89 89 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r6578 r6642 27 27 import java.util.List; 28 28 import java.util.Map; 29 import java.util.Set; 30 import java.util.TreeSet; 29 31 30 32 import javax.swing.JFrame; … … 87 89 mainFrame.setIconImages(l); 88 90 mainFrame.addWindowListener(new WindowAdapter(){ 89 @Override public void windowClosing(final WindowEvent arg0) { 91 @Override 92 public void windowClosing(final WindowEvent arg0) { 90 93 Main.exitJosm(true, 0); 91 94 } … … 297 300 298 301 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler()); 299 // http://stuffthathappens.com/blog/2007/10/15/one-more-note-on-uncaught-exception-handlers/ 302 // http://stackoverflow.com/q/75218/2257172 303 // To be replaced with official API when switching to Java 7: https://bugs.openjdk.java.net/browse/JDK-4714232 300 304 System.setProperty("sun.awt.exception.handler", BugReportExceptionHandler.class.getName()); 301 305 … … 441 445 public void run() { 442 446 443 // Handle proxy errors early to inform user he should change settings to be able to use JOSM correctly 444 handleProxyErrors(); 447 // Handle proxy/network errors early to inform user he should change settings to be able to use JOSM correctly 448 if (!handleProxyErrors()) { 449 handleNetworkErrors(); 450 } 445 451 446 452 // Restore autosave layers after crash and start autosave thread … … 480 486 } 481 487 482 private void handleProxyErrors() {483 if ( proxySelector.hasErrors()) {488 private boolean handleNetworkOrProxyErrors(boolean hasErrors, String title, String message) { 489 if (hasErrors) { 484 490 ExtendedDialog ed = new ExtendedDialog( 485 Main.parent, t r("Proxy errors occurred"),491 Main.parent, title, 486 492 new String[]{tr("Change proxy settings"), tr("Cancel")}); 487 493 ed.setButtonIcons(new String[]{"dialogs/settings.png", "cancel.png"}).setCancelButton(2); 488 494 ed.setMinimumSize(new Dimension(460, 260)); 489 495 ed.setIcon(JOptionPane.WARNING_MESSAGE); 490 ed.setContent(tr("JOSM tried to access the following resources:<br>" + 491 "{0}" + 492 "but <b>failed</b> to do so, because of the following proxy errors:<br>" + 493 "{1}" + 494 "Would you like to change your proxy settings now?", 495 Utils.joinAsHtmlUnorderedList(proxySelector.getErrorResources()), 496 Utils.joinAsHtmlUnorderedList(proxySelector.getErrorMessages()) 497 )); 496 ed.setContent(message); 498 497 499 498 if (ed.showDialog().getValue() == 1) { … … 501 500 } 502 501 } 502 return hasErrors; 503 } 504 505 private boolean handleProxyErrors() { 506 return handleNetworkOrProxyErrors(proxySelector.hasErrors(), tr("Proxy errors occurred"), 507 tr("JOSM tried to access the following resources:<br>" + 508 "{0}" + 509 "but <b>failed</b> to do so, because of the following proxy errors:<br>" + 510 "{1}" + 511 "Would you like to change your proxy settings now?", 512 Utils.joinAsHtmlUnorderedList(proxySelector.getErrorResources()), 513 Utils.joinAsHtmlUnorderedList(proxySelector.getErrorMessages()) 514 )); 515 } 516 517 private boolean handleNetworkErrors() { 518 boolean condition = !networkErrors.isEmpty(); 519 if (condition) { 520 Set<String> errors = new TreeSet<String>(); 521 for (Throwable t : networkErrors.values()) { 522 errors.add(t.toString()); 523 } 524 return handleNetworkOrProxyErrors(condition, tr("Network errors occurred"), 525 tr("JOSM tried to access the following resources:<br>" + 526 "{0}" + 527 "but <b>failed</b> to do so, because of the following network errors:<br>" + 528 "{1}" + 529 "It may result of a missing proxy configuration.<br>" + 530 "Would you like to change your proxy settings now?", 531 Utils.joinAsHtmlUnorderedList(networkErrors.keySet()), 532 Utils.joinAsHtmlUnorderedList(errors) 533 )); 534 } 535 return false; 503 536 } 504 537 } -
trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
r6617 r6642 297 297 con.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000); 298 298 con.setReadTimeout(Main.pref.getInteger("socket.timeout.read",30)*1000); 299 con.connect(); 299 try { 300 con.connect(); 301 } catch (IOException e) { 302 Main.addNetworkError(downloadUrl, Utils.getRootCause(e)); 303 throw e; 304 } 300 305 switch(con.getResponseCode()) { 301 306 case HttpURLConnection.HTTP_OK: -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r6582 r6642 78 78 private static Map<String, OsmApi> instances = new HashMap<String, OsmApi>(); 79 79 80 private URL url = null; 81 80 82 /** 81 83 * Replies the {@link OsmApi} for a given server URL … … 235 237 /* This is an interim solution for openstreetmap.org not currently 236 238 * transmitting their imagery blacklist in the capabilities call. 237 * remove this as soon as openstreetmap.org adds blacklists. */ 239 * remove this as soon as openstreetmap.org adds blacklists. 240 * If you want to update this list, please ask for update of 241 * http://trac.openstreetmap.org/ticket/5024 242 * This list should not be maintained by each OSM editor (see #9210) */ 238 243 if (this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty()) 239 244 { … … 261 266 } catch (OsmTransferCanceledException e) { 262 267 throw e; 268 } catch (OsmTransferException e) { 269 initialized = false; 270 Main.addNetworkError(url, Utils.getRootCause(e)); 271 throw new OsmApiInitializationException(e); 263 272 } catch (Exception e) { 264 273 initialized = false; … … 598 607 while(true) { // the retry loop 599 608 try { 600 URLurl = new URL(new URL(getBaseUrl()), urlSuffix);601 System.out.print(requestMethod + " " + url + "... ");609 url = new URL(new URL(getBaseUrl()), urlSuffix); 610 Main.info(requestMethod + " " + url + "... "); 602 611 // fix #5369, see http://www.tikalk.com/java/forums/httpurlconnection-disable-keep-alive 603 612 activeConnection = Utils.openHttpConnection(url, false); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6623 r6642 419 419 return true; 420 420 } catch (IllegalStateException ex) { 421 ex.printStackTrace();421 Main.error(ex); 422 422 return false; 423 423 } … … 449 449 } 450 450 } catch (UnsupportedFlavorException ex) { 451 ex.printStackTrace();451 Main.error(ex); 452 452 return null; 453 453 } catch (IOException ex) { 454 ex.printStackTrace();454 Main.error(ex); 455 455 return null; 456 456 } … … 895 895 } 896 896 897 /** 898 * Returns the root cause of a throwable object. 899 * @param t The object to get root cause for 900 * @return the root cause of {@code t} 901 * @since 6639 902 */ 903 public static Throwable getRootCause(Throwable t) { 904 Throwable result = t; 905 if (result != null) { 906 Throwable cause = result.getCause(); 907 while (cause != null && cause != result) { 908 result = cause; 909 cause = result.getCause(); 910 } 911 } 912 return result; 913 } 897 914 } -
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r6380 r6642 18 18 private final String baseurl; 19 19 20 /** 21 * Constructs a new {@code WikiReader} for the given base URL. 22 * @param baseurl The wiki base URL 23 */ 20 24 public WikiReader(String baseurl) { 21 25 this.baseurl = baseurl; … … 80 84 81 85 private String readLang(URL url) throws IOException { 82 BufferedReader in = Utils.openURLReader(url); 86 BufferedReader in; 87 try { 88 in = Utils.openURLReader(url); 89 } catch (IOException e) { 90 Main.addNetworkError(url, Utils.getRootCause(e)); 91 throw e; 92 } 83 93 try { 84 94 return readFromTrac(in, url); … … 124 134 // add a border="0" attribute to images, otherwise the internal help browser 125 135 // will render a thick border around images inside an <a> element 126 //127 136 b += line.replaceAll("<img ", "<img border=\"0\" ") 128 137 .replaceAll("<span class=\"icon\">.</span>", "")
Note:
See TracChangeset
for help on using the changeset viewer.