hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r321379 - in /jakarta/httpclient/trunk/http-common/src: contrib/org/apache/http/contrib/spring/ examples/org/apache/http/examples/ java/org/apache/http/ java/org/apache/http/impl/ java/org/apache/http/io/ test/org/apache/http/
Date Sat, 15 Oct 2005 17:07:32 GMT
Author: olegk
Date: Sat Oct 15 10:07:11 2005
New Revision: 321379

URL: http://svn.apache.org/viewcvs?rev=321379&view=rev
Log:
* Protocol class renamed to Scheme
* Added test cases

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Scheme.java
      - copied, changed from r239377, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Protocol.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java   (with
props)
Removed:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Protocol.java
Modified:
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
    jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
    jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
    jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/ProxyHost.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpProxyConnection.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/SocketFactory.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java

Modified: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
Sat Oct 15 10:07:11 2005
@@ -34,7 +34,7 @@
 import org.apache.http.HttpRequestFactory;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
-import org.apache.http.Protocol;
+import org.apache.http.Scheme;
 import org.apache.http.entity.EntityConsumer;
 import org.apache.http.executor.HttpRequestExecutor;
 import org.apache.http.params.HttpParams;
@@ -63,7 +63,7 @@
         HttpRequestExecutor httpexec = (HttpRequestExecutor)beanfactory.getBean("http-executor");
         httpexec.setParams(params);
         
-        Protocol http = (Protocol) beanfactory.getBean("http-protocol");
+        Scheme http = (Scheme) beanfactory.getBean("http-protocol");
         HttpHost host = new HttpHost("www.yahoo.com", 80, http);
 
         HttpRequestFactory requestfactory = (HttpRequestFactory) beanfactory.getBean("http-request-factory");

Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
Sat Oct 15 10:07:11 2005
@@ -33,7 +33,7 @@
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
-import org.apache.http.Protocol;
+import org.apache.http.Scheme;
 import org.apache.http.entity.EntityConsumer;
 import org.apache.http.impl.DefaultHttpClientConnection;
 import org.apache.http.impl.DefaultHttpParams;
@@ -54,7 +54,7 @@
     public static void main(String[] args) throws Exception {
         
         SocketFactory socketfactory = PlainSocketFactory.getSocketFactory();
-        Protocol.registerProtocol("http", new Protocol("http", socketfactory, 80));
+        Scheme.registerScheme("http", new Scheme("http", socketfactory, 80));
         
         HttpParams connparams = new DefaultHttpParams(null);
         HttpHost host = new HttpHost("www.yahoo.com");

Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpPost.java
Sat Oct 15 10:07:11 2005
@@ -36,7 +36,7 @@
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
-import org.apache.http.Protocol;
+import org.apache.http.Scheme;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.entity.EntityConsumer;
 import org.apache.http.entity.InputStreamEntity;
@@ -60,7 +60,7 @@
     public static void main(String[] args) throws Exception {
         
         SocketFactory socketfactory = PlainSocketFactory.getSocketFactory();
-        Protocol.registerProtocol("http", new Protocol("http", socketfactory, 80));
+        Scheme.registerScheme("http", new Scheme("http", socketfactory, 80));
 
         HttpParams connparams = new DefaultHttpParams(null);
         HttpHost host = new HttpHost("localhost", 8080);

Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java
Sat Oct 15 10:07:11 2005
@@ -33,7 +33,7 @@
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
-import org.apache.http.Protocol;
+import org.apache.http.Scheme;
 import org.apache.http.entity.EntityConsumer;
 import org.apache.http.executor.HttpRequestExecutor;
 import org.apache.http.impl.DefaultHttpClientConnection;
@@ -61,7 +61,7 @@
     public static void main(String[] args) throws Exception {
         
         SocketFactory socketfactory = PlainSocketFactory.getSocketFactory();
-        Protocol.registerProtocol("http", new Protocol("http", socketfactory, 80));
+        Scheme.registerScheme("http", new Scheme("http", socketfactory, 80));
         
         HttpParams params = new DefaultHttpParams(null);
         HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java Sat Oct 15
10:07:11 2005
@@ -34,7 +34,7 @@
 
 /**
  * Holds all of the variables needed to describe an HTTP connection to a host. This includes

- * remote host, port and protocol.
+ * remote host, port and scheme.
  * 
  * @author <a href="mailto:becke@u.washington.edu">Michael Becke</a>
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
@@ -51,30 +51,30 @@
     /** The port to use. */
     private int port = -1;
 
-    /** The protocol */
-    private Protocol protocol = null;
+    /** The scheme */
+    private Scheme scheme = null;
 
     /**
      * Constructor for HttpHost.
      *   
      * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
-     * @param port the port. Value <code>-1</code> can be used to set default
protocol port
-     * @param protocol the protocol. Value <code>null</code> can be used to set
default protocol
+     * @param port the port. Value <code>-1</code> can be used to set default
scheme port
+     * @param scheme the scheme. Value <code>null</code> can be used to set default
scheme
      */
-    public HttpHost(final String hostname, int port, final Protocol protocol) {
+    public HttpHost(final String hostname, int port, final Scheme scheme) {
         super();
         if (hostname == null) {
             throw new IllegalArgumentException("Host name may not be null");
         }
-        if (protocol == null) {
+        if (scheme == null) {
             throw new IllegalArgumentException("Protocol may not be null");
         }
         this.hostname = hostname;
-        this.protocol = protocol;
+        this.scheme = scheme;
         if (port >= 0) {
             this.port = port;
         } else {
-            this.port = this.protocol.getDefaultPort();
+            this.port = this.scheme.getDefaultPort();
         }
     }
 
@@ -82,10 +82,10 @@
      * Constructor for HttpHost.
      *   
      * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
-     * @param port the port. Value <code>-1</code> can be used to set default
protocol port
+     * @param port the port. Value <code>-1</code> can be used to set default
scheme port
      */
     public HttpHost(final String hostname, int port) {
-        this(hostname, port, Protocol.getProtocol("http"));
+        this(hostname, port, Scheme.getScheme("http"));
     }
     
     /**
@@ -94,7 +94,7 @@
      * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
      */
     public HttpHost(final String hostname) {
-        this(hostname, -1, Protocol.getProtocol("http"));
+        this(hostname, -1, Scheme.getScheme("http"));
     }
     
     /**
@@ -106,7 +106,7 @@
         super();
         this.hostname = httphost.hostname;
         this.port = httphost.port;
-        this.protocol = httphost.protocol;
+        this.scheme = httphost.scheme;
     }
 
     /**
@@ -135,11 +135,11 @@
     }
 
     /**
-     * Returns the protocol.
-     * @return The protocol.
+     * Returns the scheme.
+     * @return The scheme.
      */
-    public Protocol getProtocol() {
-        return this.protocol;
+    public Scheme getScheme() {
+        return this.scheme;
     }
 
     /**
@@ -149,10 +149,10 @@
      */
     public String toURI() {
     	CharArrayBuffer buffer = new CharArrayBuffer(32);        
-        buffer.append(this.protocol.getScheme());
+        buffer.append(this.scheme.getName());
         buffer.append("://");
         buffer.append(this.hostname);
-        if (this.port != this.protocol.getDefaultPort()) {
+        if (this.port != this.scheme.getDefaultPort()) {
             buffer.append(':');
             buffer.append(Integer.toString(this.port));
         }
@@ -162,7 +162,7 @@
     public String toHostString() {
     	CharArrayBuffer buffer = new CharArrayBuffer(32);        
         buffer.append(this.hostname);
-        if (this.port != this.protocol.getDefaultPort()) {
+        if (this.port != this.scheme.getDefaultPort()) {
             buffer.append(':');
             buffer.append(Integer.toString(this.port));
         }
@@ -186,7 +186,7 @@
             HttpHost that = (HttpHost) obj;
             return this.hostname.equalsIgnoreCase(that.hostname) 
                 && this.port == that.port
-                && this.protocol.equals(that.protocol);
+                && this.scheme.equals(that.scheme);
         } else {
             return false;
         }
@@ -199,7 +199,7 @@
         int hash = LangUtils.HASH_SEED;
         hash = LangUtils.hashCode(hash, this.hostname.toUpperCase());
         hash = LangUtils.hashCode(hash, this.port);
-        hash = LangUtils.hashCode(hash, this.protocol);
+        hash = LangUtils.hashCode(hash, this.scheme);
         return hash;
     }
 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/ProxyHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/ProxyHost.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/ProxyHost.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/ProxyHost.java Sat Oct 15
10:07:11 2005
@@ -55,10 +55,10 @@
      * Constructor for ProxyHost.
      *   
      * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
-     * @param port the port. Value <code>-1</code> can be used to set default
protocol port
+     * @param port the port. Value <code>-1</code> can be used to set default
scheme port
      */
     public ProxyHost(final String hostname, int port) {
-        super(hostname, port, Protocol.getProtocol("http"));
+        super(hostname, port, Scheme.getScheme("http"));
     }
     
     /**

Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Scheme.java (from r239377,
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Protocol.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Scheme.java?p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Scheme.java&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Protocol.java&r1=239377&r2=321379&rev=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Protocol.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Scheme.java Sat Oct 15 10:07:11
2005
@@ -34,19 +34,20 @@
 
 import org.apache.http.io.SecureSocketFactory;
 import org.apache.http.io.SocketFactory;
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.LangUtils;
 
 /**
- * A class to encapsulate the specifics of a protocol.  This class also
+ * A class to encapsulate the specifics of a protocol scheme. This class also
  * provides the ability to customize the set and characteristics of the
- * protocols used.
+ * schemes 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 );
+ * Scheme myHTTPS = new Scheme( "https", new MySSLSocketFactory(), 443 );
  * 
- * Protocol.registerProtocol( "https", myHTTPS );
+ * Scheme.registerScheme( "https", myHTTPS );
  * </pre>
  *
  * @author Michael Becke 
@@ -55,103 +56,99 @@
  *  
  * @since 2.0 
  */
-public class Protocol {
+public class Scheme {
 
-    /** The available protocols */
-    private static final Map PROTOCOLS = Collections.synchronizedMap(new HashMap());
+    /** The available schemes */
+    private static final Map SCHEMES = Collections.synchronizedMap(new HashMap());
 
     /**
-     * Registers a new protocol with the given identifier.  If a protocol with
+     * Registers a new scheme with the given identifier. If a scheme with
      * the given ID already exists it will be overridden.  This ID is the same
-     * one used to retrieve the protocol from getProtocol(String).
+     * one used to retrieve the scheme from getScheme(String).
      * 
-     * @param id the identifier for this protocol
-     * @param protocol the protocol to register
+     * @param id the identifier for this scheme
+     * @param scheme the scheme to register
      * 
-     * @see #getProtocol(String)
+     * @see #getScheme(String)
      */
-    public static void registerProtocol(String id, Protocol protocol) {
-
+    public static void registerScheme(final String id, final Scheme scheme) {
         if (id == null) {
-            throw new IllegalArgumentException("id is null");
+            throw new IllegalArgumentException("Id may not be null");
         }
-        if (protocol == null) {
-            throw new IllegalArgumentException("protocol is null");
+        if (scheme == null) {
+            throw new IllegalArgumentException("Scheme may not be null");
         }
-
-        PROTOCOLS.put(id, protocol);
+        SCHEMES.put(id, scheme);
     }
 
     /**
-     * Unregisters the protocol with the given ID.
+     * Unregisters the scheme with the given ID.
      * 
-     * @param id the ID of the protocol to remove
+     * @param id the ID of the scheme to remove
      */
-    public static void unregisterProtocol(String id) {
-
+    public static void unregisterScheme(final String id) {
         if (id == null) {
-            throw new IllegalArgumentException("id is null");
+            throw new IllegalArgumentException("Id may not be null");
         }
-
-        PROTOCOLS.remove(id);
+        SCHEMES.remove(id);
     }
 
     /**
-     * Gets the protocol with the given ID.
+     * Gets the scheme with the given ID.
      * 
-     * @param id the protocol ID
+     * @param id the scheme ID
      * 
-     * @return Protocol a protocol
+     * @return Scheme a scheme
      * 
-     * @throws IllegalStateException if a protocol with the ID cannot be found
+     * @throws IllegalStateException if a scheme with the ID cannot be found
      */
-    public static Protocol getProtocol(String id) 
+    public static Scheme getScheme(String id) 
         throws IllegalStateException {
 
         if (id == null) {
             throw new IllegalArgumentException("id is null");
         }
-        Protocol protocol = (Protocol) PROTOCOLS.get(id);
-        if (protocol == null) {
-            throw new IllegalStateException("Unsupported protocol: '" + id + "'");
+        Scheme scheme = (Scheme) SCHEMES.get(id);
+        if (scheme == null) {
+            throw new IllegalStateException("Unsupported scheme: '" + id + "'");
         }
-        return protocol;
+        return scheme;
     } 
 
-    /** the scheme of this protocol (e.g. http, https) */
-    private String scheme;
+    /** the scheme of this scheme (e.g. http, https) */
+    private String name;
     
-    /** The socket factory for this protocol */
+    /** The socket factory for this scheme */
     private SocketFactory socketFactory;
     
-    /** The default port for this protocol */
+    /** The default port for this scheme */
     private int defaultPort;
     
-    /** True if this protocol is secure */
+    /** True if this scheme is secure */
     private boolean secure;
   
     /**
-     * Constructs a new Protocol. Whether the created protocol is secure depends on
+     * Constructs a new Protocol. Whether the created scheme is secure depends on
      * the class of <code>factory</code>.
      * 
-     * @param scheme the scheme (e.g. http, https)
+     * @param name the scheme name (e.g. http, https)
      * @param factory the factory for creating sockets for communication using
-     * this protocol
-     * @param defaultPort the port this protocol defaults to
+     * this scheme
+     * @param defaultPort the port this scheme defaults to
      */
-    public Protocol(final String scheme, final SocketFactory factory, int defaultPort) {
+    public Scheme(final String name, final SocketFactory factory, int defaultPort) {
         
-        if (scheme == null) {
-            throw new IllegalArgumentException("scheme is null");
+        if (name == null) {
+            throw new IllegalArgumentException("Scheme name may not be null");
         }
         if (factory == null) {
-            throw new IllegalArgumentException("socketFactory is null");
+            throw new IllegalArgumentException("Socket factory may not be null");
         }
         if (defaultPort <= 0) {
-            throw new IllegalArgumentException("port is invalid: " + defaultPort);
+            throw new IllegalArgumentException("Port is invalid: " + defaultPort);
         }
         
-        this.scheme = scheme;
+        this.name = name;
         this.socketFactory = factory;
         this.defaultPort = defaultPort;
         this.secure = (factory instanceof SecureSocketFactory);
@@ -177,20 +174,20 @@
      * Returns the scheme.
      * @return The scheme
      */
-    public String getScheme() {
-        return scheme;
+    public String getName() {
+        return name;
     }
 
     /**
-     * Returns true if this protocol is secure
-     * @return true if this protocol is secure
+     * Returns true if this scheme is secure
+     * @return true if this scheme is secure
      */
     public boolean isSecure() {
         return secure;
     }
     
     /**
-     * Resolves the correct port for this protocol.  Returns the given port if
+     * Resolves the correct port for this scheme.  Returns the given port if
      * valid or the default port otherwise.
      * 
      * @param port the port to be resolved
@@ -206,7 +203,11 @@
      * @return a string representation of this object.
      */
     public String toString() {
-        return scheme + ":" + defaultPort;
+    	CharArrayBuffer buffer = new CharArrayBuffer(32);
+    	buffer.append(this.name);
+    	buffer.append(':');
+    	buffer.append(Integer.toString(this.defaultPort));
+        return buffer.toString();
     }
     
     /**
@@ -215,11 +216,13 @@
      * @return true if the objects are equal.
      */
     public boolean equals(Object obj) {
-        if (obj instanceof Protocol) {
-            Protocol p = (Protocol) obj;
+        if (obj == null) return false;
+        if (this == obj) return true;
+        if (obj instanceof Scheme) {
+            Scheme p = (Scheme) obj;
             return (
                 defaultPort == p.getDefaultPort()
-                && scheme.equalsIgnoreCase(p.getScheme())
+                && name.equalsIgnoreCase(p.getName())
                 && secure == p.isSecure()
                 && socketFactory.equals(p.getSocketFactory()));
             
@@ -236,7 +239,7 @@
     public int hashCode() {
         int hash = LangUtils.HASH_SEED;
         hash = LangUtils.hashCode(hash, this.defaultPort);
-        hash = LangUtils.hashCode(hash, this.scheme.toLowerCase());
+        hash = LangUtils.hashCode(hash, this.name.toLowerCase());
         hash = LangUtils.hashCode(hash, this.secure);
         hash = LangUtils.hashCode(hash, this.socketFactory);
         return hash;

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
Sat Oct 15 10:07:11 2005
@@ -112,7 +112,7 @@
         if (this.targethost == null) {
         	throw new IllegalStateException("Target host not specified");
         }
-        SocketFactory socketfactory = this.targethost.getProtocol().getSocketFactory();
+        SocketFactory socketfactory = this.targethost.getScheme().getSocketFactory();
         Socket socket = socketfactory.createSocket(
                 this.targethost.getHostName(), this.targethost.getPort(), 
                 this.localAddress, 0, 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpProxyConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpProxyConnection.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpProxyConnection.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpProxyConnection.java
Sat Oct 15 10:07:11 2005
@@ -35,7 +35,7 @@
 
 import org.apache.http.HttpHost;
 import org.apache.http.HttpProxyConnection;
-import org.apache.http.Protocol;
+import org.apache.http.Scheme;
 import org.apache.http.ProxyHost;
 import org.apache.http.io.SecureSocketFactory;
 import org.apache.http.io.SocketFactory;
@@ -83,7 +83,7 @@
                     this.tunneltarget + " is already active");
         }
         assertOpen();
-        Protocol protocol = targetHost.getProtocol();
+        Scheme protocol = targetHost.getScheme();
         SocketFactory socketfactory = protocol.getSocketFactory();
         if (socketfactory instanceof SecureSocketFactory) {
             Socket socket = ((SecureSocketFactory)socketfactory)

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/SocketFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/SocketFactory.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/SocketFactory.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/SocketFactory.java Sat
Oct 15 10:07:11 2005
@@ -35,7 +35,7 @@
 import java.net.UnknownHostException;
 
 import org.apache.http.ConnectTimeoutException;
-import org.apache.http.Protocol;
+import org.apache.http.Scheme;
 import org.apache.http.params.HttpParams;
 
 /**
@@ -47,7 +47,7 @@
  * <code>HostConfiguration</code>s, and <code>equals()</code> and
<code>hashCode()</code> are 
  * required for the correct operation of some connection managers.</p>
  * 
- * @see Protocol
+ * @see Scheme
  * 
  * @author Michael Becke
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java Sat Oct 15
10:07:11 2005
@@ -53,6 +53,7 @@
         suite.addTest(TestHttpVersion.suite());
         suite.addTest(TestStatusLine.suite());
         suite.addTest(TestRequestLine.suite());
+        suite.addTest(TestScheme.suite());
         suite.addTest(TestHttpHost.suite());
 
         suite.addTest(TestAllIO.suite());

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java?rev=321379&r1=321378&r2=321379&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java Sat Oct
15 10:07:11 2005
@@ -60,28 +60,28 @@
     protected void setUp() throws Exception {
         super.setUp();
         SocketFactory socketfactory = PlainSocketFactory.getSocketFactory();
-        final Protocol http = new Protocol("http", socketfactory, 80);
-        Protocol.registerProtocol("http", http);
+        final Scheme http = new Scheme("http", socketfactory, 80);
+        Scheme.registerScheme("http", http);
     }
     
     public void testConstructor() {
-        Protocol http = Protocol.getProtocol("http");
+        Scheme http = Scheme.getScheme("http");
         HttpHost host1 = new HttpHost("somehost");
         assertEquals("somehost", host1.getHostName()); 
         assertEquals(http.getDefaultPort(), host1.getPort()); 
-        assertEquals(http, host1.getProtocol()); 
+        assertEquals(http, host1.getScheme()); 
         HttpHost host2 = new HttpHost("somehost", 8080);
         assertEquals("somehost", host2.getHostName()); 
         assertEquals(8080, host2.getPort()); 
-        assertEquals(http, host2.getProtocol()); 
+        assertEquals(http, host2.getScheme()); 
         HttpHost host3 = new HttpHost("somehost", -1);
         assertEquals("somehost", host3.getHostName()); 
         assertEquals(http.getDefaultPort(), host3.getPort()); 
-        assertEquals(http, host3.getProtocol()); 
+        assertEquals(http, host3.getScheme()); 
         HttpHost host4 = new HttpHost("somehost", 8080, http);
         assertEquals("somehost", host4.getHostName()); 
         assertEquals(8080, host4.getPort()); 
-        assertEquals(http, host4.getProtocol()); 
+        assertEquals(http, host4.getScheme()); 
         try {
             new HttpHost(null, -1, null);
             fail("IllegalArgumentException should have been thrown");
@@ -97,22 +97,22 @@
         ProxyHost proxyhost1 = new ProxyHost("somehost");
         assertEquals("somehost", proxyhost1.getHostName()); 
         assertEquals(http.getDefaultPort(), proxyhost1.getPort()); 
-        assertEquals(http, proxyhost1.getProtocol()); 
+        assertEquals(http, proxyhost1.getScheme()); 
 
         ProxyHost proxyhost2 = new ProxyHost("somehost", 8080);
         assertEquals("somehost", proxyhost2.getHostName()); 
         assertEquals(8080, proxyhost2.getPort()); 
-        assertEquals(http, proxyhost2.getProtocol()); 
+        assertEquals(http, proxyhost2.getScheme()); 
 
         ProxyHost proxyhost3 = new ProxyHost(proxyhost2);
         assertEquals("somehost", proxyhost3.getHostName()); 
         assertEquals(8080, proxyhost3.getPort()); 
-        assertEquals(http, proxyhost3.getProtocol()); 
+        assertEquals(http, proxyhost3.getScheme()); 
     }
     
     public void testHashCode() {
-        Protocol http = Protocol.getProtocol("http");
-        Protocol myhttp = new Protocol("myhttp", 
+        Scheme http = Scheme.getScheme("http");
+        Scheme myhttp = new Scheme("myhttp", 
                 NIOSocketFactory.getSocketFactory(), 8080);
         HttpHost host1 = new HttpHost("somehost", 8080, http);
         HttpHost host2 = new HttpHost("somehost", 80, http);
@@ -130,8 +130,8 @@
     }
     
     public void testEquals() {
-        Protocol http = Protocol.getProtocol("http");
-        Protocol myhttp = new Protocol("myhttp", 
+        Scheme http = Scheme.getScheme("http");
+        Scheme myhttp = new Scheme("myhttp", 
                 NIOSocketFactory.getSocketFactory(), 8080);
         HttpHost host1 = new HttpHost("somehost", 8080, http);
         HttpHost host2 = new HttpHost("somehost", 80, http);
@@ -151,8 +151,8 @@
     }
     
     public void testToString() {
-        Protocol http = Protocol.getProtocol("http");
-        Protocol myhttp = new Protocol("myhttp", 
+        Scheme http = Scheme.getScheme("http");
+        Scheme myhttp = new Scheme("myhttp", 
                 NIOSocketFactory.getSocketFactory(), 8080);
         HttpHost host1 = new HttpHost("somehost");
         assertEquals("http://somehost", host1.toString());
@@ -169,7 +169,7 @@
     }
 
     public void testToHostString() {
-        Protocol http = Protocol.getProtocol("http");
+        Scheme http = Scheme.getScheme("http");
         HttpHost host1 = new HttpHost("somehost");
         assertEquals("somehost", host1.toHostString());
         HttpHost host2 = new HttpHost("somehost", http.getDefaultPort());
@@ -181,7 +181,7 @@
     }
 
     public void testClone() {
-        HttpHost host1 = new HttpHost("somehost", 8888, Protocol.getProtocol("http"));
+        HttpHost host1 = new HttpHost("somehost", 8888, Scheme.getScheme("http"));
         HttpHost host2 = (HttpHost) host1.clone(); 
         assertEquals(host1, host2);
         ProxyHost proxyhost1 = new ProxyHost("somehost", 8888);

Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java?rev=321379&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java Sat Oct
15 10:07:11 2005
@@ -0,0 +1,168 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * 
+ * ====================================================================
+ *
+ *  Copyright 1999-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 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;
+
+import org.apache.http.impl.io.PlainSocketFactory;
+import org.apache.http.impl.io.SSLSocketFactory;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link Scheme}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestScheme extends TestCase {
+
+    public TestScheme(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestScheme.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestScheme.class);
+    }
+
+    public void testConstructor() {
+        Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        assertEquals("http", http.getName()); 
+        assertEquals(80, http.getDefaultPort()); 
+        assertEquals(PlainSocketFactory.getSocketFactory(), http.getSocketFactory()); 
+        assertFalse(http.isSecure()); 
+        Scheme https = new Scheme("http", SSLSocketFactory.getSocketFactory(), 443);
+        assertEquals("http", https.getName()); 
+        assertEquals(443, https.getDefaultPort()); 
+        assertEquals(SSLSocketFactory.getSocketFactory(), https.getSocketFactory()); 
+        assertTrue(https.isSecure());
+        
+        try {
+        	new Scheme(null, PlainSocketFactory.getSocketFactory(), 80);
+        	fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+        	// expected
+        }
+        try {
+        	new Scheme("http", null, 80);
+        	fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+        	// expected
+        }
+        try {
+        	new Scheme("http", PlainSocketFactory.getSocketFactory(), -1);
+        	fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+        	// expected
+        }
+    }
+
+    public void testRegisterUnregister() {
+        Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        Scheme https = new Scheme("http", SSLSocketFactory.getSocketFactory(), 443);
+    	Scheme.registerScheme("http", http);
+    	Scheme.registerScheme("https", https);
+    	assertEquals(http, Scheme.getScheme("http"));
+    	assertEquals(https, Scheme.getScheme("https"));
+    	Scheme.unregisterScheme("http");
+    	Scheme.unregisterScheme("https");
+    	
+    	try {
+        	Scheme.getScheme("http");
+        	fail("IllegalStateException should have been thrown");
+    	} catch (IllegalStateException ex) {
+        	// expected
+    	}
+    }
+
+    public void testIllegalRegisterUnregister() {
+        Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        try {
+        	Scheme.registerScheme(null, http);
+        	fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+        	// expected
+        }
+        try {
+        	Scheme.registerScheme("http", null);
+        	fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+        	// expected
+        }
+        try {
+        	Scheme.unregisterScheme(null);
+        	fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+        	// expected
+        }
+        try {
+        	Scheme.getScheme(null);
+        	fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+        	// expected
+        }
+    }
+    
+    public void testResolvePort() {
+        Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        assertEquals(8080, http.resolvePort(8080));
+        assertEquals(80, http.resolvePort(-1));
+    }
+    
+    public void testHashCode() {
+        Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        Scheme myhttp = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        Scheme https = new Scheme("http", SSLSocketFactory.getSocketFactory(), 443);
+        assertTrue(http.hashCode() != https.hashCode());
+        assertTrue(http.hashCode() == myhttp.hashCode());
+    }
+    
+    public void testEquals() {
+        Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        Scheme myhttp = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        Scheme https = new Scheme("http", SSLSocketFactory.getSocketFactory(), 443);
+        assertFalse(http.equals(https));
+        assertFalse(http.equals(null));
+        assertFalse(http.equals("http"));
+        assertTrue(http.equals(http));
+        assertTrue(http.equals(myhttp));
+        assertFalse(http.equals(https));
+    }
+    
+    public void testToString() {
+        Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+        assertEquals("http:80", http.toString());
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestScheme.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message