Return-Path: Delivered-To: apmail-hc-commits-archive@www.apache.org Received: (qmail 93984 invoked from network); 22 May 2008 18:34:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 May 2008 18:34:12 -0000 Received: (qmail 15087 invoked by uid 500); 22 May 2008 18:34:14 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 15065 invoked by uid 500); 22 May 2008 18:34:13 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 15056 invoked by uid 99); 22 May 2008 18:34:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 May 2008 11:34:13 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 May 2008 18:33:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 19C1F2388A1F; Thu, 22 May 2008 11:33:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r659194 - in /httpcomponents/httpclient/trunk: ./ module-client/src/main/java/org/apache/http/conn/scheme/ module-client/src/main/java/org/apache/http/conn/ssl/ Date: Thu, 22 May 2008 18:33:48 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080522183349.19C1F2388A1F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Thu May 22 11:33:47 2008 New Revision: 659194 URL: http://svn.apache.org/viewvc?rev=659194&view=rev Log: HTTPCLIENT-670: Pluggable hostname resolver Added: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=659194&r1=659193&r2=659194&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original) +++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu May 22 11:33:47 2008 @@ -1,6 +1,9 @@ Changes since 4.0 Alpha 4 ------------------- +* [HTTPCLIENT-670] Pluggable hostname resolver. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-719] Clone support for HTTP request and cookie objects. Contributed by Oleg Kalnichevski Added: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java?rev=659194&view=auto ============================================================================== --- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java (added) +++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/HostNameResolver.java Thu May 22 11:33:47 2008 @@ -0,0 +1,41 @@ +/* + * $HeadURL:$ + * $Revision:$ + * $Date:$ + * + * ==================================================================== + * 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.conn.scheme; + +import java.io.IOException; +import java.net.InetAddress; + +public interface HostNameResolver { + + InetAddress resolve (String hostname) throws IOException; + +} Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java?rev=659194&r1=659193&r2=659194&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java (original) +++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java Thu May 22 11:33:47 2008 @@ -53,6 +53,8 @@ private static final PlainSocketFactory DEFAULT_FACTORY = new PlainSocketFactory(); + private final HostNameResolver nameResolver; + /** * Gets the singleton instance of this class. * @return the one and only plain socket factory @@ -61,14 +63,16 @@ return DEFAULT_FACTORY; } - /** - * Restricted default constructor. - */ - private PlainSocketFactory() { + public PlainSocketFactory(final HostNameResolver nameResolver) { super(); + this.nameResolver = nameResolver; } + public PlainSocketFactory() { + this(null); + } + // non-javadoc, see interface org.apache.http.conn.SocketFactory public Socket createSocket() { return new Socket(); @@ -103,7 +107,14 @@ int timeout = HttpConnectionParams.getConnectionTimeout(params); - sock.connect(new InetSocketAddress(host, port), timeout); + InetSocketAddress remoteAddress; + if (this.nameResolver != null) { + remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port); + } else { + remoteAddress = new InetSocketAddress(host, port); + } + + sock.connect(remoteAddress, timeout); return sock; Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java?rev=659194&r1=659193&r2=659194&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java (original) +++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java Thu May 22 11:33:47 2008 @@ -31,6 +31,7 @@ package org.apache.http.conn.ssl; +import org.apache.http.conn.scheme.HostNameResolver; import org.apache.http.conn.scheme.LayeredSocketFactory; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; @@ -164,6 +165,7 @@ private final SSLContext sslcontext; private final javax.net.ssl.SSLSocketFactory socketfactory; + private final HostNameResolver nameResolver; private X509HostnameVerifier hostnameVerifier = BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; public SSLSocketFactory( @@ -171,7 +173,8 @@ final KeyStore keystore, final String keystorePassword, final KeyStore truststore, - final SecureRandom random) + final SecureRandom random, + final HostNameResolver nameResolver) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(); @@ -189,6 +192,7 @@ this.sslcontext = SSLContext.getInstance(algorithm); this.sslcontext.init(keymanagers, trustmanagers, random); this.socketfactory = this.sslcontext.getSocketFactory(); + this.nameResolver = nameResolver; } public SSLSocketFactory( @@ -197,19 +201,19 @@ final KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { - this(TLS, keystore, keystorePassword, truststore, null); + this(TLS, keystore, keystorePassword, truststore, null, null); } public SSLSocketFactory(final KeyStore keystore, final String keystorePassword) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { - this(TLS, keystore, keystorePassword, null, null); + this(TLS, keystore, keystorePassword, null, null, null); } public SSLSocketFactory(final KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { - this(TLS, null, null, truststore, null); + this(TLS, null, null, truststore, null, null); } /** @@ -221,6 +225,7 @@ super(); this.sslcontext = null; this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory(); + this.nameResolver = null; } private static KeyManager[] createKeyManagers(final KeyStore keystore, final String password) @@ -289,7 +294,14 @@ int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); - sslsock.connect(new InetSocketAddress(host, port), connTimeout); + InetSocketAddress remoteAddress; + if (this.nameResolver != null) { + remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port); + } else { + remoteAddress = new InetSocketAddress(host, port); + } + + sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); try {