Split Cookie interface into a generic non-mutable Cookie interface and mutable SetCookie interface representing SetCookie response header sent by the origin server to the HTTP agent in order to maintain a conversational state

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@558519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2007-07-22 18:19:49 +00:00
parent 6d36b3aa06
commit 3c5e2e6491
21 changed files with 250 additions and 202 deletions

View File

@ -68,16 +68,6 @@ public interface Cookie {
*/
String getComment();
/**
* If a user agent (web browser) presents this cookie to a user, the
* cookie's purpose will be described using this comment.
*
* @param comment
*
* @see #getComment()
*/
void setComment(String comment);
/**
* Returns the expiration {@link Date} of the cookie, or <tt>null</tt>
* if none exists.
@ -91,20 +81,6 @@ public interface Cookie {
*/
Date getExpiryDate();
/**
* Sets expiration date.
* <p><strong>Note:</strong> the object returned by this method is considered
* immutable. Changing it (e.g. using setTime()) could result in undefined
* behaviour. Do so at your peril.</p>
*
* @param expiryDate the {@link Date} after which this cookie is no longer valid.
*
* @see #getExpiryDate
*
*/
void setExpiryDate (Date expiryDate);
/**
* Returns <tt>false</tt> if the cookie should be discarded at the end
* of the "session"; <tt>true</tt> otherwise.
@ -114,7 +90,6 @@ public interface Cookie {
*/
boolean isPersistent();
/**
* Returns domain attribute of the cookie.
*
@ -124,16 +99,6 @@ public interface Cookie {
*/
String getDomain();
/**
* Sets the domain attribute.
*
* @param domain The value of the domain attribute
*
* @see #getDomain
*/
void setDomain(String domain);
/**
* Returns the path attribute of the cookie
*
@ -143,36 +108,12 @@ public interface Cookie {
*/
String getPath();
/**
* Sets the path attribute.
*
* @param path The value of the path attribute
*
* @see #getPath
*
*/
void setPath(String path);
/**
* @return <code>true</code> if this cookie should only be sent over secure connections.
* @see #setSecure(boolean)
*/
boolean isSecure();
/**
* Sets the secure attribute of the cookie.
* <p>
* When <tt>true</tt> the cookie should only be sent
* using a secure protocol (https). This should only be set when
* the cookie's originating server used a secure protocol to set the
* cookie's value.
*
* @param secure The value of the secure attribute
*
* @see #isSecure()
*/
void setSecure (boolean secure);
/**
* Returns the version of the cookie specification to which this
* cookie conforms.
@ -184,16 +125,6 @@ public interface Cookie {
*/
int getVersion();
/**
* Sets the version of the cookie specification to which this
* cookie conforms.
*
* @param version the version of the cookie.
*
* @see #getVersion
*/
void setVersion(int version);
/**
* Returns true if this cookie has expired.
* @param date Current time
@ -202,21 +133,6 @@ public interface Cookie {
*/
boolean isExpired(final Date date);
/**
* Indicates whether the cookie had a path specified in a
* path attribute of the <tt>Set-Cookie</tt> header. This value
* is important for generating the <tt>Cookie</tt> header because
* some cookie specifications require that the <tt>Cookie</tt> header
* should only include a path attribute if the cookie's path
* was specified in the <tt>Set-Cookie</tt> header.
*
* @param value <tt>true</tt> if the cookie's path was explicitly
* set, <tt>false</tt> otherwise.
*
* @see #isPathAttributeSpecified
*/
public void setPathAttributeSpecified(boolean value);
/**
* Returns <tt>true</tt> if cookie's path was set via a path attribute
* in the <tt>Set-Cookie</tt> header.
@ -228,21 +144,6 @@ public interface Cookie {
*/
boolean isPathAttributeSpecified();
/**
* Indicates whether the cookie had a domain specified in a
* domain attribute of the <tt>Set-Cookie</tt> header. This value
* is important for generating the <tt>Cookie</tt> header because
* some cookie specifications require that the <tt>Cookie</tt> header
* should only include a domain attribute if the cookie's domain
* was specified in the <tt>Set-Cookie</tt> header.
*
* @param value <tt>true</tt> if the cookie's domain was explicitly
* set, <tt>false</tt> otherwise.
*
* @see #isDomainAttributeSpecified
*/
void setDomainAttributeSpecified(boolean value);
/**
* Returns <tt>true</tt> if cookie's domain was set via a domain
* attribute in the <tt>Set-Cookie</tt> header.

View File

@ -52,7 +52,7 @@ public interface CookieAttributeHandler {
* @param cookie {@link org.apache.http.cookie.Cookie} to be updated
* @param value cookie attribute value from the cookie response header
*/
void parse(Cookie cookie, String value)
void parse(SetCookie cookie, String value)
throws MalformedCookieException;
/**

View File

@ -0,0 +1,143 @@
/*
* $HeadURL$
* $Revision$
* $Date$
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.cookie;
import java.util.Date;
/**
* This interface represents a <code>SetCookie</code> response header sent by the
* origin server to the HTTP agent in order to maintain a conversational state.
*
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
* @since 4.0
*/
public interface SetCookie extends Cookie {
/**
* If a user agent (web browser) presents this cookie to a user, the
* cookie's purpose will be described using this comment.
*
* @param comment
*
* @see #getComment()
*/
void setComment(String comment);
/**
* Sets expiration date.
* <p><strong>Note:</strong> the object returned by this method is considered
* immutable. Changing it (e.g. using setTime()) could result in undefined
* behaviour. Do so at your peril.</p>
*
* @param expiryDate the {@link Date} after which this cookie is no longer valid.
*
* @see #getExpiryDate
*
*/
void setExpiryDate (Date expiryDate);
/**
* Sets the domain attribute.
*
* @param domain The value of the domain attribute
*
* @see #getDomain
*/
void setDomain(String domain);
/**
* Sets the path attribute.
*
* @param path The value of the path attribute
*
* @see #getPath
*
*/
void setPath(String path);
/**
* Sets the secure attribute of the cookie.
* <p>
* When <tt>true</tt> the cookie should only be sent
* using a secure protocol (https). This should only be set when
* the cookie's originating server used a secure protocol to set the
* cookie's value.
*
* @param secure The value of the secure attribute
*
* @see #isSecure()
*/
void setSecure (boolean secure);
/**
* Sets the version of the cookie specification to which this
* cookie conforms.
*
* @param version the version of the cookie.
*
* @see #getVersion
*/
void setVersion(int version);
/**
* Indicates whether the cookie had a path specified in a
* path attribute of the <tt>Set-Cookie</tt> header. This value
* is important for generating the <tt>Cookie</tt> header because
* some cookie specifications require that the <tt>Cookie</tt> header
* should only include a path attribute if the cookie's path
* was specified in the <tt>Set-Cookie</tt> header.
*
* @param value <tt>true</tt> if the cookie's path was explicitly
* set, <tt>false</tt> otherwise.
*
* @see #isPathAttributeSpecified
*/
public void setPathAttributeSpecified(boolean value);
/**
* Indicates whether the cookie had a domain specified in a
* domain attribute of the <tt>Set-Cookie</tt> header. This value
* is important for generating the <tt>Cookie</tt> header because
* some cookie specifications require that the <tt>Cookie</tt> header
* should only include a domain attribute if the cookie's domain
* was specified in the <tt>Set-Cookie</tt> header.
*
* @param value <tt>true</tt> if the cookie's domain was explicitly
* set, <tt>false</tt> otherwise.
*
* @see #isDomainAttributeSpecified
*/
void setDomainAttributeSpecified(boolean value);
}

View File

@ -30,8 +30,8 @@
*/
package org.apache.http.impl.cookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class BasicCommentHandler extends AbstractCookieAttributeHandler {
@ -39,7 +39,7 @@ public BasicCommentHandler() {
super();
}
public void parse(final Cookie cookie, final String value)
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -33,7 +33,7 @@
import java.util.Date;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.SetCookie;
import org.apache.http.util.CharArrayBuffer;
/**
@ -56,7 +56,7 @@
*
* @version $Revision$
*/
public class BasicCookie implements Cookie {
public class BasicCookie implements SetCookie {
/**
* Default Constructor taking a name and a value. The value may be null.

View File

@ -34,6 +34,7 @@
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class BasicDomainHandler implements CookieAttributeHandler {
@ -41,7 +42,7 @@ public BasicDomainHandler() {
super();
}
public void parse(final Cookie cookie, final String value)
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -30,8 +30,8 @@
*/
package org.apache.http.impl.cookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class BasicExpiresHandler extends AbstractCookieAttributeHandler {
@ -46,7 +46,7 @@ public BasicExpiresHandler(final String[] datepatterns) {
this.datepatterns = datepatterns;
}
public void parse(final Cookie cookie, final String value)
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -32,8 +32,8 @@
import java.util.Date;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class BasicMaxAgeHandler extends AbstractCookieAttributeHandler {
@ -41,7 +41,7 @@ public BasicMaxAgeHandler() {
super();
}
public void parse(final Cookie cookie, final String value)
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -34,6 +34,7 @@
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class BasicPathHandler implements CookieAttributeHandler {
@ -41,7 +42,7 @@ public BasicPathHandler() {
super();
}
public void parse(final Cookie cookie, String value)
public void parse(final SetCookie cookie, String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -33,6 +33,7 @@
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class BasicSecureHandler extends AbstractCookieAttributeHandler {
@ -40,7 +41,7 @@ public BasicSecureHandler() {
super();
}
public void parse(final Cookie cookie, final String value)
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -39,6 +39,7 @@
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
/**
* Cookie management functions shared by all specification.
@ -78,7 +79,7 @@ protected Cookie[] parse(final HeaderElement[] elems, final CookieOrigin origin)
throw new MalformedCookieException("Cookie name may not be empty");
}
Cookie cookie = new BasicCookie(name, value);
SetCookie cookie = new BasicCookie(name, value);
cookie.setPath(getDefaultPath(origin));
cookie.setDomain(getDefaultDomain(origin));

View File

@ -34,6 +34,7 @@
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class RFC2109DomainHandler implements CookieAttributeHandler {
@ -41,7 +42,7 @@ public RFC2109DomainHandler() {
super();
}
public void parse(final Cookie cookie, final String value)
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -33,6 +33,7 @@
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class RFC2109VersionHandler extends AbstractCookieAttributeHandler {
@ -40,7 +41,7 @@ public RFC2109VersionHandler() {
super();
}
public void parse(final Cookie cookie, final String value)
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");

View File

@ -57,9 +57,9 @@ public static Test suite() {
}
public void testUnequality1() {
Cookie cookie1 = new BasicCookie("name1", "value");
BasicCookie cookie1 = new BasicCookie("name1", "value");
cookie1.setPath("/a/b/");
Cookie cookie2 = new BasicCookie("name1", "value");
BasicCookie cookie2 = new BasicCookie("name1", "value");
cookie2.setPath("/a/");
Comparator comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) < 0);
@ -67,9 +67,9 @@ public void testUnequality1() {
}
public void testUnequality2() {
Cookie cookie1 = new BasicCookie("name1", "value");
BasicCookie cookie1 = new BasicCookie("name1", "value");
cookie1.setPath("/a/b");
Cookie cookie2 = new BasicCookie("name1", "value");
BasicCookie cookie2 = new BasicCookie("name1", "value");
cookie2.setPath("/a");
Comparator comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) < 0);
@ -77,9 +77,9 @@ public void testUnequality2() {
}
public void testEquality1() {
Cookie cookie1 = new BasicCookie("name1", "value");
BasicCookie cookie1 = new BasicCookie("name1", "value");
cookie1.setPath("/a");
Cookie cookie2 = new BasicCookie("name1", "value");
BasicCookie cookie2 = new BasicCookie("name1", "value");
cookie2.setPath("/a");
Comparator comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0);
@ -87,9 +87,9 @@ public void testEquality1() {
}
public void testEquality2() {
Cookie cookie1 = new BasicCookie("name1", "value");
BasicCookie cookie1 = new BasicCookie("name1", "value");
cookie1.setPath("/a/");
Cookie cookie2 = new BasicCookie("name1", "value");
BasicCookie cookie2 = new BasicCookie("name1", "value");
cookie2.setPath("/a");
Comparator comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0);
@ -97,9 +97,9 @@ public void testEquality2() {
}
public void testEquality3() {
Cookie cookie1 = new BasicCookie("name1", "value");
BasicCookie cookie1 = new BasicCookie("name1", "value");
cookie1.setPath(null);
Cookie cookie2 = new BasicCookie("name1", "value");
BasicCookie cookie2 = new BasicCookie("name1", "value");
cookie2.setPath("/");
Comparator comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0);
@ -107,9 +107,9 @@ public void testEquality3() {
}
public void testEquality4() {
Cookie cookie1 = new BasicCookie("name1", "value");
BasicCookie cookie1 = new BasicCookie("name1", "value");
cookie1.setPath("/this");
Cookie cookie2 = new BasicCookie("name1", "value");
BasicCookie cookie2 = new BasicCookie("name1", "value");
cookie2.setPath("/that");
Comparator comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0);

View File

@ -42,6 +42,7 @@
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
public class TestAbstractCookieSpec extends TestCase {
@ -84,7 +85,7 @@ public boolean match(Cookie cookie, CookieOrigin origin) {
return true;
}
public void parse(Cookie cookie, String value) throws MalformedCookieException {
public void parse(SetCookie cookie, String value) throws MalformedCookieException {
}
public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {

View File

@ -39,7 +39,6 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
@ -62,7 +61,7 @@ public static void main(String args[]) {
}
public void testBasicDomainParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicDomainHandler();
h.parse(cookie, "www.somedomain.com");
assertEquals("www.somedomain.com", cookie.getDomain());
@ -70,7 +69,7 @@ public void testBasicDomainParse() throws Exception {
}
public void testBasicDomainParseInvalid() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicDomainHandler();
try {
h.parse(cookie, "");
@ -87,7 +86,7 @@ public void testBasicDomainParseInvalid() throws Exception {
}
public void testBasicDomainValidate1() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new BasicDomainHandler();
@ -111,7 +110,7 @@ public void testBasicDomainValidate1() throws Exception {
}
public void testBasicDomainValidate2() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
CookieAttributeHandler h = new BasicDomainHandler();
@ -128,7 +127,7 @@ public void testBasicDomainValidate2() throws Exception {
}
public void testBasicDomainValidate3() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
CookieAttributeHandler h = new BasicDomainHandler();
@ -137,7 +136,7 @@ public void testBasicDomainValidate3() throws Exception {
}
public void testBasicDomainValidate4() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
CookieAttributeHandler h = new BasicDomainHandler();
@ -151,7 +150,7 @@ public void testBasicDomainValidate4() throws Exception {
}
public void testBasicDomainMatch1() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
CookieAttributeHandler h = new BasicDomainHandler();
@ -163,7 +162,7 @@ public void testBasicDomainMatch1() throws Exception {
}
public void testBasicDomainMatch2() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new BasicDomainHandler();
@ -212,7 +211,7 @@ public void testBasicDomainInvalidInput() throws Exception {
}
public void testBasicPathParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicPathHandler();
h.parse(cookie, "stuff");
assertEquals("stuff", cookie.getPath());
@ -226,7 +225,7 @@ public void testBasicPathParse() throws Exception {
}
public void testBasicPathMatch1() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false);
CookieAttributeHandler h = new BasicPathHandler();
cookie.setPath("/stuff");
@ -234,7 +233,7 @@ public void testBasicPathMatch1() throws Exception {
}
public void testBasicPathMatch2() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff/", false);
CookieAttributeHandler h = new BasicPathHandler();
cookie.setPath("/stuff");
@ -242,7 +241,7 @@ public void testBasicPathMatch2() throws Exception {
}
public void testBasicPathMatch3() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff/more-stuff", false);
CookieAttributeHandler h = new BasicPathHandler();
cookie.setPath("/stuff");
@ -250,7 +249,7 @@ public void testBasicPathMatch3() throws Exception {
}
public void testBasicPathMatch4() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuffed", false);
CookieAttributeHandler h = new BasicPathHandler();
cookie.setPath("/stuff");
@ -258,7 +257,7 @@ public void testBasicPathMatch4() throws Exception {
}
public void testBasicPathMatch5() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/otherstuff", false);
CookieAttributeHandler h = new BasicPathHandler();
cookie.setPath("/stuff");
@ -266,7 +265,7 @@ public void testBasicPathMatch5() throws Exception {
}
public void testBasicPathMatch6() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false);
CookieAttributeHandler h = new BasicPathHandler();
cookie.setPath("/stuff/");
@ -274,14 +273,14 @@ public void testBasicPathMatch6() throws Exception {
}
public void testBasicPathMatch7() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false);
CookieAttributeHandler h = new BasicPathHandler();
assertTrue(h.match(cookie, origin));
}
public void testBasicPathValidate() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false);
CookieAttributeHandler h = new BasicPathHandler();
cookie.setPath("/stuff");
@ -318,14 +317,14 @@ public void testBasicPathInvalidInput() throws Exception {
}
public void testBasicMaxAgeParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicMaxAgeHandler();
h.parse(cookie, "2000");
assertNotNull(cookie.getExpiryDate());
}
public void testBasicMaxAgeParseInvalid() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicMaxAgeHandler();
try {
h.parse(cookie, "garbage");
@ -352,7 +351,7 @@ public void testBasicMaxAgeInvalidInput() throws Exception {
}
public void testBasicCommentParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicCommentHandler();
h.parse(cookie, "whatever");
assertEquals("whatever", cookie.getComment());
@ -371,7 +370,7 @@ public void testBasicCommentInvalidInput() throws Exception {
}
public void testBasicSecureParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicSecureHandler();
h.parse(cookie, "whatever");
assertTrue(cookie.isSecure());
@ -380,7 +379,7 @@ public void testBasicSecureParse() throws Exception {
}
public void testBasicSecureMatch() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicSecureHandler();
CookieOrigin origin1 = new CookieOrigin("somehost", 80, "/stuff", false);
@ -419,7 +418,7 @@ public void testBasicSecureInvalidInput() throws Exception {
}
public void testBasicExpiresParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicExpiresHandler(new String[] {DateUtils.PATTERN_RFC1123});
DateFormat dateformat = new SimpleDateFormat(DateUtils.PATTERN_RFC1123, Locale.US);
@ -432,7 +431,7 @@ public void testBasicExpiresParse() throws Exception {
}
public void testBasicExpiresParseInvalid() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new BasicExpiresHandler(new String[] {DateUtils.PATTERN_RFC1123});
try {
h.parse(cookie, "garbage");

View File

@ -658,7 +658,7 @@ private void checkDate(String date) throws Exception {
* browser compatibility mode.
*/
public void testSecondDomainLevelCookie() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".sourceforge.net");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
@ -670,7 +670,7 @@ public void testSecondDomainLevelCookie() throws Exception {
}
public void testSecondDomainLevelCookieMatch1() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".sourceforge.net");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
@ -682,7 +682,7 @@ public void testSecondDomainLevelCookieMatch1() throws Exception {
}
public void testSecondDomainLevelCookieMatch2() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain("sourceforge.net");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
@ -694,7 +694,7 @@ public void testSecondDomainLevelCookieMatch2() throws Exception {
}
public void testSecondDomainLevelCookieMatch3() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".sourceforge.net");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
@ -706,7 +706,7 @@ public void testSecondDomainLevelCookieMatch3() throws Exception {
}
public void testInvalidSecondDomainLevelCookieMatch1() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".sourceforge.net");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
@ -718,7 +718,7 @@ public void testInvalidSecondDomainLevelCookieMatch1() throws Exception {
}
public void testInvalidSecondDomainLevelCookieMatch2() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain("sourceforge.net");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
@ -731,7 +731,7 @@ public void testInvalidSecondDomainLevelCookieMatch2() throws Exception {
public void testMatchBlankPath() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin("host", 80, " ", false);
@ -740,7 +740,7 @@ public void testMatchBlankPath() throws Exception {
public void testMatchNullCookieDomain() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin("host", 80, "/", false);
assertFalse(cookiespec.match(cookie, origin));
@ -748,7 +748,7 @@ public void testMatchNullCookieDomain() throws Exception {
public void testMatchNullCookiePath() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
CookieOrigin origin = new CookieOrigin("host", 80, "/", false);
assertTrue(cookiespec.match(cookie, origin));
@ -756,7 +756,7 @@ public void testMatchNullCookiePath() throws Exception {
public void testCookieMatch1() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin("host", 80, "/", false);
@ -765,7 +765,7 @@ public void testCookieMatch1() throws Exception {
public void testCookieMatch2() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain(".whatever.com");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin(".whatever.com", 80, "/", false);
@ -774,7 +774,7 @@ public void testCookieMatch2() throws Exception {
public void testCookieMatch3() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain(".whatever.com");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin(".really.whatever.com", 80, "/", false);
@ -783,7 +783,7 @@ public void testCookieMatch3() throws Exception {
public void testCookieMatch4() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin("host", 80, "/foobar", false);
@ -792,7 +792,7 @@ public void testCookieMatch4() throws Exception {
public void testCookieMismatch1() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host1");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin("host2", 80, "/", false);
@ -801,7 +801,7 @@ public void testCookieMismatch1() throws Exception {
public void testCookieMismatch2() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain(".aaaaaaaaa.com");
cookie.setPath("/");
CookieOrigin origin = new CookieOrigin(".bbbbbbbb.com", 80, "/", false);
@ -810,7 +810,7 @@ public void testCookieMismatch2() throws Exception {
public void testCookieMismatch3() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
cookie.setPath("/foobar");
CookieOrigin origin = new CookieOrigin("host", 80, "/foo", false);
@ -819,7 +819,7 @@ public void testCookieMismatch3() throws Exception {
public void testCookieMismatch4() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
cookie.setPath("/foobar");
CookieOrigin origin = new CookieOrigin("host", 80, "/foobar/", false);
@ -828,7 +828,7 @@ public void testCookieMismatch4() throws Exception {
public void testCookieMatch5() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
cookie.setPath("/foobar/r");
CookieOrigin origin = new CookieOrigin("host", 80, "/foobar/", false);
@ -837,7 +837,7 @@ public void testCookieMatch5() throws Exception {
public void testCookieMismatch6() throws Exception {
CookieSpec cookiespec = new BrowserCompatSpec();
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
cookie.setDomain("host");
cookie.setPath("/foobar");
cookie.setSecure(true);
@ -846,7 +846,7 @@ public void testCookieMismatch6() throws Exception {
}
public void testInvalidMatchDomain() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain("beta.gamma.com");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
@ -878,7 +878,7 @@ public void testGenericCookieFormatting() throws Exception {
* Tests if null cookie values are handled correctly.
*/
public void testNullCookieValueFormatting() {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".whatever.com");
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");

View File

@ -209,7 +209,7 @@ public void testCookieWithComma() throws Exception {
}
public void testFormatCookies() throws Exception {
Cookie c1 = new BasicCookie("name1", "value1");
BasicCookie c1 = new BasicCookie("name1", "value1");
c1.setDomain(".whatever.com");
c1.setDomainAttributeSpecified(true);
c1.setPath("/");

View File

@ -169,7 +169,7 @@ public void testParseWithIllegalDomain4() throws Exception {
* browser compatibility mode.
*/
public void testSecondDomainLevelCookie() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".sourceforge.net");
cookie.setPath("/");
cookie.setDomainAttributeSpecified(true);
@ -186,7 +186,7 @@ public void testSecondDomainLevelCookie() throws Exception {
}
public void testSecondDomainLevelCookieMatch() throws Exception {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".sourceforge.net");
cookie.setPath("/");
cookie.setDomainAttributeSpecified(true);
@ -361,7 +361,7 @@ public void testRFC2109CookiesFormatting() throws Exception {
* Tests if null cookie values are handled correctly.
*/
public void testNullCookieValueFormatting() {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomain(".whatever.com");
cookie.setPath("/");
cookie.setDomainAttributeSpecified(true);
@ -383,7 +383,7 @@ public void testNullCookieValueFormatting() {
}
public void testCookieNullDomainNullPathFormatting() {
Cookie cookie = new BasicCookie("name", null);
BasicCookie cookie = new BasicCookie("name", null);
cookie.setDomainAttributeSpecified(true);
cookie.setPath("/");
cookie.setPathAttributeSpecified(true);
@ -403,16 +403,16 @@ public void testCookieNullDomainNullPathFormatting() {
}
public void testCookieOrderingByPath() {
Cookie c1 = new BasicCookie("name1", "value1");
BasicCookie c1 = new BasicCookie("name1", "value1");
c1.setPath("/a/b/c");
c1.setPathAttributeSpecified(true);
Cookie c2 = new BasicCookie("name2", "value2");
BasicCookie c2 = new BasicCookie("name2", "value2");
c2.setPath("/a/b");
c2.setPathAttributeSpecified(true);
Cookie c3 = new BasicCookie("name3", "value3");
BasicCookie c3 = new BasicCookie("name3", "value3");
c3.setPath("/a");
c3.setPathAttributeSpecified(true);
Cookie c4 = new BasicCookie("name4", "value4");
BasicCookie c4 = new BasicCookie("name4", "value4");
c4.setPath("/");
c4.setPathAttributeSpecified(true);

View File

@ -34,7 +34,6 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
@ -56,7 +55,7 @@ public static void main(String args[]) {
}
public void testNetscapeDomainValidate1() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();
@ -73,7 +72,7 @@ public void testNetscapeDomainValidate1() throws Exception {
}
public void testNetscapeDomainValidate2() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();
@ -97,7 +96,7 @@ public void testNetscapeDomainValidate2() throws Exception {
}
public void testNetscapeDomainValidate3() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();
@ -114,7 +113,7 @@ public void testNetscapeDomainValidate3() throws Exception {
}
public void testNetscapeDomainValidate4() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();
@ -131,7 +130,7 @@ public void testNetscapeDomainValidate4() throws Exception {
}
public void testNetscapeDomainMatch1() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();
@ -143,7 +142,7 @@ public void testNetscapeDomainMatch1() throws Exception {
}
public void testNetscapeDomainMatch2() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.whatever.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();

View File

@ -34,7 +34,6 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
@ -56,7 +55,7 @@ public static void main(String args[]) {
}
public void testRFC2109DomainParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new RFC2109DomainHandler();
h.parse(cookie, "somehost");
@ -77,7 +76,7 @@ public void testRFC2109DomainParse() throws Exception {
}
public void testRFC2109DomainValidate1() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -101,7 +100,7 @@ public void testRFC2109DomainValidate1() throws Exception {
}
public void testRFC2109DomainValidate2() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -125,7 +124,7 @@ public void testRFC2109DomainValidate2() throws Exception {
}
public void testRFC2109DomainValidate3() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -142,7 +141,7 @@ public void testRFC2109DomainValidate3() throws Exception {
}
public void testRFC2109DomainValidate4() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -166,7 +165,7 @@ public void testRFC2109DomainValidate4() throws Exception {
}
public void testRFC2109DomainMatch1() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -178,7 +177,7 @@ public void testRFC2109DomainMatch1() throws Exception {
}
public void testRFC2109DomainMatch2() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.whatever.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -187,7 +186,7 @@ public void testRFC2109DomainMatch2() throws Exception {
}
public void testRFC2109DomainMatch3() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -196,7 +195,7 @@ public void testRFC2109DomainMatch3() throws Exception {
}
public void testRFC2109DomainMatch4() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
@ -239,14 +238,14 @@ public void testRFC2109DomainInvalidInput() throws Exception {
}
public void testRFC2109VersionParse() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new RFC2109VersionHandler();
h.parse(cookie, "12");
assertEquals(12, cookie.getVersion());
}
public void testRFC2109VersionParseInvalid() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieAttributeHandler h = new RFC2109VersionHandler();
try {
h.parse(cookie, "garbage");
@ -269,7 +268,7 @@ public void testRFC2109VersionParseInvalid() throws Exception {
}
public void testRFC2109VersionValidate() throws Exception {
Cookie cookie = new BasicCookie("name", "value");
BasicCookie cookie = new BasicCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109VersionHandler();