Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 62379 invoked by uid 500); 4 Feb 2001 04:49:39 -0000 Delivered-To: apmail-jakarta-tomcat-4.0-cvs@apache.org Received: (qmail 62372 invoked by uid 1059); 4 Feb 2001 04:49:39 -0000 Date: 4 Feb 2001 04:49:39 -0000 Message-ID: <20010204044939.62371.qmail@apache.org> From: craigmcc@apache.org To: jakarta-tomcat-4.0-cvs@apache.org Subject: cvs commit: jakarta-tomcat-4.0/tester/web/WEB-INF web.xml craigmcc 01/02/03 20:49:39 Modified: tester/src/bin tester.xml tester/src/tester/org/apache/tester TestClient.java tester/web/WEB-INF web.xml Added: tester/src/tester/org/apache/tester Session01.java Session02.java Session03.java SessionBean.java Log: Add a series of unit tests for session attributes. TODO: Add a mechanism to test session reloading after a webapp restart. Revision Changes Path 1.11 +35 -0 jakarta-tomcat-4.0/tester/src/bin/tester.xml Index: tester.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- tester.xml 2001/02/04 01:46:38 1.10 +++ tester.xml 2001/02/04 04:49:38 1.11 @@ -381,4 +381,39 @@ + + + + + + + + + + + + + + + + + + + 1.6 +73 -1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/TestClient.java Index: TestClient.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/TestClient.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TestClient.java 2001/01/27 01:49:14 1.5 +++ TestClient.java 2001/02/04 04:49:38 1.6 @@ -115,7 +115,7 @@ * * * @author Craig R. McClanahan - * @version $Revision: 1.5 $ $Date: 2001/01/27 01:49:14 $ + * @version $Revision: 1.6 $ $Date: 2001/02/04 04:49:38 $ */ public class TestClient extends Task { @@ -194,6 +194,21 @@ /** + * Should we join the session whose session identifier was returned + * on the previous request. + */ + protected boolean joinSession = false; + + public boolean getJoinSession() { + return (this.joinSession); + } + + public void setJoinSession(boolean joinSession) { + this.joinSession = true; + } + + + /** * The HTTP response message to be expected in the response. */ protected String message = null; @@ -308,6 +323,17 @@ } + // ------------------------------------------------------- Static Variables + + + /** + * The session identifier returned by the most recent request, or + * null if the previous request did not specify a session + * identifier. + */ + protected static String sessionId = null; + + // --------------------------------------------------------- Public Methods @@ -363,6 +389,16 @@ } else { conn.setDoOutput(false); } + + // Send the session id cookie (if any) + if (joinSession && (sessionId != null)) { + conn.setRequestProperty("Cookie", + "JSESSIONID=" + sessionId); + if (debug >= 1) + System.out.println("INPH: Cookie: JSESSIONID=" + + sessionId); + } + conn.setFollowRedirects(false); conn.setRequestMethod(method); if (inHeaders != null) { @@ -432,6 +468,8 @@ if (debug >= 1) System.out.println("HEAD: " + name + ": " + value); save(name, value); + if ("Set-Cookie".equals(name)) + parseSession(value); } if (debug >= 1) { System.out.println("DATA: " + outData); @@ -539,6 +577,14 @@ pw.print("Content-Length: " + inContent.length() + "\r\n"); } + // Send the session id cookie (if any) + if (joinSession && (sessionId != null)) { + pw.println("Cookie: JSESSIONID=" + sessionId); + if (debug >= 1) + System.out.println("INPH: Cookie: JSESSIONID=" + + sessionId); + } + // Send the specified headers (if any) if (inHeaders != null) { String headers = inHeaders; @@ -622,6 +668,8 @@ System.out.println("HEAD: " + headerName + ": " + headerValue); save(headerName, headerValue); + if ("Set-Cookie".equals(headerName)) + parseSession(headerValue); } } @@ -714,6 +762,30 @@ if (throwable != null) throwable.printStackTrace(System.out); } + + } + + + /** + * Parse the session identifier from the specified Set-Cookie value. + * + * @param value The Set-Cookie value to parse + */ + protected void parseSession(String value) { + + if (value == null) + return; + int equals = value.indexOf("JSESSIONID="); + if (equals < 0) + return; + value = value.substring(equals + "JSESSIONID=".length()); + int semi = value.indexOf(";"); + if (semi >= 0) + value = value.substring(0, semi); + + if (debug >= 1) + System.out.println("SESSION ID: " + value); + sessionId = value; } 1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session01.java Index: Session01.java =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999, 2000 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation ." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact . * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see . * * * * ========================================================================= */ package org.apache.tester; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Part 1 of Session Tests. Ensures that there is no current session, then * creates a new session and sets a session attribute. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2001/02/04 04:49:38 $ */ public class Session01 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); // Ensure that there is no current session boolean ok = true; HttpSession session = request.getSession(false); if (session != null) { writer.println("Session01 FAILED - Requested existing session " + session.getId()); ok = false; } // Create a new session if (ok) { session = request.getSession(true); if (session == null) { writer.println("Session01 FAILED - No session created"); ok = false; } } // Ensure that there is no existing attribute if (ok) { if (session.getAttribute("sessionBean") != null) { writer.println("Session01 FAILED - Attribute already exists"); ok = false; } } // Create and stash a session attribute if (ok) { SessionBean bean = new SessionBean(); bean.setStringProperty("Session01"); session.setAttribute("sessionBean", bean); } // Ensure that we can retrieve the attribute successfully if (ok) { Object bean = session.getAttribute("sessionBean"); if (bean == null) { writer.println("Session01 FAILED - Cannot retrieve attribute"); ok = false; } else if (!(bean instanceof SessionBean)) { writer.println("Session01 FAILED - Attribute instance of " + bean.getClass().getName()); ok = false; } else { String value = ((SessionBean) bean).getStringProperty(); if (!"Session01".equals(value)) { writer.println("Session01 FAILED - Property = " + value); ok = false; } } } // Report success if everything is still ok if (ok) writer.println("Session01 PASSED"); while (true) { String message = StaticLogger.read(); if (message == null) break; writer.println(message); } StaticLogger.reset(); } } 1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session02.java Index: Session02.java =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999, 2000 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation ." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact . * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see . * * * * ========================================================================= */ package org.apache.tester; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Part 2 of Session Tests. Ensures that there is an existing session, and * that the session bean stashed in Part 1 can be retrieved successfully. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2001/02/04 04:49:38 $ */ public class Session02 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); // Ensure that there is a current session boolean ok = true; HttpSession session = request.getSession(false); if (session == null) { writer.println("Session02 FAILED - No existing session " + request.getRequestedSessionId()); ok = false; } // Ensure that we can retrieve the attribute successfully if (ok) { Object bean = session.getAttribute("sessionBean"); if (bean == null) { writer.println("Session02 FAILED - Cannot retrieve attribute"); ok = false; } else if (!(bean instanceof SessionBean)) { writer.println("Session02 FAILED - Attribute instance of " + bean.getClass().getName()); ok = false; } else { String value = ((SessionBean) bean).getStringProperty(); if (!"Session01".equals(value)) { writer.println("Session02 FAILED - Property = " + value); ok = false; } } } // Report success if everything is still ok if (ok) writer.println("Session02 PASSED"); while (true) { String message = StaticLogger.read(); if (message == null) break; writer.println(message); } StaticLogger.reset(); } } 1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session03.java Index: Session03.java =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999, 2000 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation ." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact . * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see . * * * * ========================================================================= */ package org.apache.tester; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Part 3 of Session Tests. Ensures that there is an existing session, and * that the session bean stashed in Part 1 can be retrieved successfully. * Then, it removes that attribute and verifies successful removal. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2001/02/04 04:49:38 $ */ public class Session03 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); // Ensure that there is a current session boolean ok = true; HttpSession session = request.getSession(false); if (session == null) { writer.println("Session03 FAILED - No existing session " + request.getRequestedSessionId()); ok = false; } // Ensure that we can retrieve the attribute successfully if (ok) { Object bean = session.getAttribute("sessionBean"); if (bean == null) { writer.println("Session03 FAILED - Cannot retrieve attribute"); ok = false; } else if (!(bean instanceof SessionBean)) { writer.println("Session03 FAILED - Attribute instance of " + bean.getClass().getName()); ok = false; } else { String value = ((SessionBean) bean).getStringProperty(); if (!"Session01".equals(value)) { writer.println("Session03 FAILED - Property = " + value); ok = false; } } } // Remove the attribute and guarantee that this was successful if (ok) { session.removeAttribute("sessionBean"); if (session.getAttribute("sessionBean") != null) { writer.println("Session03 FAILED - Removal failed"); ok = false; } } // Report success if everything is still ok if (ok) writer.println("Session03 PASSED"); while (true) { String message = StaticLogger.read(); if (message == null) break; writer.println(message); } StaticLogger.reset(); } } 1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionBean.java Index: SessionBean.java =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999, 2000 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation ." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact . * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see . * * * * ========================================================================= */ package org.apache.tester; import java.io.Serializable; /** * Simple JavaBean to use for session attribute tests. It is Serializable * so that instances can be saved and restored across server restarts. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2001/02/04 04:49:38 $ */ public class SessionBean implements Serializable { // ------------------------------------------------------------- Properties /** * A string property. */ private String stringProperty = "Default String Property Value"; public String getStringProperty() { return (this.stringProperty); } public void setStringProperty(String stringProperty) { this.stringProperty = stringProperty; } } 1.9 +60 -0 jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml Index: web.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- web.xml 2001/01/27 01:49:14 1.8 +++ web.xml 2001/02/04 04:49:39 1.9 @@ -111,6 +111,21 @@ + HttpFilter + /WrappedSession01 + + + + HttpFilter + /WrappedSession02 + + + + HttpFilter + /WrappedSession03 + + + GenericFilter /WrappedSetBufferSize01 @@ -204,6 +219,21 @@ + Session01 + org.apache.tester.Session01 + + + + Session02 + org.apache.tester.Session02 + + + + Session03 + org.apache.tester.Session03 + + + SetBufferSize01 org.apache.tester.SetBufferSize01 @@ -369,6 +399,36 @@ Resources04 /WrappedResources04 + + + + Session01 + /Session01 + + + + Session01 + /WrappedSession01 + + + + Session02 + /Session02 + + + + Session02 + /WrappedSession02 + + + + Session03 + /Session03 + + + + Session03 + /WrappedSession03