java.net.URLConnection#setIfModifiedSince ( )源码实例Demo

下面列出了java.net.URLConnection#setIfModifiedSince ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rome   文件: HttpURLFeedFetcher.java
/**
 * <p>
 * Set appropriate HTTP headers, including conditional get and gzip encoding headers
 * </p>
 *
 * @param connection A URLConnection
 * @param syndFeedInfo The SyndFeedInfo for the feed to be retrieved. May be null
 * @param userAgent the name of the user-agent to be placed in HTTP-header.
 */
protected void setRequestHeaders(final URLConnection connection, final SyndFeedInfo syndFeedInfo, final String userAgent) {
    if (syndFeedInfo != null) {
        // set the headers to get feed only if modified
        // we support the use of both last modified and eTag headers
        if (syndFeedInfo.getLastModified() != null) {
            final Object lastModified = syndFeedInfo.getLastModified();
            if (lastModified instanceof Long) {
                connection.setIfModifiedSince((Long) syndFeedInfo.getLastModified());
            }
        }
        if (syndFeedInfo.getETag() != null) {
            connection.setRequestProperty("If-None-Match", syndFeedInfo.getETag());
        }

    }
    // header to retrieve feed gzipped
    connection.setRequestProperty("Accept-Encoding", "gzip");
    connection.addRequestProperty("User-Agent", userAgent);

    if (isUsingDeltaEncoding()) {
        connection.addRequestProperty("A-IM", "feed");
    }
}
 
源代码2 项目: JsDroidCmd   文件: UrlModuleSourceProvider.java
void applyConditionals(URLConnection urlConnection) {
    if(lastModified != 0L) {
        urlConnection.setIfModifiedSince(lastModified);
    }
    if(entityTags != null && entityTags.length() > 0) {
        urlConnection.addRequestProperty("If-None-Match", entityTags);
    }
}
 
源代码3 项目: rdf4j   文件: DatasetRepository.java
/**
 * Inspects if the dataset at the supplied URL location has been modified since the last load into this repository
 * and if so loads it into the supplied context.
 *
 * @param url     the location of the dataset
 * @param context the context in which to load the dataset
 * @param config  parser configuration to use for processing the dataset
 * @throws RepositoryException if an error occurred while loading the dataset.
 */
public void loadDataset(URL url, IRI context, ParserConfig config) throws RepositoryException {
	try {
		Long since = lastModified.get(url);
		URLConnection urlCon = url.openConnection();
		if (since != null) {
			urlCon.setIfModifiedSince(since);
		}
		if (since == null || since < urlCon.getLastModified()) {
			load(url, urlCon, context, config);
		}
	} catch (RDFParseException | IOException e) {
		throw new RepositoryException(e);
	}
}
 
源代码4 项目: android-sdk   文件: Client.java
/**
 * Adds a if-modified-since header to the open {@link URLConnection} if this value is
 * stored in {@link OptlyStorage}.
 * @param urlConnection an open {@link URLConnection}
 */
public void setIfModifiedSince(@NonNull URLConnection urlConnection) {
    if (urlConnection == null || urlConnection.getURL() == null) {
        logger.error("Invalid connection");
        return;
    }

    long lastModified = optlyStorage.getLong(urlConnection.getURL().toString(), 0);
    if (lastModified > 0) {
        urlConnection.setIfModifiedSince(lastModified);
    }
}
 
源代码5 项目: APICloud-Studio   文件: UniformResourceStorage.java
/**
 * isValid
 * 
 * @return boolean
 */
public boolean isValid() {
	if (timestamp == -1) {
		return false;
	}
	if (expires >= System.currentTimeMillis()) {
		return true;
	}
	try {
		URLConnection connection = getURI().toURL().openConnection();
		if (connection instanceof HttpURLConnection) {
			connection.setIfModifiedSince(timestamp);
			((HttpURLConnection) connection).setRequestMethod("HEAD"); //$NON-NLS-1$
		}
		connection.connect();
		if (connection instanceof HttpURLConnection) {
			HttpURLConnection httpConnection = (HttpURLConnection) connection;
			long lastModified = httpConnection.getLastModified();
			if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED || (lastModified != 0 && timestamp >= lastModified)) {
				expires = System.currentTimeMillis();
				long expiration = connection.getExpiration();
				long date = connection.getDate();
				if (expiration != 0 && date != 0 && expiration > date) {
					expires += (expiration - date);
				} else {
					expires += 10 * 1000; // 10 sec
				}
				return true;
			}
		}
	} catch (IOException e) {
		IdeLog.logError(CorePlugin.getDefault(), e);
	}
	return false;
}
 
