/** * Returns an HTTPConnection. A cache of connections is kept and first * consulted; only when the cache lookup fails is a new one created * and added to the cache. * * @param url the url * @return an HTTPConnection * @exception ProtocolNotSuppException if the protocol is not supported */ protected HTTPConnection getConnection(URL url) throws ProtocolNotSuppException { // try the cache, using the host name String php = url.getProtocol() + ":" + url.getHost() + ":" + ((url.getPort() != -1) ? url.getPort() : URI.defaultPort(url.getProtocol())); php = php.toLowerCase(); HTTPConnection con = (HTTPConnection) connections.get(php); if (con != null) return con; // Not in cache, so create new one and cache it con = new HTTPConnection(url); connections.put(php, con); return con; }