Ignore:
Timestamp:
2013-12-24T20:26:51+01:00 (10 years ago)
Author:
Don-vip
Message:

Ask user to change proxy settings when proxy errors occur at startup (useful when a laptop is often used between two locations with different proxy settings)

File:
1 edited

Legend:

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

    r6348 r6523  
    1212import java.net.URI;
    1313import java.util.Collections;
     14import java.util.HashSet;
    1415import java.util.List;
     16import java.util.Set;
     17import java.util.TreeSet;
    1518
    1619import org.openstreetmap.josm.Main;
     
    5659    private InetSocketAddress socksProxySocketAddress;
    5760    private ProxySelector delegate;
     61
     62    private final Set<String> errorResources = new HashSet<String>();
     63    private final Set<String> errorMessages = new HashSet<String>();
    5864
    5965    /**
     
    134140    public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
    135141        // Just log something. The network stack will also throw an exception which will be caught somewhere else
    136         //
    137142        Main.error(tr("Connection to proxy ''{0}'' for URI ''{1}'' failed. Exception was: {2}", sa.toString(), uri.toString(), ioe.toString()));
     143        // Remember errors to give a friendly user message asking to review proxy configuration
     144        errorResources.add(uri.toString());
     145        errorMessages.add(ioe.toString());
     146    }
     147
     148    /**
     149     * Returns the set of current proxy resources that failed to be retrieved.
     150     * @return the set of current proxy resources that failed to be retrieved
     151     * @since 6523
     152     */
     153    public final Set<String> getErrorResources() {
     154        return new TreeSet<String>(errorResources);
     155    }
     156
     157    /**
     158     * Returns the set of current proxy error messages.
     159     * @return the set of current proxy error messages
     160     * @since 6523
     161     */
     162    public final Set<String> getErrorMessages() {
     163        return new TreeSet<String>(errorMessages);
     164    }
     165
     166    /**
     167     * Clear the sets of failed resources and error messages.
     168     * @since 6523
     169     */
     170    public final void clearErrors() {
     171        errorResources.clear();
     172        errorMessages.clear();
     173    }
     174
     175    /**
     176     * Determines if proxy errors have occured.
     177     * @return {@code true} if errors have occured, {@code false} otherwise.
     178     * @since 6523
     179     */
     180    public final boolean hasErrors() {
     181        return !errorResources.isEmpty();
    138182    }
    139183
Note: See TracChangeset for help on using the changeset viewer.