Return-Path: Delivered-To: apmail-jakarta-httpclient-commits-archive@www.apache.org Received: (qmail 40820 invoked from network); 3 Apr 2005 18:36:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Apr 2005 18:36:40 -0000 Received: (qmail 8744 invoked by uid 500); 3 Apr 2005 18:36:39 -0000 Mailing-List: contact httpclient-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpclient-dev@jakarta.apache.org Delivered-To: mailing list httpclient-commits@jakarta.apache.org Received: (qmail 8729 invoked by uid 500); 3 Apr 2005 18:36:39 -0000 Delivered-To: apmail-jakarta-httpclient-cvs@jakarta.apache.org Received: (qmail 8721 invoked by uid 99); 3 Apr 2005 18:36:39 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 03 Apr 2005 11:36:39 -0700 Received: (qmail 40817 invoked by uid 65534); 3 Apr 2005 18:36:38 -0000 Message-ID: <20050403183638.40816.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Sun, 03 Apr 2005 18:36:38 -0000 Subject: svn commit: r159951 - in jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl: DefaultProtocolSocketFactory.java NIOProtocolSocketFactory.java OldIOProtocolSocketFactory.java To: httpclient-cvs@jakarta.apache.org From: olegk@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Sun Apr 3 11:36:37 2005 New Revision: 159951 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D159951 Log: Provided NIO and old IO versions of the default protocol socket factory Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOP= rotocolSocketFactory.java - copied, changed from r159764, jakarta/httpclient/trunk/http-common/= src/java/org/apache/http/impl/DefaultProtocolSocketFactory.java jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldI= OProtocolSocketFactory.java (with props) Removed: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Defa= ultProtocolSocketFactory.java Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/= NIOProtocolSocketFactory.java (from r159764, jakarta/httpclient/trunk/http-= common/src/java/org/apache/http/impl/DefaultProtocolSocketFactory.java) URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src= /java/org/apache/http/impl/NIOProtocolSocketFactory.java?view=3Ddiff&rev=3D= 159951&p1=3Djakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/DefaultProtocolSocketFactory.java&r1=3D159764&p2=3Djakarta/httpclient/t= runk/http-common/src/java/org/apache/http/impl/NIOProtocolSocketFactory.jav= a&r2=3D159951 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Defa= ultProtocolSocketFactory.java (original) +++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOP= rotocolSocketFactory.java Sun Apr 3 11:36:37 2005 @@ -48,38 +48,30 @@ *=20 * @since 2.0 */ -public class DefaultProtocolSocketFactory implements ProtocolSocketFactory= { +public class NIOProtocolSocketFactory implements ProtocolSocketFactory { =20 /** * The factory singleton. */ - private static final DefaultProtocolSocketFactory factory =3D new Defa= ultProtocolSocketFactory(); + private static final NIOProtocolSocketFactory factory =3D new NIOProto= colSocketFactory(); =20 /** * Gets an singleton instance of the DefaultProtocolSocketFactory. * @return a DefaultProtocolSocketFactory */ - public static DefaultProtocolSocketFactory getSocketFactory() { + public static NIOProtocolSocketFactory getSocketFactory() { return factory; } =20 /** * Constructor for DefaultProtocolSocketFactory. */ - private DefaultProtocolSocketFactory() { + private NIOProtocolSocketFactory() { super(); } =20 /** * Attempts to get a new socket connection to the given host within th= e given time limit. - *

- * This method employs several techniques to circumvent the limitation= s of older JREs that=20 - * do not support connect timeout. When running in JRE 1.4 or above re= flection is used to=20 - * call Socket#connect(SocketAddress endpoint, int timeout) method. Wh= en executing in older=20 - * JREs a controller thread is executed. The controller thread attempt= s to create a new socket - * within the given limit of time. If socket constructor does not retu= rn until the timeout=20 - * expires, the controller terminates and throws an {@link ConnectTime= outException} - *

* =20 * @param host the host name/IP * @param port the port on the host @@ -121,14 +113,14 @@ * All instances of DefaultProtocolSocketFactory are the same. */ public boolean equals(Object obj) { - return ((obj !=3D null) && obj.getClass().equals(DefaultProtocolSo= cketFactory.class)); + return ((obj !=3D null) && obj.getClass().equals(NIOProtocolSocket= Factory.class)); } =20 /** * All instances of DefaultProtocolSocketFactory have the same hash co= de. */ public int hashCode() { - return DefaultProtocolSocketFactory.class.hashCode(); + return NIOProtocolSocketFactory.class.hashCode(); } =20 } Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/O= ldIOProtocolSocketFactory.java URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src= /java/org/apache/http/impl/OldIOProtocolSocketFactory.java?view=3Dauto&rev= =3D159951 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldI= OProtocolSocketFactory.java (added) +++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldI= OProtocolSocketFactory.java Sun Apr 3 11:36:37 2005 @@ -0,0 +1,127 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * Copyright 2002-2004 The Apache Software Foundation + * + * Licensed 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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * 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; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; +import java.net.UnknownHostException; + +import org.apache.http.ProtocolSocketFactory; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; + +/** + * The default class for creating protocol sockets. This class just uses = the + * {@link java.net.Socket socket} constructors. + *=20 + * @author Michael Becke + *=20 + * @since 2.0 + */ +public class OldIOProtocolSocketFactory implements ProtocolSocketFactory { + + /** + * The factory singleton. + */ + private static final OldIOProtocolSocketFactory factory =3D new OldIOP= rotocolSocketFactory(); + =20 + /** + * Gets an singleton instance of the DefaultProtocolSocketFactory. + * @return a DefaultProtocolSocketFactory + */ + public static OldIOProtocolSocketFactory getSocketFactory() { + return factory; + } + =20 + /** + * Constructor for DefaultProtocolSocketFactory. + */ + private OldIOProtocolSocketFactory() { + super(); + } + + /** + * Attempts to get a new socket connection to using old (pre Java 1.4)= IO mode. + * This socket factory does not support connect timeout as it requires= Java 1.4 + * functionality. + * =20 + * @param host the host name/IP + * @param port the port on the host + * @param localAddress the local host name/IP to bind the socket to + * @param localPort the port on the local machine + * @param params {@link HttpConnectionParams Http connection parameter= s} + *=20 + * @return Socket a new socket + *=20 + * @throws IOException if an I/O error occurs while creating the socket + * @throws UnknownHostException if the IP address of the host cannot be + * @throws IllegalStateException if connection timeout is set + * determined + *=20 + * @since 3.0 + */ + public Socket createSocket( + final String host, + final int port, + final InetAddress localAddress, + final int localPort, + final HttpParams params + ) throws IOException, UnknownHostException { + if (params =3D=3D null) { + throw new IllegalArgumentException("Parameters may not be null= "); + } + HttpConnectionParams connparams =3D new HttpConnectionParams(param= s);=20 + int timeout =3D connparams.getConnectionTimeout(); + if (timeout !=3D 0) { + throw new IllegalStateException("Connection timeout is not sup= ported in old IO mode"); + } + if (localAddress !=3D null) { + return new Socket(host, port, localAddress, localPort); + } else { + return new Socket(host, port); + } + } + + /** + * All instances of DefaultProtocolSocketFactory are the same. + */ + public boolean equals(Object obj) { + return ((obj !=3D null) && obj.getClass().equals(OldIOProtocolSock= etFactory.class)); + } + + /** + * All instances of DefaultProtocolSocketFactory have the same hash co= de. + */ + public int hashCode() { + return OldIOProtocolSocketFactory.class.hashCode(); + } + +} Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/OldIOProtocolSocketFactory.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/OldIOProtocolSocketFactory.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/OldIOProtocolSocketFactory.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain