hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r604434 - in /jakarta/httpcomponents/httpclient/trunk/module-client/src: examples/org/apache/http/examples/client/ main/java/org/apache/http/client/ main/java/org/apache/http/client/protocol/ main/java/org/apache/http/impl/client/ test/java...
Date Sat, 15 Dec 2007 14:45:49 GMT
Author: olegk
Date: Sat Dec 15 06:45:48 2007
New Revision: 604434

URL: http://svn.apache.org/viewvc?rev=604434&view=rev
Log:
CookieStore converted to generics 

Modified:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientFormLogin.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CookieStore.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java?rev=604434&r1=604433&r2=604434&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
Sat Dec 15 06:45:48 2007
@@ -31,6 +31,8 @@
 
 package org.apache.http.examples.client;
 
+import java.util.List;
+
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.CookieStore;
@@ -78,9 +80,9 @@
             System.out.println("Response content length: " + entity.getContentLength());
             System.out.println("Chunked?: " + entity.isChunked());
         }
-        Cookie[] cookies = cookieStore.getCookies();
-        for (int i = 0; i < cookies.length; i++) {
-            System.out.println("Local cookie: " + cookies[i]);
+        List<Cookie> cookies = cookieStore.getCookies();
+        for (int i = 0; i < cookies.size(); i++) {
+            System.out.println("Local cookie: " + cookies.get(i));
         }
         
         // Consume response content

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientFormLogin.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientFormLogin.java?rev=604434&r1=604433&r2=604434&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientFormLogin.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientFormLogin.java
Sat Dec 15 06:45:48 2007
@@ -29,6 +29,8 @@
 
 package org.apache.http.examples.client;
 
+import java.util.List;
+
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.NameValuePair;
@@ -64,12 +66,12 @@
             entity.consumeContent();
         }
         System.out.println("Initial set of cookies:");    
-        Cookie[] cookies = httpclient.getCookieStore().getCookies();
-        if (cookies.length == 0) {
+        List<Cookie> cookies = httpclient.getCookieStore().getCookies();
+        if (cookies.isEmpty()) {
             System.out.println("None");    
         } else {
-            for (int i = 0; i < cookies.length; i++) {
-                System.out.println("- " + cookies[i].toString());    
+            for (int i = 0; i < cookies.size(); i++) {
+                System.out.println("- " + cookies.get(i).toString());    
             }
         }
         
@@ -95,11 +97,11 @@
         
         System.out.println("Post logon cookies:");    
         cookies = httpclient.getCookieStore().getCookies();
-        if (cookies.length == 0) {
+        if (cookies.isEmpty()) {
             System.out.println("None");    
         } else {
-            for (int i = 0; i < cookies.length; i++) {
-                System.out.println("- " + cookies[i].toString());    
+            for (int i = 0; i < cookies.size(); i++) {
+                System.out.println("- " + cookies.get(i).toString());    
             }
         }
     }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CookieStore.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CookieStore.java?rev=604434&r1=604433&r2=604434&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CookieStore.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CookieStore.java
Sat Dec 15 06:45:48 2007
@@ -31,6 +31,7 @@
 package org.apache.http.client;
 
 import java.util.Date;
+import java.util.List;
 
 import org.apache.http.cookie.Cookie;
 
@@ -57,7 +58,7 @@
      * 
      * @return all cookies
      */
-    Cookie[] getCookies();
+    List<Cookie> getCookies();
 
     /**
      * Removes all of {@link Cookie cookies} in this store that have expired by 

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=604434&r1=604433&r2=604434&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
Sat Dec 15 06:45:48 2007
@@ -146,11 +146,11 @@
         // Get an instance of the selected cookie policy
         CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
         // Get all cookies available in the HTTP state
-        Cookie[] cookies = cookieStore.getCookies();
+        List<Cookie> cookies = cookieStore.getCookies();
         // Find cookies matching the given origin
-        List<Cookie> matchedCookies = new ArrayList<Cookie>(cookies.length);
-        for (int i = 0; i < cookies.length; i++) {
-            Cookie cookie = cookies[i];
+        List<Cookie> matchedCookies = new ArrayList<Cookie>();
+        for (int i = 0; i < cookies.size(); i++) {
+            Cookie cookie = cookies.get(i);
             if (cookieSpec.match(cookie, cookieOrigin)) {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Cookie " + cookie + " match " + cookieOrigin);
@@ -169,8 +169,9 @@
         int ver = cookieSpec.getVersion();
         if (ver > 0) {
             boolean needVersionHeader = false;
-            for (int i = 0; i < cookies.length; i++) {
-                if (ver != cookies[i].getVersion()) {
+            for (int i = 0; i < matchedCookies.size(); i++) {
+                Cookie cookie = matchedCookies.get(i);
+                if (ver != cookie.getVersion()) {
                     needVersionHeader = true;
                 }
             }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java?rev=604434&r1=604433&r2=604434&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
Sat Dec 15 06:45:48 2007
@@ -31,9 +31,11 @@
 package org.apache.http.impl.client;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.http.client.CookieStore;
 import org.apache.http.cookie.Cookie;
@@ -114,13 +116,13 @@
     }
 
     /**
-     * Returns an array of {@link Cookie cookies} that this HTTP
+     * Returns an immutable array of {@link Cookie cookies} that this HTTP
      * state currently contains.
      * 
      * @return an array of {@link Cookie cookies}.
      */
-    public synchronized Cookie[] getCookies() {
-        return (Cookie[]) (cookies.toArray(new Cookie[cookies.size()]));
+    public synchronized List<Cookie> getCookies() {
+        return Collections.unmodifiableList(this.cookies);
     }
 
     /**

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java?rev=604434&r1=604433&r2=604434&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
Sat Dec 15 06:45:48 2007
@@ -29,6 +29,7 @@
 package org.apache.http.client.protocol;
 
 import java.io.IOException;
+import java.util.List;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -115,9 +116,9 @@
             e1.consumeContent();
         }
         
-        Cookie[] cookies = cookieStore.getCookies();
+        List<Cookie> cookies = cookieStore.getCookies();
         assertNotNull(cookies);
-        assertEquals(1, cookies.length);
+        assertEquals(1, cookies.size());
 
         HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e2 = response2.getEntity();
@@ -166,9 +167,9 @@
             e1.consumeContent();
         }
         
-        Cookie[] cookies = cookieStore.getCookies();
+        List<Cookie> cookies = cookieStore.getCookies();
         assertNotNull(cookies);
-        assertEquals(2, cookies.length);
+        assertEquals(2, cookies.size());
 
         HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e2 = response2.getEntity();
@@ -215,9 +216,9 @@
             e1.consumeContent();
         }
         
-        Cookie[] cookies = cookieStore.getCookies();
+        List<Cookie> cookies = cookieStore.getCookies();
         assertNotNull(cookies);
-        assertEquals(1, cookies.length);
+        assertEquals(1, cookies.size());
 
         HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
         HttpEntity e2 = response2.getEntity();
@@ -266,11 +267,11 @@
             e1.consumeContent();
         }
         
-        Cookie[] cookies = cookieStore.getCookies();
+        List<Cookie> cookies = cookieStore.getCookies();
         assertNotNull(cookies);
-        assertEquals(1, cookies.length);
-        assertEquals("right", cookies[0].getValue());
-        assertTrue(cookies[0] instanceof SetCookie2);
+        assertEquals(1, cookies.size());
+        assertEquals("right", cookies.get(0).getValue());
+        assertTrue(cookies.get(0) instanceof SetCookie2);
     }
 
 }



Mime
View raw message