Author: hlship
Date: Sun Oct 30 13:03:21 2005
New Revision: 329643
URL: http://svn.apache.org/viewcvs?rev=329643&view=rev
Log:
TAPESTRY-571: CookieSource service stores only session cookies (despite
documentation) and provides no way to store a persistent cookie
Added:
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java
- copied, changed from r329587,
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/TestCookieSource.java
Removed:
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/TestCookieSource.java
Modified:
jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.request.xml
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/CookieSource.java
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java
jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/configuration.xml
jakarta/tapestry/trunk/status.xml
Modified:
jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.request.xml
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.request.xml?rev=329643&r1=329642&r2=329643&view=diff
==============================================================================
---
jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.request.xml
(original)
+++
jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.request.xml
Sun Oct 30 13:03:21 2005
@@ -48,6 +48,8 @@
<contribution configuration-id="hivemind.FactoryDefaults">
<default symbol="org.apache.tapestry.accepted-locales" value=""/>
+ <!-- One week, in seconds -->
+ <default symbol="org.apache.tapestry.default-cookie-max-age"
value="604800"/>
</contribution>
<service-point id="CookieSource">
@@ -58,6 +60,7 @@
<construct class="impl.CookieSourceImpl">
<set-service property="request"
service-id="tapestry.globals.HttpServletRequest"/>
<set-service property="response"
service-id="tapestry.globals.HttpServletResponse"/>
+ <set property="defaultMaxAge"
value="${org.apache.tapestry.default-cookie-max-age}"/>
</construct>
</invoke-factory>
</service-point>
Modified:
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/CookieSource.java
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/CookieSource.java?rev=329643&r1=329642&r2=329643&view=diff
==============================================================================
---
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/CookieSource.java
(original)
+++
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/CookieSource.java
Sun Oct 30 13:03:21 2005
@@ -24,16 +24,25 @@
{
/**
* Returns the value of the first cookie whose name matches. Returns null
if no such cookie
- * exists.
+ * exists. This method is only aware of cookies that are part of the
incoming request; it does
+ * not know about additional cookies added since then (via
+ * [EMAIL PROTECTED] #writeCookieValue(String, String)}).
*/
public String readCookieValue(String name);
/**
- * Creates or updates a cookie value. The value is stored permanently (no
timeout, not session
- * based). TODO: add suport for timeouts and session cookies.
+ * Creates or updates a cookie value. The value is stored using a max age
(in seconds) defined
+ * by the symbol <code>org.apache.tapestry.default-cookie-max-age</code>.
The factory default
+ * for this value is the equivalent of one week.
*/
public void writeCookieValue(String name, String value);
+
+ /**
+ * As with [EMAIL PROTECTED] #writeCookieValue(String, String)} but an
explicit maximum age may be set.
+ */
+
+ public void writeCookieValue(String name, String value, int maxAge);
/**
* Removes a previously written cookie, by writing a new cookie with a
maxAge of 0.
Modified:
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java?rev=329643&r1=329642&r2=329643&view=diff
==============================================================================
---
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java
(original)
+++
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/CookieSourceImpl.java
Sun Oct 30 13:03:21 2005
@@ -32,6 +32,8 @@
private HttpServletResponse _response;
+ private int _defaultMaxAge;
+
public String readCookieValue(String name)
{
Cookie[] cookies = _request.getCookies();
@@ -50,8 +52,14 @@
public void writeCookieValue(String name, String value)
{
+ writeCookieValue(name, value, _defaultMaxAge);
+ }
+
+ public void writeCookieValue(String name, String value, int maxAge)
+ {
Cookie cookie = new Cookie(name, value);
cookie.setPath(_request.getContextPath() + "/");
+ cookie.setMaxAge(maxAge);
_response.addCookie(cookie);
}
@@ -73,5 +81,10 @@
public void setResponse(HttpServletResponse response)
{
_response = response;
+ }
+
+ public void setDefaultMaxAge(int defaultMaxAge)
+ {
+ _defaultMaxAge = defaultMaxAge;
}
}
Copied:
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java
(from r329587,
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/TestCookieSource.java)
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java?p2=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java&p1=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/TestCookieSource.java&r1=329587&r2=329643&rev=329643&view=diff
==============================================================================
---
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/TestCookieSource.java
(original)
+++
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/CookieSourceTest.java
Sun Oct 30 13:03:21 2005
@@ -30,13 +30,18 @@
* @author Howard Lewis Ship
* @since 4.0
*/
-public class TestCookieSource extends HiveMindTestCase
+public class CookieSourceTest extends HiveMindTestCase
{
+ // In seconds
+
+ private static final int ONE_WEEK = 7 * 24 * 60 * 60;
+
private static class ComparableCookie extends Cookie
{
- public ComparableCookie(String name, String value)
+ public ComparableCookie(String name, String value, int maxAge)
{
super(name, value);
+ setMaxAge(maxAge);
}
public boolean equals(Object obj)
@@ -44,7 +49,7 @@
Cookie c = (Cookie) obj;
return equals(getName(), c.getName()) && equals(getValue(),
c.getValue())
- && equals(getPath(), c.getPath());
+ && equals(getPath(), c.getPath()) && getMaxAge() ==
c.getMaxAge();
}
private boolean equals(Object value, Object other)
@@ -53,7 +58,7 @@
}
}
- private HttpServletRequest setupRequest(String[] nameValues)
+ private HttpServletRequest newRequest(String[] nameValues)
{
Cookie[] cookies = null;
@@ -75,18 +80,22 @@
cookies = (Cookie[]) l.toArray(new Cookie[l.size()]);
}
- MockControl control = newControl(HttpServletRequest.class);
- HttpServletRequest request = (HttpServletRequest) control.getMock();
+ HttpServletRequest request = newRequest();
request.getCookies();
- control.setReturnValue(cookies);
+ setReturnValue(request, cookies);
return request;
}
+ protected HttpServletRequest newRequest()
+ {
+ return (HttpServletRequest) newMock(HttpServletRequest.class);
+ }
+
private void attempt(String name, String expected, String[] nameValues)
{
- HttpServletRequest request = setupRequest(nameValues);
+ HttpServletRequest request = newRequest(nameValues);
CookieSourceImpl cs = new CookieSourceImpl();
@@ -120,17 +129,14 @@
public void testWriteCookie()
{
- MockControl requestControl = newControl(HttpServletRequest.class);
- HttpServletRequest request = (HttpServletRequest)
requestControl.getMock();
-
- HttpServletResponse response = (HttpServletResponse)
newMock(HttpServletResponse.class);
+ HttpServletRequest request = newRequest();
+ HttpServletResponse response = newResponse();
// Training
- request.getContextPath();
- requestControl.setReturnValue("/context");
+ trainGetContextPath(request, "/context");
- Cookie cookie = new ComparableCookie("foo", "bar");
+ Cookie cookie = new ComparableCookie("foo", "bar", ONE_WEEK);
cookie.setPath("/context/");
response.addCookie(cookie);
@@ -140,25 +146,60 @@
CookieSourceImpl cs = new CookieSourceImpl();
cs.setRequest(request);
cs.setResponse(response);
+ cs.setDefaultMaxAge(ONE_WEEK);
cs.writeCookieValue("foo", "bar");
verifyControls();
}
- public void testRemoveCookie()
+ public void testWriteCookieWithMaxAge()
{
- MockControl requestControl = newControl(HttpServletRequest.class);
- HttpServletRequest request = (HttpServletRequest)
requestControl.getMock();
-
- HttpServletResponse response = (HttpServletResponse)
newMock(HttpServletResponse.class);
+ HttpServletRequest request = newRequest();
+ HttpServletResponse response = newResponse();
// Training
+ trainGetContextPath(request, "/ctx");
+
+ Cookie cookie = new ComparableCookie("foo", "bar", -1);
+ cookie.setPath("/ctx/");
+
+ response.addCookie(cookie);
+
+ replayControls();
+
+ CookieSourceImpl cs = new CookieSourceImpl();
+ cs.setRequest(request);
+ cs.setResponse(response);
+ cs.setDefaultMaxAge(ONE_WEEK);
+
+ cs.writeCookieValue("foo", "bar", -1);
+
+ verifyControls();
+ }
+
+ private void trainGetContextPath(HttpServletRequest request, String
contextPath)
+ {
request.getContextPath();
- requestControl.setReturnValue("/context");
+ setReturnValue(request, contextPath);
+ }
+
+ private HttpServletResponse newResponse()
+ {
+ return (HttpServletResponse) newMock(HttpServletResponse.class);
+ }
+
+ public void testRemoveCookie()
+ {
+ HttpServletRequest request = newRequest();
+ HttpServletResponse response = newResponse();
+
+ // Training
+
+ trainGetContextPath(request, "/context");
- Cookie cookie = new ComparableCookie("foo", null);
+ Cookie cookie = new ComparableCookie("foo", null, 0);
cookie.setPath("/context/");
response.addCookie(cookie);
Modified:
jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/configuration.xml
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/configuration.xml?rev=329643&r1=329642&r2=329643&view=diff
==============================================================================
---
jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/configuration.xml
(original)
+++
jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/configuration.xml
Sun Oct 30 13:03:21 2005
@@ -354,6 +354,15 @@
</tr>
<tr>
+ <td>org.apache.tapestry.default-cookie-max-age</td>
+ <td>
+ The default max age (in seconds) for cookies written by Tapestry,
including the cookie used
+ to track the user's locale. A value of -1 means the cookie is a session
cookie,
+ stored only until the user's browser exits. The default value is
equivalent to one week.
+ </td>
+ </tr>
+
+ <tr>
<td>org.apache.tapestry.default-page-class</td>
Modified: jakarta/tapestry/trunk/status.xml
URL:
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=329643&r1=329642&r2=329643&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Sun Oct 30 13:03:21 2005
@@ -62,6 +62,7 @@
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-602">Add annotation to
define default value of property</action>
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-723">The "empty"
property of StringTranslator is broken</action>
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-526" due-to="Marcus
Brito">Tapestry throws a NPE if you try to configure an asset without an
extension</action>
+ <action type="fix" dev="HLS" fixes-bug="TAPESTRY-571">CookieSource
service stores only session cookies (despite documentation) and provides no way
to store a persistent cookie</action>
</release>
<release version="4.0-beta-11" date="Oct 16 2005">
<action type="fix" dev="HLS"
fixes-bug="TAPESTRY-650">ClassNotFoundException thrown when deserializing an
object from a client persistent property</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]