Title: [2490] trunk/openejb1: Tomcat 5.5 integration works
- Revision
- 2490
- Author
- dblevins
- Date
- 2006-02-22 22:32:23 -0500 (Wed, 22 Feb 2006)
Log Message
Tomcat 5.5 integration works
Modified Paths
Added Paths
Diff
Modified: trunk/openejb1/maven.xml (2489 => 2490)
--- trunk/openejb1/maven.xml 2006-02-23 00:27:34 UTC (rev 2489)
+++ trunk/openejb1/maven.xml 2006-02-23 03:32:23 UTC (rev 2490)
@@ -642,4 +642,27 @@
<replace file="${tomcat.home}/webapps/movies/WEB-INF/web.xml" token="@OPENEJB_HOME@" value="${openejb.home}"/>
</goal>
+ <goal name="test:local">
+ <j:set var="openejb.jar" value="target/openejb-${pom.currentVersion}/lib/openejb-core-${pom.currentVersion}.jar"/>
+ <java jar="${openejb.jar}" fork="yes">
+ <arg value="test"/>
+ <arg value="local"/>
+ </java>
+ </goal>
+
+ <goal name="test:remote">
+ <j:set var="openejb.jar" value="target/openejb-${pom.currentVersion}/lib/openejb-core-${pom.currentVersion}.jar"/>
+ <java jar="${openejb.jar}" fork="yes">
+ <arg value="test"/>
+ <arg value="remote"/>
+ </java>
+ </goal>
+
+ <goal name="test:httpejb">
+ <j:set var="openejb.jar" value="target/openejb-${pom.currentVersion}/lib/openejb-core-${pom.currentVersion}.jar"/>
+ <java jar="${openejb.jar}" fork="yes">
+ <arg value="test"/>
+ <arg value="httpejb"/>
+ </java>
+ </goal>
</project>
Modified: trunk/openejb1/modules/core/src/java/org/openejb/loader/TomcatClassPath.java (2489 => 2490)
--- trunk/openejb1/modules/core/src/java/org/openejb/loader/TomcatClassPath.java 2006-02-23 00:27:34 UTC (rev 2489)
+++ trunk/openejb1/modules/core/src/java/org/openejb/loader/TomcatClassPath.java 2006-02-23 03:32:23 UTC (rev 2490)
@@ -45,6 +45,8 @@
package org.openejb.loader;
+import sun.misc.URLClassPath;
+
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
@@ -70,6 +72,7 @@
*/
private Method addRepositoryMethod;
private Method addURLMethod;
+ private Method getLoaderMethod;
public TomcatClassPath() {
@@ -87,6 +90,10 @@
} catch (Exception tomcat5Exception) {
throw new RuntimeException("Failed accessing classloader for Tomcat 4 or 5", tomcat5Exception);
}
+ try {
+ getLoaderMethod = getLoaderMethod();
+ } catch (Exception e) {
+ }
}
}
@@ -125,18 +132,31 @@
}
public void _addJarToPath(URL jar) throws Exception {
- String path = jar.toExternalForm();
- this.addRepository(path);
- }
-
- public void addRepository(String path) throws Exception {
if (addRepositoryMethod != null){
+ String path = jar.toExternalForm();
addRepositoryMethod.invoke(getClassLoader(), new Object[]{path});
} else {
- addURLMethod.invoke(getClassLoader(), new Object[]{new File(path).toURL()});
+ addURLMethod.invoke(getClassLoader(), new Object[]{jar});
+ int index = 0;
+ while (getLoader(index++) != null);
}
}
+ private Object getLoader(int i) {
+ if (getLoaderMethod == null){
+ return null;
+ }
+
+ try {
+ sun.misc.URLClassPath cp = getURLClassPath((URLClassLoader) getClassLoader());
+ Object object = getLoaderMethod.invoke(cp, new Object[]{new Integer(i)});
+ return object;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
protected void rebuild() {
try {
sun.misc.URLClassPath cp = getURLClassPath((URLClassLoader) getClassLoader());
@@ -191,6 +211,23 @@
});
}
+ private java.lang.reflect.Method getLoaderMethod() throws Exception {
+ return (java.lang.reflect.Method) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ java.lang.reflect.Method method = null;
+ try {
+ Class clazz = URLClassPath.class;
+ method = clazz.getDeclaredMethod("getLoader", new Class[]{Integer.TYPE});
+ method.setAccessible(true);
+ return method;
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ return method;
+ }
+ });
+ }
+
private Method getAddRepositoryMethod() throws Exception {
return (Method) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
Added: trunk/openejb1/modules/core/src/test/org/openejb/cli/MainTest.java (2489 => 2490)
--- trunk/openejb1/modules/core/src/test/org/openejb/cli/MainTest.java 2006-02-23 00:27:34 UTC (rev 2489)
+++ trunk/openejb1/modules/core/src/test/org/openejb/cli/MainTest.java 2006-02-23 03:32:23 UTC (rev 2490)
@@ -0,0 +1,14 @@
+package org.openejb.cli;
+/**
+ * @version $Revision$ $Date$
+ */
+
+import junit.framework.*;
+import org.openejb.cli.Main;
+
+public class MainTest extends TestCase {
+
+ public void testMain() throws Exception {
+
+ }
+}
\ No newline at end of file
Added: trunk/openejb1/modules/core/src/test/org/openejb/loader/SystemClassPathTest.java (2489 => 2490)
--- trunk/openejb1/modules/core/src/test/org/openejb/loader/SystemClassPathTest.java 2006-02-23 00:27:34 UTC (rev 2489)
+++ trunk/openejb1/modules/core/src/test/org/openejb/loader/SystemClassPathTest.java 2006-02-23 03:32:23 UTC (rev 2490)
@@ -0,0 +1,36 @@
+package org.openejb.loader;
+/**
+ * @version $Revision$ $Date$
+ */
+
+import junit.framework.*;
+import org.openejb.loader.SystemClassPath;
+
+import java.net.URL;
+
+public class SystemClassPathTest extends TestCase {
+ SystemClassPath systemClassPath;
+
+ public void testAddJarToPath() throws Exception {
+ SystemClassPath systemClassPath = new SystemClassPath();
+
+ ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+
+ try {
+ systemClassLoader.loadClass("org.apache.commons.io.HexDump");
+ fail("Class already exists");
+ } catch (ClassNotFoundException e) {
+ // this should fail
+ }
+
+ URL commonsIoJar = new URL("http://www.ibiblio.org/maven/commons-io/jars/commons-io-1.0.jar");
+ systemClassPath.addJarToPath(commonsIoJar);
+
+ try {
+ systemClassLoader.loadClass("org.apache.commons.io.HexDump");
+ } catch (ClassNotFoundException e) {
+ // this should fail pass
+ fail("Class should exist");
+ }
+ }
+}
\ No newline at end of file