craigmcc 01/02/06 09:16:28
Modified: tester/src/bin tester.xml
tester/src/tester/org/apache/tester Session03.java
SessionBean.java
tester/web/WEB-INF web.xml
Added: tester/src/tester/org/apache/tester Include02.java
Include02a.java
Log:
Enhance the session management test to validate that the appropriate
lifecycle events have been called at the correct times across an application
shutdown and restart.
Add a unit test for the corrected handling of exceptions thrown by
an included or forwarded-to servlet.
Revision Changes Path
1.14 +26 -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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- tester.xml 2001/02/04 05:34:18 1.13
+++ tester.xml 2001/02/06 17:16:21 1.14
@@ -115,6 +115,32 @@
request="${context.path}/WrappedInclude01"
outContent="Include01 PASSED"/>
+ <!-- ========== Included Servlet Throwing Exceptions ================== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/Include02?exception=IOException"
+ outContent="Include02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/Include02?exception=ServletException"
+ outContent="Include02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/Include02?exception=NullPointerException"
+ outContent="Include02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/WrappedInclude02?exception=IOException"
+ outContent="Include02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/WrappedInclude02?exception=ServletException"
+ outContent="Include02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/WrappedInclude02?exception=NullPointerException"
+ outContent="Include02 PASSED"/>
+
</target>
1.2 +18 -6
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session03.java
Index: Session03.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session03.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Session03.java 2001/02/04 04:49:38 1.1
+++ Session03.java 2001/02/06 17:16:24 1.2
@@ -68,7 +68,7 @@
* Then, it removes that attribute and verifies successful removal.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/02/04 04:49:38 $
+ * @version $Revision: 1.2 $ $Date: 2001/02/06 17:16:24 $
*/
public class Session03 extends HttpServlet {
@@ -89,17 +89,19 @@
}
// Ensure that we can retrieve the attribute successfully
+ SessionBean bean = null;
if (ok) {
- Object bean = session.getAttribute("sessionBean");
- if (bean == null) {
+ Object object = session.getAttribute("sessionBean");
+ if (object == null) {
writer.println("Session03 FAILED - Cannot retrieve attribute");
ok = false;
- } else if (!(bean instanceof SessionBean)) {
+ } else if (!(object instanceof SessionBean)) {
writer.println("Session03 FAILED - Attribute instance of " +
- bean.getClass().getName());
+ object.getClass().getName());
ok = false;
} else {
- String value = ((SessionBean) bean).getStringProperty();
+ bean = (SessionBean) object;
+ String value = bean.getStringProperty();
if (!"Session01".equals(value)) {
writer.println("Session03 FAILED - Property = " + value);
ok = false;
@@ -115,6 +117,16 @@
ok = false;
}
}
+
+ // Validate the bean lifecycle of this bean
+ if (ok) {
+ String lifecycle = bean.getLifecycle();
+ if (!"/vb/swp/sda/vu".equals(lifecycle)) {
+ writer.println("Session03 FAILED - Invalid bean lifecycle '" +
+ lifecycle + "'");
+ ok = false;
+ }
+ }
// Report success if everything is still ok
if (ok)
1.2 +75 -2
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionBean.java
Index: SessionBean.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SessionBean.java 2001/02/04 04:49:38 1.1
+++ SessionBean.java 2001/02/06 17:16:24 1.2
@@ -59,6 +59,10 @@
import java.io.Serializable;
+import javax.servlet.http.HttpSessionActivationListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionEvent;
/**
@@ -66,16 +70,31 @@
* 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 $
+ * @version $Revision: 1.2 $ $Date: 2001/02/06 17:16:24 $
*/
-public class SessionBean implements Serializable {
+public class SessionBean implements
+ HttpSessionActivationListener, HttpSessionBindingListener, Serializable {
// ------------------------------------------------------------- Properties
/**
+ * The lifecycle events that have happened on this bean instance.
+ */
+ private String lifecycle = "";
+
+ public String getLifecycle() {
+ return (this.lifecycle);
+ }
+
+ public void setLifecycle(String lifecycle) {
+ this.lifecycle = lifecycle;
+ }
+
+
+ /**
* A string property.
*/
private String stringProperty = "Default String Property Value";
@@ -89,5 +108,59 @@
}
+ // ---------------------------------- HttpSessionActivationListener Methods
+
+
+ /**
+ * Receive notification that this session was activated.
+ *
+ * @param event The session event that has occurred
+ */
+ public void sessionDidActivate(HttpSessionEvent event) {
+
+ lifecycle += "/sda";
+
+ }
+
+
+ /**
+ * Receive notification that this session will be passivated.
+ *
+ * @param event The session event that has occurred
+ */
+ public void sessionWillPassivate(HttpSessionEvent event) {
+
+ lifecycle += "/swp";
+
+ }
+
+
+ // ------------------------------------- HttpSessionBindingListener Methods
+
+
+ /**
+ * Receive notification that this attribute has been bound.
+ *
+ * @param event The session event that has occurred
+ */
+ public void valueBound(HttpSessionBindingEvent event) {
+
+ lifecycle += "/vb";
+
+ }
+
+
+ /**
+ * Receive notification that this attribute has been unbound.
+ *
+ * @param event The session event that has occurred
+ */
+ public void valueUnbound(HttpSessionBindingEvent event) {
+
+ lifecycle += "/vu";
+
+ }
+
}
+
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Include02.java
Index: Include02.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 <http://www.apache.org/>." *
* *
* 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 <[EMAIL PROTECTED]>. *
* *
* 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 <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Positive test for handling exceptions thrown by an included servlet.
* Request parameter <strong>exception</strong> is used to indicate the type
* of exception that should be thrown, which must be one of
* <code>IOException</code>, <code>ServletException</code>, or
* <code>ServletException</code>. According to the spec, any exceptions of
* these types should be propogated back to the caller unchanged.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/02/06 17:16:23 $
*/
public class Include02 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
boolean ok = true;
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/Include02a");
if (rd == null) {
writer.println("Include02 FAILED - No RequestDispatcher returned");
ok = false;
}
String type = request.getParameter("exception");
if (ok) {
if (type == null) {
writer.println("Include02 FAILED - No exception type specified");
ok = false;
} else if (!type.equals("IOException") &&
!type.equals("ServletException") &&
!type.equals("NullPointerException")) {
writer.println("Include02 FAILED - Invalid exception type " +
type + " requested");
ok = false;
}
}
IOException ioException = null;
ServletException servletException = null;
Throwable throwable = null;
try {
if (ok)
rd.include(request, response);
} catch (IOException e) {
ioException = e;
} catch (ServletException e) {
servletException = e;
} catch (Throwable e) {
throwable = e;
}
if (ok) {
if (type.equals("IOException")) {
if (ioException == null) {
writer.println("Include02 FAILED - No IOException thrown");
ok = false;
} else {
String message = ioException.getMessage();
if (!"Include02 IOException".equals(message)) {
writer.println("Include02 FAILED - IOException was " +
message);
ok = false;
}
}
} else if (type.equals("ServletException")) {
if (servletException == null) {
writer.println("Include02 FAILED - No ServletException thrown");
ok = false;
} else {
String message = servletException.getMessage();
if (!"Include02 ServletException".equals(message)) {
writer.println("Include02 FAILED - ServletException was " +
message);
ok = false;
}
}
} else if (type.equals("NullPointerException")) {
if (throwable == null) {
writer.println("Include02 FAILED - No NullPointerException
thrown");
ok = false;
} else if (!(throwable instanceof NullPointerException)) {
writer.println("Include02 FAILED - Thrown Exception was " +
throwable.getClass().getName());
ok = false;
} else {
String message = throwable.getMessage();
if (!"Include02 NullPointerException".equals(message)) {
writer.println("Include02 FAILED - NullPointerException was " +
message);
ok = false;
}
}
}
}
if (ok)
writer.println("Include02 PASSED");
StaticLogger.reset();
}
}
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Include02a.java
Index: Include02a.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 <http://www.apache.org/>." *
* *
* 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 <[EMAIL PROTECTED]>. *
* *
* 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 <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Included servlet for the test performed by Include02.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/02/06 17:16:24 $
*/
public class Include02a extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String type = request.getParameter("exception");
if (type == null)
return;
else if (type.equals("IOException"))
throw new IOException("Include02 IOException");
else if (type.equals("ServletException"))
throw new ServletException("Include02 ServletException");
else if (type.equals("NullPointerException"))
throw new NullPointerException("Include02 NullPointerException");
}
}
1.10 +35 -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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- web.xml 2001/02/04 04:49:39 1.9
+++ web.xml 2001/02/06 17:16:27 1.10
@@ -86,6 +86,11 @@
</filter-mapping>
<filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedInclude02</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
<filter-name>GenericFilter</filter-name>
<url-pattern>/WrappedReset01</url-pattern>
</filter-mapping>
@@ -194,6 +199,16 @@
</servlet>
<servlet>
+ <servlet-name>Include02</servlet-name>
+ <servlet-class>org.apache.tester.Include02</servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Include02a</servlet-name>
+ <servlet-class>org.apache.tester.Include02a</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>Reset01</servlet-name>
<servlet-class>org.apache.tester.Reset01</servlet-class>
</servlet>
@@ -349,6 +364,26 @@
<servlet-mapping>
<servlet-name>Include01</servlet-name>
<url-pattern>/WrappedInclude01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Include02</servlet-name>
+ <url-pattern>/Include02</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Include02</servlet-name>
+ <url-pattern>/WrappedInclude02</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Include02a</servlet-name>
+ <url-pattern>/Include02a</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Include02a</servlet-name>
+ <url-pattern>/WrappedInclude02a</url-pattern>
</servlet-mapping>
<servlet-mapping>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]