/** * Obtain a URLConnection for a given URL. Ensure proxy servers are considered and page caching is * ignored. * * @param source the non-null URL from which to obtain a URLConnection. * @return URLConnection to the source URL. * @throws IllegalStateException if source is null. * @throws IOException if a connection to the URL can't be opened. */ public static URLConnection getURLConnection(URL source) throws IOException { if (source == null) { throw new IllegalStateException("getURLConnection was given a null 'source' argument."); } Proxy cytoProxy = ProxyHandler.getProxyServer(); URLConnection uc = null; if (cytoProxy == null) { uc = source.openConnection(); } else { try { uc = source.openConnection(cytoProxy); } catch (UnsupportedOperationException e) { // This happens when we have a URL whose // protocol handler doesn't take a proxy // argument (such as a URL referring to inside // a jar file). In this case, just use the // normal way to open a connection: uc = source.openConnection(); } } uc.setUseCaches(false); // don't use a cached page uc.setConnectTimeout(msConnectionTimeout); // set timeout for connection return uc; }