craigmcc 01/06/22 14:57:08
Modified: tester build.xml
tester/src/tester/org/apache/tester Session01.java
Session03.java SessionBean.java
Added: tester/src/tester/org/apache/tester/shared
SharedSessionBean.java
tester/src/tester/org/apache/tester/unshared
UnsharedSessionBean.java
Log:
Add some unit tests for bean references from a servlet (Session01 or
Session03) to beans in the following locations:
* SessionBean is in the same /WEB-INF/lib/tester.jar JAR file as the
servlet classes are
* UnsharedSessionBean is unpacked under /WEB-INF/classes in the
tester web app, but should be loaded by the same webapp class loader
that loads the servlet.
* SharedSessionBean is in a JAR file under $CATALINA_HOME/lib, so it
should be loaded by the parent classloader
There definitely appears to be a problem with class loading, and trying
this stuff fails under either WebappClassLoader and StandardClassLoader.
Right now, I've commented things in the build.xml file out so that all the
classes get built into tester.jar, and running the "HttpSession" target
all succeeds.
If you uncomment the following sets of lines in build.xml, though:
* 75-76 to copy UnsharedSessionBean to /WEB-INF/classes
* 95-96 to exclude SharedSessionBean and UnsharedSessionBean
from tester.jar
* 151-156 to create and deploy SharedSessionBean into the
$CATALINA_HOME/lib directory
then you will get NoClassDefFound exceptions when trying to execute either
Session01 or Session03.
Conclusion: class loading fails when a class within a JAR file under
/WEB-INF/lib references a class in /WEB-INF/classes, or in a shared JAR
file in the parent class loader.
Notes:
- Fails identically under WebappClassLoader and StandardClassLoader
- WebappClassLoader copies the JAR files under /WEB-INF/lib to the
work directory (why?), but it does NOT copy the /WEB-INF/classes
directory (even though the log messages say that it does).
Now for the fun part -- figuring out WHY this is happening :-(.
Revision Changes Path
1.10 +22 -2 jakarta-tomcat-4.0/tester/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/build.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- build.xml 2001/05/21 21:47:22 1.9
+++ build.xml 2001/06/22 21:57:07 1.10
@@ -71,6 +71,10 @@
<include name="**/*.txt"/>
</fileset>
</copy>
+<!--
+ <copy
file="${tester.build}/classes/org/apache/tester/unshared/UnsharedSessionBean.class"
+
tofile="${tester.build}/web/WEB-INF/classes/org/apache/tester/unshared/UnsharedSessionBean.class"/>
+-->
<copy file="src/tester/org/apache/tester/Resources01.txt"
tofile="${tester.build}/web/WEB-INF/classes/org/apache/tester/Unpacked01.txt"/>
<copy file="src/tester/org/apache/tester/Resources03.txt"
@@ -85,8 +89,14 @@
<!-- Create and install tester library -->
<mkdir dir="${tester.build}/web/WEB-INF/lib"/>
- <jar jarfile="${tester.build}/web/WEB-INF/lib/tester.jar"
- basedir="${tester.build}/classes"/>
+ <jar jarfile="${tester.build}/web/WEB-INF/lib/tester.jar">
+ <fileset dir="${tester.build}/classes">
+<!--
+ <exclude name="**/shared/*"/>
+ <exclude name="**/unshared/*"/>
+-->
+ </fileset>
+ </jar>
</target>
@@ -135,6 +145,16 @@
<fixcrlf srcdir="${tester.deploy}/bin" includes="*.sh" cr="remove"/>
<fixcrlf srcdir="${tester.deploy}/bin" includes="*.bat" cr="add"/>
<chmod perm="+x" file="${tester.deploy}/bin/tester.sh"/>
+
+ <!-- Shared Library -->
+<!--
+ <mkdir dir="${tester.deploy}/lib"/>
+ <jar jarfile="${tester.deploy}/lib/tester-shared.jar">
+ <fileset dir="${tester.build}/classes">
+ <include name="**/shared/*"/>
+ </fileset>
+ </jar>
+-->
<!-- Web Application -->
<mkdir dir="${tester.deploy}/webapps/tester"/>
1.3 +14 -1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session01.java
Index: Session01.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Session01.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Session01.java 2001/04/26 18:30:17 1.2
+++ Session01.java 2001/06/22 21:57:08 1.3
@@ -61,14 +61,17 @@
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
+import org.apache.tester.shared.SharedSessionBean;
+import org.apache.tester.unshared.UnsharedSessionBean;
+
/**
* Part 1 of Session Tests. Ensures that there is no current session, then
* creates a new session and sets a session attribute. Also, ensure that
* calling setAttribute("name", null) acts like removeAttribute().
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2001/04/26 18:30:17 $
+ * @version $Revision: 1.3 $ $Date: 2001/06/22 21:57:08 $
*/
public class Session01 extends HttpServlet {
@@ -139,6 +142,16 @@
writer.println("Session01 FAILED - setAttribute(name,null)");
ok = false;
}
+ }
+
+ // Create two more beans that will be used to test application restart
+ if (ok) {
+ SharedSessionBean ssb = new SharedSessionBean();
+ ssb.setStringProperty("Session01");
+ session.setAttribute("sharedSessionBean", ssb);
+ UnsharedSessionBean usb = new UnsharedSessionBean();
+ usb.setStringProperty("Session01");
+ session.setAttribute("unsharedSessionBean", usb);
}
// Report success if everything is still ok
1.3 +65 -1
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Session03.java 2001/02/06 17:16:24 1.2
+++ Session03.java 2001/06/22 21:57:08 1.3
@@ -61,14 +61,17 @@
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
+import org.apache.tester.shared.SharedSessionBean;
+import org.apache.tester.unshared.UnsharedSessionBean;
+
/**
* 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.2 $ $Date: 2001/02/06 17:16:24 $
+ * @version $Revision: 1.3 $ $Date: 2001/06/22 21:57:08 $
*/
public class Session03 extends HttpServlet {
@@ -127,6 +130,67 @@
ok = false;
}
}
+
+ // Retrieve and validate the shared session bean
+ SharedSessionBean ssb = null;
+ if (ok) {
+ Object object = session.getAttribute("sharedSessionBean");
+ if (object == null) {
+ writer.println("Session03 FAILED - Cannot retrieve ssb");
+ ok = false;
+ } else if (!(object instanceof SharedSessionBean)) {
+ writer.println("Session03 FAILED - Shared attribute class "
+ + object.getClass().getName());
+ ok = false;
+ } else {
+ ssb = (SharedSessionBean) object;
+ String value = ssb.getStringProperty();
+ if (!"Session01".equals(value)) {
+ writer.println("Session03 FAILED - Shared property ="
+ + value);
+ ok = false;
+ } else {
+ session.removeAttribute("sharedSessionBean");
+ String lifecycle = ssb.getLifecycle();
+ if (!"/vb/swp/sda/vu".equals(lifecycle)) {
+ writer.println("Session03 FAILED - Shared lifecycle ="
+ + lifecycle);
+ ok = false;
+ }
+ }
+ }
+ }
+
+ // Retrieve and validate the unshared session bean
+ UnsharedSessionBean usb = null;
+ if (ok) {
+ Object object = session.getAttribute("unsharedSessionBean");
+ if (object == null) {
+ writer.println("Session03 FAILED - Cannot retrieve usb");
+ ok = false;
+ } else if (!(object instanceof UnsharedSessionBean)) {
+ writer.println("Session03 FAILED - Unshared attribute class "
+ + object.getClass().getName());
+ ok = false;
+ } else {
+ usb = (UnsharedSessionBean) object;
+ String value = usb.getStringProperty();
+ if (!"Session01".equals(value)) {
+ writer.println("Session03 FAILED - Unshared property = "
+ + value);
+ ok = false;
+ } else {
+ session.removeAttribute("unsharedSessionBean");
+ String lifecycle = usb.getLifecycle();
+ if (!"/vb/swp/sda/vu".equals(lifecycle)) {
+ writer.println("Session03 FAILED - Unshared lifecycle"
+ + " = " + lifecycle);
+ ok = false;
+ }
+ }
+ }
+ }
+
// Report success if everything is still ok
if (ok)
1.4 +3 -3
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SessionBean.java 2001/05/31 22:08:41 1.3
+++ SessionBean.java 2001/06/22 21:57:08 1.4
@@ -70,7 +70,7 @@
* so that instances can be saved and restored across server restarts.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2001/05/31 22:08:41 $
+ * @version $Revision: 1.4 $ $Date: 2001/06/22 21:57:08 $
*/
public class SessionBean implements
@@ -83,7 +83,7 @@
/**
* The lifecycle events that have happened on this bean instance.
*/
- private String lifecycle = "";
+ protected String lifecycle = "";
public String getLifecycle() {
return (this.lifecycle);
@@ -97,7 +97,7 @@
/**
* A string property.
*/
- private String stringProperty = "Default String Property Value";
+ protected String stringProperty = "Default String Property Value";
public String getStringProperty() {
return (this.stringProperty);
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/shared/SharedSessionBean.java
Index: SharedSessionBean.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.shared;
import java.io.Serializable;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import org.apache.tester.SessionBean;
/**
* Simple JavaBean to use for session attribute tests. It is Serializable
* so that instances can be saved and restored across server restarts.
* <p>
* This bean is functionally equivalent to
* <code>org.apache.tester.SessionBean</code>, but will be deployed inside
* <code>$CATALINA_HOME/lib/tester-shared.jar</code> instead of inside
* <code>/WEB-INF/lib/tester.jar</code>.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/06/22 21:57:08 $
*/
public class SharedSessionBean extends SessionBean implements
HttpSessionActivationListener, HttpSessionBindingListener, Serializable {
/**
* Return a string representation of this bean.
*/
public String toString() {
StringBuffer sb = new StringBuffer("SharedSessionBean[lifecycle=");
sb.append(this.lifecycle);
sb.append(",stringProperty=");
sb.append(this.stringProperty);
sb.append("]");
return (sb.toString());
}
}
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/unshared/UnsharedSessionBean.java
Index: UnsharedSessionBean.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.unshared;
import java.io.Serializable;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import org.apache.tester.SessionBean;
/**
* Simple JavaBean to use for session attribute tests. It is Serializable
* so that instances can be saved and restored across server restarts.
* <p>
* This bean is functionally equivalent to
* <code>org.apache.tester.SessionBean</code>, but will be deployed under
* <code>/WEB-INF/classes</code> instead of inside
* <code>/WEB-INF/lib/tester.jar</code>.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/06/22 21:57:08 $
*/
public class UnsharedSessionBean extends SessionBean implements
HttpSessionActivationListener, HttpSessionBindingListener, Serializable {
/**
* Return a string representation of this bean.
*/
public String toString() {
StringBuffer sb = new StringBuffer("UnsharedSessionBean[lifecycle=");
sb.append(this.lifecycle);
sb.append(",stringProperty=");
sb.append(this.stringProperty);
sb.append("]");
return (sb.toString());
}
}