Ticket #23078: josm_23078.patch

File josm_23078.patch, 4.0 KB (added by gaben, 3 years ago)
  • src/org/openstreetmap/josm/io/OsmApi.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/io/OsmApi.java b/src/org/openstreetmap/josm/io/OsmApi.java
    a b  
    247247    public void initialize(ProgressMonitor monitor, boolean fastFail) throws OsmTransferCanceledException, OsmApiInitializationException {
    248248        if (initialized)
    249249            return;
    250         cancel = false;
    251250        try {
    252251            CapabilitiesCache cache = new CapabilitiesCache(monitor, fastFail);
    253252            try {
     
    617616
    618617    private void sleepAndListen(int retry, ProgressMonitor monitor) throws OsmTransferCanceledException {
    619618        Logging.info(tr("Waiting 10 seconds ... "));
     619        if (monitor != null) {
     620            monitor.addCancelListener(this::cancel);
     621        }
     622
    620623        for (int i = 0; i < 10; i++) {
    621624            if (monitor != null) {
    622625                monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry, getMaxRetries(), 10-i));
    623             }
    624             if (cancel)
    625                 throw new OsmTransferCanceledException("Operation canceled" + (i > 0 ? " in retry #"+i : ""));
     626                if (monitor.isCanceled()) {
     627                    throw new OsmTransferCanceledException("Operation canceled" + (i > 0 ? " in retry #"+i : ""));
     628                }
     629            }
    626630            try {
    627631                Thread.sleep(1000);
    628632            } catch (InterruptedException ex) {
  • src/org/openstreetmap/josm/io/OsmConnection.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/io/OsmConnection.java b/src/org/openstreetmap/josm/io/OsmConnection.java
    a b  
    4848
    4949    private static final String BASIC_AUTH = "Basic ";
    5050
    51     protected boolean cancel;
    5251    protected HttpClient activeConnection;
    5352    protected OAuthParameters oauthParameters;
    5453    protected IOAuthParameters oAuth20Parameters;
     
    8483     * Cancels the connection.
    8584     */
    8685    public void cancel() {
    87         cancel = true;
    8886        synchronized (this) {
    8987            if (activeConnection != null) {
    9088                activeConnection.disconnect();
     
    132130        } catch (CredentialsAgentException e) {
    133131            throw new OsmTransferException(e);
    134132        }
    135         if (response != null) {
    136             if (response.isCanceled()) {
    137                 cancel = true;
    138             } else {
    139                 String username = response.getUsername() == null ? "" : response.getUsername();
    140                 String password = response.getPassword() == null ? "" : String.valueOf(response.getPassword());
    141                 String token = username + ':' + password;
    142                 con.setHeader("Authorization", BASIC_AUTH + Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8)));
    143             }
     133        if (response != null && !response.isCanceled()) {
     134            String username = response.getUsername() == null ? "" : response.getUsername();
     135            String password = response.getPassword() == null ? "" : String.valueOf(response.getPassword());
     136            String token = username + ':' + password;
     137            con.setHeader("Authorization", BASIC_AUTH + Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8)));
    144138        }
    145139    }
    146140
     
    292286                throw new OsmTransferException(msg);
    293287        }
    294288    }
    295 
    296     /**
    297      * Replies true if this connection is canceled
    298      *
    299      * @return true if this connection is canceled
    300      */
    301     public boolean isCanceled() {
    302         return cancel;
    303     }
    304289}