JBossWeb SVN: r235 - sandbox/webapps/src.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-08-22 10:53:01 -0400 (Wed, 22 Aug 2007)
New Revision: 235
Modified:
sandbox/webapps/src/GrowCookies.java
sandbox/webapps/src/MyCookies.java
Log:
Improve the testing by displaying the excepted result.
Modified: sandbox/webapps/src/GrowCookies.java
===================================================================
--- sandbox/webapps/src/GrowCookies.java 2007-08-22 09:10:27 UTC (rev 234)
+++ sandbox/webapps/src/GrowCookies.java 2007-08-22 14:53:01 UTC (rev 235)
@@ -75,6 +75,14 @@
}
out.println("Size (names+values)=" + size + "<br>");
+ String createValue = request.getParameter("create");
+ int icreate = 1;
+ if (createValue != null) {
+ Integer iwait = new Integer(createValue);
+ icreate = iwait.intValue();
+ }
+ out.println("creates " + icreate + " new cookies");
+
/* value of the new cookie */
StringBuffer buffer = new StringBuffer();
// buffer.append("<xml><name>John Doe</name><age attribute=\"this breaks\">45</age></xml>");
@@ -83,13 +91,16 @@
buffer.append("<xml><name>John Doe</name><age attribute=this_breaks>45</age></xml>");
buffer.append("<xml><name>John Doe</name><age attribute=this_breaks>45</age></xml>");
buffer.append("<xml><name>John Doe</name><age attribute=this_breaks>45</age></xml>");
- /* name of the new cookie */
- String name = String.valueOf(i);
- name.concat("Test");
- Cookie cookie = new Cookie(name, buffer.toString());
- response.addCookie(cookie);
+ for (int j=0; j<icreate; j++) {
+ /* name of the new cookie */
+ String name = String.valueOf(i + j);
+ name = name.concat("Test");
+ Cookie cookie = new Cookie(name, buffer.toString());
+ response.addCookie(cookie);
+ }
+
/* Get the servlet name */
String servletname = request.getServletPath().substring(1);
Modified: sandbox/webapps/src/MyCookies.java
===================================================================
--- sandbox/webapps/src/MyCookies.java 2007-08-22 09:10:27 UTC (rev 234)
+++ sandbox/webapps/src/MyCookies.java 2007-08-22 14:53:01 UTC (rev 235)
@@ -37,6 +37,26 @@
public class MyCookies extends HttpServlet {
+ public class Test {
+ String Name;
+ String Value;
+ public Test(String Name, String Value) {
+ this.Name = Name;
+ this.Value = Value;
+ }
+ }
+ public Cookie CreateCookie(Test test) {
+ Cookie cookie = new Cookie(test.Name, test.Value);
+ return cookie;
+ }
+ public String GetVal(Test[] test, String Name) {
+ for (int i=0; i<test.length; i++) {
+ if (Name.equals(test[i].Name))
+ return test[i].Value;
+ }
+ return "Failed: Unknown";
+ }
+
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
@@ -57,35 +77,40 @@
out.println("<h3>" + title + "</h3>");
+ /*
+ * create the name/value pairs
+ */
+ Test[] mytest = new Test[10];
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<xml><name>John Doe</name><age attribute=\"this breaks\">45</age></xml>");
+ mytest[0] = new Test("xmlCookie",buffer.toString());
+ mytest[1] = new Test("Multiparam","I am testing...");
+ mytest[2] = new Test("SingleParam","I_am_testing...");
+ mytest[3] = new Test("Quoted1","\"I am testing...\"");
+ mytest[4] = new Test("Quoted2","I am \"testing...");
+ // A " in a not quoted-string is not ok, see rfc 2965 and 2616 */
+ mytest[5] = new Test("Quoted3","I_am\"_esting...");
+ mytest[6] = new Test("Quoted4","\\\"I am\"_esting...\\\"");
+ mytest[7] = new Test("Quoted5","'");
+ mytest[8] = new Test("Quoted6","A");
+ mytest[9] = new Test("Quoted7","val'ue");
+ mytest[10] = new Test("Quoted8","I am \" testing...");
+
Cookie[] cookies = request.getCookies();
if(cookies != null) {
for(int i=0;i<cookies.length;i++) {
out.println("Name=" + cookies[i].getName() + "<br>");
out.println("Value=" + cookies[i].getValue() + "<br>");
+ out.println("Expected=" + GetVal(mytest, cookies[i].getName()) + "<br>");
}
}
- StringBuffer buffer = new StringBuffer();
- buffer.append("<xml><name>John Doe</name><age attribute=\"this breaks\">45</age></xml>");
- Cookie cookie = new Cookie("xmlCookie",buffer.toString());
- response.addCookie(cookie);
- Cookie cookie2 = new Cookie("Multiparam","I am testing...");
- response.addCookie(cookie2);
- Cookie cookie3 = new Cookie("SingleParam","I_am_testing...");
- response.addCookie(cookie3);
- Cookie cookie4 = new Cookie("Quoted1","\"I am testing...\"");
- response.addCookie(cookie4);
- Cookie cookie5 = new Cookie("Quoted2","I am \"testing...");
- response.addCookie(cookie5);
- // A " in a not quoted-string is not ok, see rfc 2965 and 2616 */
- Cookie cookie6 = new Cookie("Quoted3","I_am\"_esting...");
- response.addCookie(cookie6);
- Cookie cookie7 = new Cookie("Quoted4","\\\"I am\"_esting...\\\"");
- response.addCookie(cookie7);
- Cookie cookie8 = new Cookie("Quoted5","'");
- response.addCookie(cookie8);
- Cookie cookie9 = new Cookie("Quoted6","A");
- response.addCookie(cookie9);
+ /* create the cookies */
+ for (int i=0; i<mytest.length; i++) {
+ Cookie cookie = CreateCookie(mytest[i]);
+ response.addCookie(cookie);
+ }
+
out.println("<P>");
out.println("<P>");