Changeset 9308 in josm for trunk/src/org


Ignore:
Timestamp:
2016-01-04T20:09:51+01:00 (4 years ago)
Author:
simon04
Message:

fix #11693 - Overpass download: parse and use timeout from [timeout:X] parameter

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

Legend:

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

    r9185 r9308  
    124124            final HttpClient client = HttpClient.create(url);
    125125            client.setReasonForRequest(reason);
     126            adaptRequest(client);
    126127            if (doAuthenticate) {
    127128                addAuth(client);
     
    170171
    171172    /**
     173     * Allows subclasses to modify the request.
     174     * @param request the prepared request
     175     * @since 9308
     176     */
     177    protected void adaptRequest(HttpClient request) {
     178    }
     179
     180    /**
    172181     * Download OSM files from somewhere
    173182     * @param progressMonitor The progress monitor
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r8870 r9308  
    55
    66import java.io.InputStream;
     7import java.util.regex.Matcher;
     8import java.util.regex.Pattern;
    79
    810import javax.xml.stream.XMLStreamConstants;
     
    1315import org.openstreetmap.josm.data.osm.DataSet;
    1416import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     17import org.openstreetmap.josm.tools.HttpClient;
    1518import org.openstreetmap.josm.tools.Utils;
    1619
     
    105108
    106109    @Override
     110    protected void adaptRequest(HttpClient request) {
     111        // see https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#timeout
     112        final Matcher timeoutMatcher = Pattern.compile("\\[timeout:(\\d+)\\]").matcher(overpassQuery);
     113        if (timeoutMatcher.find()) {
     114            final int timeout = 1000 * Integer.parseInt(timeoutMatcher.group(1));
     115            request.setConnectTimeout(timeout);
     116            request.setReadTimeout(timeout);
     117        }
     118    }
     119
     120    @Override
    107121    protected String getTaskName() {
    108122        return tr("Contacting Server...");
Note: See TracChangeset for help on using the changeset viewer.