oglueck     2003/01/16 05:28:40

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HostConfiguration.java HttpClient.java
                        HttpConnection.java HttpConstants.java
                        MultiThreadedHttpConnectionManager.java
                        SimpleHttpConnectionManager.java
  Added:       httpclient/src/java/org/apache/commons/httpclient/protocol
                        DefaultProtocolSocketFactory.java Protocol.java
                        ProtocolSocketFactory.java
                        SSLProtocolSocketFactory.java
                        SecureProtocolSocketFactory.java
  Removed:     httpclient/src/java/org/apache/commons/httpclient
                        Protocol.java
  Log:
  - HttpClient has now only two compile-time dependencies on Java 1.4
    org.apache.commons.httpclient.NTML.java
    org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.java
  - HttpClient should again be runnable on Java 1.2.2
  - All protocol related classes moved to org.apache.commons.httpclient.protocol 
package
  - all references to java.lang.RuntimeException.RuntimeException(java.lang.Throwable) 
removed
  
  Revision  Changes    Path
  1.5       +5 -3      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java
  
  Index: HostConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HostConfiguration.java    17 Dec 2002 01:36:41 -0000      1.4
  +++ HostConfiguration.java    16 Jan 2003 13:28:39 -0000      1.5
  @@ -61,6 +61,8 @@
    */
   package org.apache.commons.httpclient;
   
  +import org.apache.commons.httpclient.protocol.Protocol;
  +
   
   /**
    *
  
  
  
  1.66      +5 -4      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
  
  Index: HttpClient.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- HttpClient.java   19 Dec 2002 10:23:34 -0000      1.65
  +++ HttpClient.java   16 Jan 2003 13:28:39 -0000      1.66
  @@ -65,6 +65,7 @@
   import java.io.IOException;
   import java.net.URL;
   
  +import org.apache.commons.httpclient.protocol.Protocol;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  
  
  
  1.31      +15 -13    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- HttpConnection.java       16 Jan 2003 10:53:08 -0000      1.30
  +++ HttpConnection.java       16 Jan 2003 13:28:39 -0000      1.31
  @@ -62,10 +62,6 @@
   
   package org.apache.commons.httpclient;
   
  -import org.apache.commons.httpclient.util.TimeoutController;
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
  @@ -73,8 +69,13 @@
   import java.net.Socket;
   import java.net.SocketException;
   
  -import javax.net.SocketFactory;
  -import javax.net.ssl.SSLSocketFactory;
  +import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory;
  +import org.apache.commons.httpclient.protocol.Protocol;
  +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
  +import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
  +import org.apache.commons.httpclient.util.TimeoutController;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   
   
  @@ -435,10 +436,10 @@
                   
                   _usingSecureSocket = isSecure() && !isProxied();                
                   
  -                final SocketFactory socketFactory = (
  +                final ProtocolSocketFactory socketFactory = (
                       isSecure() && !isProxied()
                       ? _protocol.getSocketFactory()
  -                    : SocketFactory.getDefault()
  +                    : new DefaultProtocolSocketFactory()
                   );
                   
                   if (connect_timeout == 0) {
  @@ -496,7 +497,8 @@
               throw new IllegalStateException("Already using a secure socket");
           }
   
  -        SSLSocketFactory socketFactory = 
(SSLSocketFactory)_protocol.getSocketFactory();
  +        SecureProtocolSocketFactory socketFactory = (SecureProtocolSocketFactory)
  +            _protocol.getSocketFactory();
   
           _socket = socketFactory.createSocket(_socket, _host, _port, true);
           _input = _socket.getInputStream();
  
  
  
  1.2       +6 -6      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java
  
  Index: HttpConstants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpConstants.java        16 Jan 2003 10:53:08 -0000      1.1
  +++ HttpConstants.java        16 Jan 2003 13:28:39 -0000      1.2
  @@ -248,7 +248,7 @@
           try {
               return data.getBytes("US-ASCII");
           } catch (UnsupportedEncodingException e) {
  -            throw new RuntimeException(e);
  +            throw new RuntimeException("HTTP client requires ASCII support");
           }
       }
   
  @@ -265,9 +265,9 @@
           }
   
           try {
  -            return new String(data, HTTP_ELEMENT_CHARSET);
  +            return new String(data, "US-ASCII");
           } catch (UnsupportedEncodingException e) {
  -            throw new RuntimeException(e);
  +            throw new RuntimeException("HTTP client requires ASCII support");
           }
       }
   }
  
  
  
  1.4       +4 -3      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java
  
  Index: MultiThreadedHttpConnectionManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultiThreadedHttpConnectionManager.java   16 Dec 2002 03:51:04 -0000      1.3
  +++ MultiThreadedHttpConnectionManager.java   16 Jan 2003 13:28:39 -0000      1.4
  @@ -70,6 +70,7 @@
   import java.util.LinkedList;
   import java.util.Map;
   
  +import org.apache.commons.httpclient.protocol.Protocol;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  
  
  
  1.5       +5 -3      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java
  
  Index: SimpleHttpConnectionManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleHttpConnectionManager.java  17 Dec 2002 01:36:41 -0000      1.4
  +++ SimpleHttpConnectionManager.java  16 Jan 2003 13:28:39 -0000      1.5
  @@ -65,6 +65,8 @@
   import java.io.InputStream;
   import java.io.IOException;
   
  +import org.apache.commons.httpclient.protocol.Protocol;
  +
   
   /**
    * A connection manager that provides access to a single HttpConnection.  This
  
  
  
  1.1                  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java
  
  Index: DefaultProtocolSocketFactory.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.commons.httpclient.protocol;
  
  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.Socket;
  import java.net.UnknownHostException;
  
  /**
   * The default class for creating protocol sockets.  This class just uses the
   * Protocol constructors.
   * 
   * @author Michael Becke
   * 
   * @since 2.0
   */
  public class DefaultProtocolSocketFactory implements ProtocolSocketFactory {
  
      /**
       * Constructor for DefaultProtocolSocketFactory.
       */
      public DefaultProtocolSocketFactory() {
          super();
      }
  
      /**
       * @see 
org.apache.commons.httpclient.ProtocolSocketFactory#createSocket(java.lang.String, 
int, java.net.InetAddress, int)
       */
      public Socket createSocket(
          String host,
          int port,
          InetAddress clientHost,
          int clientPort
      ) throws IOException, UnknownHostException {
          return new Socket(host, port, clientHost, clientPort);
      }
  
      /**
       * @see 
org.apache.commons.httpclient.ProtocolSocketFactory#createSocket(java.lang.String, int)
       */
      public Socket createSocket(String host, int port)
          throws IOException, UnknownHostException {
          return new Socket(host, port);
      }
  
  }
  
  
  
  1.1                  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java
  
  Index: Protocol.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java,v
 1.1 2003/01/16 13:28:40 oglueck Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/16 13:28:40 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  package org.apache.commons.httpclient.protocol;
  
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * A class to encapsulate the specifics of a protocol.  This class class also
   * provides the ability to customize the set and characteristics of the
   * protocols used.
   * 
   * <p>One use case for modifying the default set of protocols would be to set a
   * custom SSL socket factory.  This would look something like the following:
   * <pre> 
   * Protocol myHTTPS = new Protocol( "https", new MySSLSocketFactory(), 443 );
   * 
   * Protocol.registerProtocol( "https", myHTTPS );
   * </pre>
   *
   * @author Michael Becke 
   * @author Jeff Dever
   *  
   * @since 2.0 
   */
  public class Protocol {
  
      private static Map protocols = Collections.synchronizedMap( new HashMap() );
  
      /**
       * Registers a new protocol with the given identifier.  If a protocol with
       * the given ID already exists it will be overridden.  This ID is the same
       * one used to retrieve the protocol from getProtocol(String).
       * 
       * @param id the identifier for this protocol
       * @param protocol the protocol to register
       * 
       * @see #getProtocol(String)
       */
      public static void registerProtocol( String id, Protocol protocol ) {
  
          if ( id == null ) {
              throw new IllegalArgumentException( "id is null" );
          }
          if ( protocol == null ) {
              throw new IllegalArgumentException( "protocol is null" );
          }
  
          protocols.put( id, protocol );
  
      }
  
      /**
       * Unregisters the protocol with the given ID.
       * 
       * @param id the ID of the protocol to remove
       */
      public static void unregisterProtocol( String id ) {
  
          if ( id == null ) {
              throw new IllegalArgumentException( "id is null" );
          }
  
          protocols.remove( id );
  
      }
  
      /**
       * Gets the protocol with the given ID.
       * 
       * @param id the protocol ID
       * 
       * @return Protocol a protocol
       * 
       * @throws IllegalStateException if a protocol with the ID cannot be found
       */
      public static Protocol getProtocol( String id ) {
  
          if ( id == null ) {
              throw new IllegalArgumentException( "id is null" );
          }
  
          Protocol protocol = (Protocol)protocols.get( id );
  
          if ( protocol == null ) {
              protocol = lazyRegisterProtocol(id);
          }
  
          return protocol;
  
      } 
  
      /**
       * Lazily registers the protocol with the given id.
       * 
       * @param id the protocol ID
       * 
       * @return the lazily registered protocol
       * 
       * @throws IllegalStateException if the protocol with id is not recognized
       */
      private static Protocol lazyRegisterProtocol(String id) {
  
          if ("http".equals(id)) {
              Protocol HTTP = new Protocol(
                      "http",
                      new DefaultProtocolSocketFactory(),
                      80
                      );
              Protocol.registerProtocol( "http", HTTP );
              return HTTP;
          }
  
          if ("https".equals(id)) {
              Protocol HTTPS = new Protocol(
                      "https",
                      new SSLProtocolSocketFactory(),
                      443
                      );
              Protocol.registerProtocol( "https", HTTPS );
              return HTTPS;
          }
  
          throw new IllegalStateException( "unsupported protocol: '" + id + "'");
  
      }
      
  
      /** the scheme of this protocol (e.g. http, https) */
      private String scheme;
      
      private ProtocolSocketFactory socketFactory;
      
      private int defaultPort;
      
      private boolean secure;
    
      /**
       * Constructs a new Protocol.  The created protcol is insecure.
       * 
       * @param scheme the scheme (e.g. http, https)
       * @param factory the factory for creating sockets for communication using
       * this protocol
       * @param defaultPort the port this protocol defaults to
       */
      public Protocol( String scheme, ProtocolSocketFactory factory, int defaultPort ) 
{
          
          if ( scheme == null ) {
              throw new IllegalArgumentException( "scheme is null" );
          }
          if ( factory == null ) {
              throw new IllegalArgumentException( "socketFactory is null" );
          }
          if ( defaultPort <= 0 ) {
              throw new IllegalArgumentException( "port is invalid: " + defaultPort );
          }
          
          this.scheme = scheme;
          this.socketFactory = factory;
          this.defaultPort = defaultPort;
          this.secure = false;
          
      }
      
      /**
       * Constructs a new Protocol.  The created protcol is secure.
       *
       * @param scheme the scheme (e.g. http, https)
       * @param factory the factory for creating sockets for communication using
       * this protocol
       * @param defaultPort the port this protocol defaults to
       */
      public Protocol( String scheme, SecureProtocolSocketFactory factory, int 
defaultPort ) {
          
          if ( scheme == null ) {
              throw new IllegalArgumentException( "scheme is null" );
          }
          if ( factory == null ) {
              throw new IllegalArgumentException( "socketFactory is null" );
          }
          if ( defaultPort <= 0 ) {
              throw new IllegalArgumentException( "port is invalid: " + defaultPort );
          }
  
          this.scheme = scheme;
          this.socketFactory = factory;
          this.defaultPort = defaultPort;
          this.secure = true;        
          
      }
  
      /**
       * Returns the defaultPort.
       * @return int
       */
      public int getDefaultPort() {
          return defaultPort;
      }
  
      /**
       * Returns the socketFactory.  If secure the factory is a
       * SecureProtocolSocketFactory.
       * @return SocketFactory
       */
      public ProtocolSocketFactory getSocketFactory() {
          return socketFactory;
      }
  
      /**
       * Returns the scheme.
       * @return String
       */
      public String getScheme() {
          return scheme;
      }
  
      /**
       * Returns the secure.
       * @return boolean
       */
      public boolean isSecure() {
          return secure;
      }
      
      /**
       * Resolves the correct port for this protocol.  Returns the given port if
       * valid or the default port otherwise.
       * 
       * @param port the port to be resolved
       * 
       * @return the given port or the defaultPort
       */
      public int resolvePort( int port ) {
          return port <= 0 ? getDefaultPort() : port;
      }
  
      /**
       * @see java.lang.Object#toString()
       */
      public String toString() {
          return scheme + ":" + defaultPort;
      }
      
  }
  
  
  
  1.1                  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java
  
  Index: ProtocolSocketFactory.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.commons.httpclient.protocol;
  
  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.Socket;
  import java.net.UnknownHostException;
  
  /**
   * A factory for creating Sockets.
   * 
   * @see org.apache.commons.httpclient.Protocol
   * 
   * @author Michael Becke
   * 
   * @since 2.0
   */
  public interface ProtocolSocketFactory {
  
      /**
       * Gets a new socket connection to the given host.
       * 
       * @param host the host name/IP
       * @param port the port on the host
       * @param clientHost the local host name/IP to bind the socket to
       * @param clientPort the port on the local machine
       * 
       * @return Socket a new socket
       * 
       * @throws IOException if an I/O error occurs while creating the socket
       * @throws UnknownHostException if the IP address of the host cannot be
       * determined
       */
      public Socket createSocket(
          String host, 
          int port, 
          InetAddress clientHost, 
          int clientPort
      ) throws IOException, UnknownHostException;
  
      /**
       * Gets a new socket connection to the given host.
       *
       * @param host the host name/IP
       * @param port the port on the host
       *
       * @return Socket a new socket
       *
       * @throws IOException if an I/O error occurs while creating the socket
       * @throws UnknownHostException if the IP address of the host cannot be
       * determined
       */
      public Socket createSocket(
          String host, 
          int port
      ) throws IOException, UnknownHostException;
  
  }
  
  
  
  1.1                  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java
  
  Index: SSLProtocolSocketFactory.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.commons.httpclient.protocol;
  
  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.Socket;
  import java.net.UnknownHostException;
  
  import javax.net.ssl.SSLSocketFactory;
  
  /**
   * A SecureProtocolSocketFactory that uses JSSE to create sockets.
   * 
   * @author Michael Becke
   * 
   * @since 2.0
   */
  public class SSLProtocolSocketFactory implements SecureProtocolSocketFactory {
  
      /**
       * Constructor for SSLProtocolSocketFactory.
       */
      public SSLProtocolSocketFactory() {
          super();
      }
  
      /**
       * @see 
org.apache.commons.httpclient.ProtocolSocketFactory#createSocket(java.lang.String, 
int, java.net.InetAddress, int)
       */
      public Socket createSocket(
          String host,
          int port,
          InetAddress clientHost,
          int clientPort)
          throws IOException, UnknownHostException {
          return SSLSocketFactory.getDefault().createSocket(
              host,
              port,
              clientHost,
              clientPort
          );
      }
  
      /**
       * @see 
org.apache.commons.httpclient.ProtocolSocketFactory#createSocket(java.lang.String, int)
       */
      public Socket createSocket(String host, int port)
          throws IOException, UnknownHostException {
          return SSLSocketFactory.getDefault().createSocket(
              host,
              port
          );
      }
  
      /**
       * @see 
org.apache.commons.httpclient.SecureProtocolSocketFactory#createSocket(java.net.Socket,
 java.lang.String, int, boolean)
       */
      public Socket createSocket(
          Socket socket,
          String host,
          int port,
          boolean autoClose)
          throws IOException, UnknownHostException {
          return ((SSLSocketFactory)SSLSocketFactory.getDefault()).createSocket(
              socket,
              host,
              port,
              autoClose
          );
      }
  
  }
  
  
  
  1.1                  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.java
  
  Index: SecureProtocolSocketFactory.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.commons.httpclient.protocol;
  
  import java.io.IOException;
  import java.net.Socket;
  import java.net.UnknownHostException;
  
  /**
   * A ProtocolSocketFactory that is secure.
   * 
   * @see org.apache.commons.httpclient.protocol.ProtocolSocketFactory
   * 
   * @author Michael Becke
   * 
   * @since 2.0
   */
  public interface SecureProtocolSocketFactory extends ProtocolSocketFactory {
  
      /**
       * Returns a socket connected to the given host that is layered over an
       * existing socket.  Used primarily for creating secure sockets through
       * proxies.
       * 
       * @param socket the existing socket 
       * @param host the host name/IP
       * @param port the port on the host
       * @param autoClose a flag for closing the underling socket when the created
       * socket is closed
       * 
       * @return Socket a new socket
       * 
       * @throws IOException if an I/O error occurs while creating the socket
       * @throws UnknownHostException if the IP address of the host cannot be
       * determined
       */
      public Socket createSocket(
          Socket socket, 
          String host, 
          int port, 
          boolean autoClose
      ) throws IOException, UnknownHostException;              
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to