源代码6 项目: openbd-core   文件: UrlModuleSourceProvider.java
void applyConditionals(URLConnection urlConnection) {
    if(lastModified != 0L) {
        urlConnection.setIfModifiedSince(lastModified);
    }
    if(entityTags != null && entityTags.length() > 0) {
        urlConnection.addRequestProperty("If-None-Match", entityTags);
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码8 项目: TencentKona-8   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码9 项目: jdk8u60   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码10 项目: openjdk-jdk8u   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码12 项目: j2objc   文件: URICertStore.java
/**
     * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
     * match the specified selector. If no <code>X509Certificate</code>s
     * match the selector, an empty <code>Collection</code> will be returned.
     *
     * @param selector a <code>CertSelector</code> used to select which
     *  <code>X509Certificate</code>s should be returned. Specify
     *  <code>null</code> to return all <code>X509Certificate</code>s.
     * @return a <code>Collection</code> of <code>X509Certificate</code>s that
     *         match the specified selector
     * @throws CertStoreException if an exception occurs
     */
    @Override
    @SuppressWarnings("unchecked")
    public synchronized Collection<X509Certificate> engineGetCertificates
        (CertSelector selector) throws CertStoreException {

        // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
        // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
//        if (ldap) {
//            X509CertSelector xsel = (X509CertSelector) selector;
//            try {
//                xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
//            } catch (IOException ioe) {
//                throw new CertStoreException(ioe);
//            }
//            // Fetch the certificates via LDAP. LDAPCertStore has its own
//            // caching mechanism, see the class description for more info.
//            // Safe cast since xsel is an X509 certificate selector.
//            return (Collection<X509Certificate>)
//                ldapCertStore.getCertificates(xsel);
//        }

        // Return the Certificates for this entry. It returns the cached value
        // if it is still current and fetches the Certificates otherwise.
        // For the caching details, see the top of this class.
        long time = System.currentTimeMillis();
        if (time - lastChecked < CHECK_INTERVAL) {
            if (debug != null) {
                debug.println("Returning certificates from cache");
            }
            return getMatchingCerts(certs, selector);
        }
        lastChecked = time;
        try {
            URLConnection connection = uri.toURL().openConnection();
            if (lastModified != 0) {
                connection.setIfModifiedSince(lastModified);
            }
            long oldLastModified = lastModified;
            try (InputStream in = connection.getInputStream()) {
                lastModified = connection.getLastModified();
                if (oldLastModified != 0) {
                    if (oldLastModified == lastModified) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    } else if (connection instanceof HttpURLConnection) {
                        // some proxy servers omit last modified
                        HttpURLConnection hconn = (HttpURLConnection)connection;
                        if (hconn.getResponseCode()
                                    == HttpURLConnection.HTTP_NOT_MODIFIED) {
                            if (debug != null) {
                                debug.println("Not modified, using cached copy");
                            }
                            return getMatchingCerts(certs, selector);
                        }
                    }
                }
                if (debug != null) {
                    debug.println("Downloading new certificates...");
                }
                // Safe cast since factory is an X.509 certificate factory
                certs = (Collection<X509Certificate>)
                    factory.generateCertificates(in);
            }
            return getMatchingCerts(certs, selector);
        } catch (IOException | CertificateException e) {
            if (debug != null) {
                debug.println("Exception fetching certificates:");
                e.printStackTrace();
            }
        }
        // exception, forget previous values
        lastModified = 0;
        certs = Collections.emptySet();
        return certs;
    }
 
源代码13 项目: Elasticsearch   文件: HttpDownloadHelper.java
private URLConnection openConnection(URL aSource) throws IOException {

            // set up the URL connection
            URLConnection connection = aSource.openConnection();
            // modify the headers
            // NB: things like user authentication could go in here too.
            if (hasTimestamp) {
                connection.setIfModifiedSince(timestamp);
            }

            // in case the plugin manager is its own project, this can become an authenticator
            boolean isSecureProcotol = "https".equalsIgnoreCase(aSource.getProtocol());
            boolean isAuthInfoSet = !Strings.isNullOrEmpty(aSource.getUserInfo());
            if (isAuthInfoSet) {
                if (!isSecureProcotol) {
                    throw new IOException("Basic auth is only supported for HTTPS!");
                }
                String basicAuth = Base64.encodeBytes(aSource.getUserInfo().getBytes(StandardCharsets.UTF_8));
                connection.setRequestProperty("Authorization", "Basic " + basicAuth);
            }

            if (connection instanceof HttpURLConnection) {
                ((HttpURLConnection) connection).setInstanceFollowRedirects(false);
                connection.setUseCaches(true);
                connection.setConnectTimeout(5000);
            }
            connection.setRequestProperty("ES-Version", Version.CURRENT.toString());
            connection.setRequestProperty("ES-Build-Hash", Build.CURRENT.hashShort());
            connection.setRequestProperty("User-Agent", "elasticsearch-plugin-manager");

            // connect to the remote site (may take some time)
            connection.connect();

            // First check on a 301 / 302 (moved) response (HTTP only)
            if (connection instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
                        responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||
                        responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
                    String newLocation = httpConnection.getHeaderField("Location");
                    URL newURL = new URL(newLocation);
                    if (!redirectionAllowed(aSource, newURL)) {
                        return null;
                    }
                    return openConnection(newURL);
                }
                // next test for a 304 result (HTTP only)
                long lastModified = httpConnection.getLastModified();
                if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
                        || (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {
                    // not modified so no file download. just return
                    // instead and trace out something so the user
                    // doesn't think that the download happened when it
                    // didn't
                    return null;
                }
                // test for 401 result (HTTP only)
                if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
                    String message = "HTTP Authorization failure";
                    throw new IOException(message);
                }
            }

            //REVISIT: at this point even non HTTP connections may
            //support the if-modified-since behaviour -we just check
            //the date of the content and skip the write if it is not
            //newer. Some protocols (FTP) don't include dates, of
            //course.
            return connection;
        }
 
源代码14 项目: openjdk-jdk9   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    if (ldap) {
        // caching mechanism, see the class description for more info.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(selector);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码15 项目: jdk8u-jdk   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码16 项目: hottub   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码17 项目: openjdk-8-source   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码18 项目: openjdk-8   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码19 项目: jdk8u-jdk   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}
 
源代码20 项目: jdk8u-dev-jdk   文件: URICertStore.java
/**
 * Returns a <code>Collection</code> of <code>X509Certificate</code>s that
 * match the specified selector. If no <code>X509Certificate</code>s
 * match the selector, an empty <code>Collection</code> will be returned.
 *
 * @param selector a <code>CertSelector</code> used to select which
 *  <code>X509Certificate</code>s should be returned. Specify
 *  <code>null</code> to return all <code>X509Certificate</code>s.
 * @return a <code>Collection</code> of <code>X509Certificate</code>s that
 *         match the specified selector
 * @throws CertStoreException if an exception occurs
 */
@Override
@SuppressWarnings("unchecked")
public synchronized Collection<X509Certificate> engineGetCertificates
    (CertSelector selector) throws CertStoreException {

    // if ldap URI we wrap the CertSelector in an LDAPCertSelector to
    // avoid LDAP DN matching issues (see LDAPCertSelector for more info)
    if (ldap) {
        X509CertSelector xsel = (X509CertSelector) selector;
        try {
            xsel = ldapHelper.wrap(xsel, xsel.getSubject(), ldapPath);
        } catch (IOException ioe) {
            throw new CertStoreException(ioe);
        }
        // Fetch the certificates via LDAP. LDAPCertStore has its own
        // caching mechanism, see the class description for more info.
        // Safe cast since xsel is an X509 certificate selector.
        return (Collection<X509Certificate>)
            ldapCertStore.getCertificates(xsel);
    }

    // Return the Certificates for this entry. It returns the cached value
    // if it is still current and fetches the Certificates otherwise.
    // For the caching details, see the top of this class.
    long time = System.currentTimeMillis();
    if (time - lastChecked < CHECK_INTERVAL) {
        if (debug != null) {
            debug.println("Returning certificates from cache");
        }
        return getMatchingCerts(certs, selector);
    }
    lastChecked = time;
    try {
        URLConnection connection = uri.toURL().openConnection();
        if (lastModified != 0) {
            connection.setIfModifiedSince(lastModified);
        }
        long oldLastModified = lastModified;
        try (InputStream in = connection.getInputStream()) {
            lastModified = connection.getLastModified();
            if (oldLastModified != 0) {
                if (oldLastModified == lastModified) {
                    if (debug != null) {
                        debug.println("Not modified, using cached copy");
                    }
                    return getMatchingCerts(certs, selector);
                } else if (connection instanceof HttpURLConnection) {
                    // some proxy servers omit last modified
                    HttpURLConnection hconn = (HttpURLConnection)connection;
                    if (hconn.getResponseCode()
                                == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        if (debug != null) {
                            debug.println("Not modified, using cached copy");
                        }
                        return getMatchingCerts(certs, selector);
                    }
                }
            }
            if (debug != null) {
                debug.println("Downloading new certificates...");
            }
            // Safe cast since factory is an X.509 certificate factory
            certs = (Collection<X509Certificate>)
                factory.generateCertificates(in);
        }
        return getMatchingCerts(certs, selector);
    } catch (IOException | CertificateException e) {
        if (debug != null) {
            debug.println("Exception fetching certificates:");
            e.printStackTrace();
        }
    }
    // exception, forget previous values
    lastModified = 0;
    certs = Collections.emptySet();
    return certs;
}