Changeset 3993 in josm


Ignore:
Timestamp:
Mar 17, 2011 3:04:31 PM (2 years ago)
Author:
framm
Message:

use short timeout for initial API connection, related to #6037

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r3956 r3993  
    216216        // capabilities are already known to the editor instance. However 
    217217        // 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. 
    224222        } 
    225223 
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r3934 r3993  
    149149    } 
    150150 
     151    public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException, OsmTransferCancelledException { 
     152        initialize(monitor, false); 
     153    } 
    151154    /** 
    152155     * Initializes this component by negotiating a protocol version with the server. 
    153156     * 
     157     * @param monitor 
     158     * @param fastFail true to request quick initialisation with a small timeout (more likely to throw exception) 
    154159     * @exception OsmApiInitializationException thrown, if an exception occurs 
    155160     */ 
    156     public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException, OsmTransferCancelledException { 
     161    public void initialize(ProgressMonitor monitor, boolean fastFail) throws OsmApiInitializationException, OsmTransferCancelledException { 
    157162        if (initialized) 
    158163            return; 
    159164        cancel = false; 
    160165        try { 
    161             String s = sendRequest("GET", "capabilities", null, monitor, false); 
     166            String s = sendRequest("GET", "capabilities", null, monitor, false, fastFail); 
    162167            InputSource inputSource = new InputSource(new StringReader(s)); 
    163168            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser()); 
     
    506511 
    507512    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); 
    509518    } 
    510519 
     
    522531     * @param doAuthenticate  set to true, if the request sent to the server shall include authentication 
    523532     * credentials; 
     533     * @param fastFail true to request a short timeout 
    524534     * 
    525535     * @return the body of the HTTP response, if and only if the response code was "200 OK". 
     
    527537     *    been exhausted), or rewrapping a Java exception. 
    528538     */ 
    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 { 
    530540        StringBuffer responseBody = new StringBuffer(); 
    531541        int retries = getMaxRetries(); 
     
    536546                System.out.print(requestMethod + " " + url + "... "); 
    537547                activeConnection = (HttpURLConnection)url.openConnection(); 
    538                 activeConnection.setConnectTimeout(15000); 
     548                activeConnection.setConnectTimeout(fastFail ? 1000 : 15000); 
    539549                activeConnection.setRequestMethod(requestMethod); 
    540550                if (doAuthenticate) { 
Note: See TracChangeset for help on using the changeset viewer.