Index: src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java =================================================================== --- src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java (revision 1165764) +++ src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java (working copy) @@ -105,7 +105,7 @@ throw new IllegalArgumentException("Scheme registry amy not be null"); } this.schemeRegistry = schemes; - this.dnsResolver = null; + this.dnsResolver = new SystemDefaultDnsResolver(); } /** @@ -120,8 +120,12 @@ public DefaultClientConnectionOperator(final SchemeRegistry schemes,final DnsResolver dnsResolver) { if (schemes == null) { throw new IllegalArgumentException( - "Scheme registry amy not be null"); + "Scheme registry may not be null"); } + + if(dnsResolver == null){ + throw new IllegalArgumentException("DNS resolver may not be null"); + } this.schemeRegistry = schemes; this.dnsResolver = dnsResolver; @@ -256,24 +260,19 @@ /** * Resolves the given host name to an array of corresponding IP addresses, based on the - * configured name service on the system. + * configured name service on the provided DNS resolver. If one wasn't provided, the system + * configuration is used. * - * If a custom DNS resolver is provided, the given host will be searched in - * it first. If the host is not configured, the default OS DNS-lookup - * mechanism is used. - * * @param host host name to resolve * @return array of IP addresses * @exception UnknownHostException if no IP address for the host could be determined. * + * @see {@link DnsResolver} + * @see {@link SystemDefaultDnsResolver} * @since 4.1 */ protected InetAddress[] resolveHostname(final String host) throws UnknownHostException { - if (dnsResolver != null) { return dnsResolver.resolve(host); - } else { - return InetAddress.getAllByName(host); - } } } Index: src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java =================================================================== --- src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java (revision 1165764) +++ src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java (working copy) @@ -101,7 +101,7 @@ throw new IllegalArgumentException("Scheme registry may not be null"); } this.schemeRegistry = schemeRegistry; - this.dnsResolver = null; + this.dnsResolver = new SystemDefaultDnsResolver(); this.operator = createConnectionOperator(schemeRegistry); this.pool = new HttpConnPool(this.log, 2, 20, timeToLive, tunit); } @@ -114,7 +114,7 @@ throw new IllegalArgumentException("Scheme registry may not be null"); } this.schemeRegistry = schemeRegistry; - this.dnsResolver = dnsResolver; + this.dnsResolver = new SystemDefaultDnsResolver(); this.operator = createConnectionOperator(schemeRegistry); this.pool = new HttpConnPool(this.log, 2, 20, timeToLive, tunit); } @@ -141,7 +141,7 @@ * @return the connection operator to use */ protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg) { - return new DefaultClientConnectionOperator(schreg, this.dnsResolver); + return new DefaultClientConnectionOperator(schreg, this.dnsResolver); } public SchemeRegistry getSchemeRegistry() { Index: src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java =================================================================== --- src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java (revision 0) +++ src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java (revision 0) @@ -0,0 +1,47 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.http.impl.conn; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.apache.http.conn.DnsResolver; + +/** + * DNS resolver that uses the default OS implementation for resolving host names. + * + */ +public class SystemDefaultDnsResolver implements DnsResolver { + + /** + * {@inheritDoc} + */ + public InetAddress[] resolve(String host) throws UnknownHostException { + return InetAddress.getAllByName(host); + } + +} Index: src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java =================================================================== --- src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java (revision 1165764) +++ src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java (working copy) @@ -64,6 +64,17 @@ SchemeRegistryFactory.createDefault(), dnsResolver); operator.resolveHostname("unknown.example.com"); } + + @Test + public void testDefaultLocalHost(){ + DefaultClientConnectionOperator operator = new DefaultClientConnectionOperator( + SchemeRegistryFactory.createDefault()); + try{ + operator.resolveHostname("localhost"); + } catch(Exception e){ + Assert.fail("No exception should be thrown " + e); + } + } private InetAddress[] translateIp(String ip) throws UnknownHostException { String[] ipParts = ip.split("\\.");