Changeset 3993 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-03-17T15:04:31+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r3956 r3993 216 216 // capabilities are already known to the editor instance. However 217 217 // if it goes wrong that's not critical at this stage. 218 if (Main.pref.getBoolean("get-capabilities-at-start", false)) { 219 try { 220 OsmApi.getOsmApi().initialize(null); 221 } catch (Exception x) { 222 // ignore any exception here. 223 } 218 try { 219 OsmApi.getOsmApi().initialize(null, true); 220 } catch (Exception x) { 221 // ignore any exception here. 224 222 } 225 223 -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r3934 r3993 149 149 } 150 150 151 public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException, OsmTransferCancelledException { 152 initialize(monitor, false); 153 } 151 154 /** 152 155 * Initializes this component by negotiating a protocol version with the server. 153 156 * 157 * @param monitor 158 * @param fastFail true to request quick initialisation with a small timeout (more likely to throw exception) 154 159 * @exception OsmApiInitializationException thrown, if an exception occurs 155 160 */ 156 public void initialize(ProgressMonitor monitor ) throws OsmApiInitializationException, OsmTransferCancelledException {161 public void initialize(ProgressMonitor monitor, boolean fastFail) throws OsmApiInitializationException, OsmTransferCancelledException { 157 162 if (initialized) 158 163 return; 159 164 cancel = false; 160 165 try { 161 String s = sendRequest("GET", "capabilities", null, monitor, false );166 String s = sendRequest("GET", "capabilities", null, monitor, false, fastFail); 162 167 InputSource inputSource = new InputSource(new StringReader(s)); 163 168 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser()); … … 506 511 507 512 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException { 508 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, true); 513 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, true, false); 514 } 515 516 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, boolean doAuth) throws OsmTransferException { 517 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, doAuth, false); 509 518 } 510 519 … … 522 531 * @param doAuthenticate set to true, if the request sent to the server shall include authentication 523 532 * credentials; 533 * @param fastFail true to request a short timeout 524 534 * 525 535 * @return the body of the HTTP response, if and only if the response code was "200 OK". … … 527 537 * been exhausted), or rewrapping a Java exception. 528 538 */ 529 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, boolean doAuthenticate ) throws OsmTransferException {539 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, boolean doAuthenticate, boolean fastFail) throws OsmTransferException { 530 540 StringBuffer responseBody = new StringBuffer(); 531 541 int retries = getMaxRetries(); … … 536 546 System.out.print(requestMethod + " " + url + "... "); 537 547 activeConnection = (HttpURLConnection)url.openConnection(); 538 activeConnection.setConnectTimeout( 15000);548 activeConnection.setConnectTimeout(fastFail ? 1000 : 15000); 539 549 activeConnection.setRequestMethod(requestMethod); 540 550 if (doAuthenticate) {
Note:
See TracChangeset
for help on using the changeset viewer.