You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/09/06 23:27:48 UTC
svn commit: r1165863 - in /httpcomponents/httpclient/trunk/httpclient/src:
main/java/org/apache/http/impl/conn/ test/java/org/apache/http/impl/conn/
Author: olegk
Date: Tue Sep 6 21:27:48 2011
New Revision: 1165863
URL: http://svn.apache.org/viewvc?rev=1165863&view=rev
Log:
HTTPCLIENT-1123: Support for pluggable DNS resolvers (default resolver).
Contributed by Alin Vasile <alinachegalati at yahoo dot com>
Added:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java (with props)
Modified:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java?rev=1165863&r1=1165862&r2=1165863&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java Tue Sep 6 21:27:48 2011
@@ -105,7 +105,7 @@ public class DefaultClientConnectionOper
throw new IllegalArgumentException("Scheme registry amy not be null");
}
this.schemeRegistry = schemes;
- this.dnsResolver = null;
+ this.dnsResolver = new SystemDefaultDnsResolver();
}
/**
@@ -120,7 +120,11 @@ public class DefaultClientConnectionOper
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;
@@ -256,24 +260,19 @@ public class DefaultClientConnectionOper
/**
* Resolves the given host name to an array of corresponding IP addresses, based on the
- * configured name service on the system.
- *
- * 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.
+ * configured name service on the provided DNS resolver. If one wasn't provided, the system
+ * configuration 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);
- }
}
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java?rev=1165863&r1=1165862&r2=1165863&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java Tue Sep 6 21:27:48 2011
@@ -101,7 +101,7 @@ public class PoolingClientConnectionMana
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 @@ public class PoolingClientConnectionMana
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 @@ public class PoolingClientConnectionMana
* @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() {
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java?rev=1165863&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java Tue Sep 6 21:27:48 2011
@@ -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
+ * <http://www.apache.org/>.
+ *
+ */
+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);
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultDnsResolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java?rev=1165863&r1=1165862&r2=1165863&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultClientConnectOperator.java Tue Sep 6 21:27:48 2011
@@ -65,6 +65,13 @@ public class TestDefaultClientConnectOpe
operator.resolveHostname("unknown.example.com");
}
+ @Test
+ public void testDefaultLocalHost() throws Exception {
+ DefaultClientConnectionOperator operator = new DefaultClientConnectionOperator(
+ SchemeRegistryFactory.createDefault());
+ operator.resolveHostname("localhost");
+ }
+
private InetAddress[] translateIp(String ip) throws UnknownHostException {
String[] ipParts = ip.split("\\.");