morrijr 01/10/31 08:16:28
Modified: src/org/apache/cocoon/servlet CocoonServlet.java
Log:
Changing getRealPath->getResource breaks under Catalina. See thread 'classDirURL =
jndi protocol'
Revision Changes Path
1.51 +54 -25 xml-cocoon2/src/org/apache/cocoon/servlet/CocoonServlet.java
Index: CocoonServlet.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/servlet/CocoonServlet.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- CocoonServlet.java 2001/10/30 13:20:28 1.50
+++ CocoonServlet.java 2001/10/31 16:16:28 1.51
@@ -39,6 +39,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
+import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -58,7 +59,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a>
- * @version CVS $Revision: 1.50 $ $Date: 2001/10/30 13:20:28 $
+ * @version CVS $Revision: 1.51 $ $Date: 2001/10/31 16:16:28 $
*/
public class CocoonServlet extends HttpServlet {
@@ -285,7 +286,7 @@
/**
* This builds the important ClassPath used by this Servlet. It
* does so in a Servlet Engine neutral way. It uses the
- * <code>ServletContext</code>'s <code>getResource</code> method
+ * <code>ServletContext</code>'s <code>getRealPath</code> method
* to get the Servlet 2.2 identified classes and lib directories.
* It iterates in alphabetical order through every file in the
* lib directory and adds it to the classpath.
@@ -294,6 +295,8 @@
* In order to protect ourselves from skitzofrantic classloaders,
* we need to work with a known one.
*
+ * We need to get this to work properly when Cocoon is in a war.
+ *
* @param context The ServletContext to perform the lookup.
*
* @throws ServletException
@@ -302,32 +305,58 @@
throws ServletException {
StringBuffer buildClassPath = new StringBuffer();
- URL classDirURL = null;
- URL libDirURL = null;
- try {
- classDirURL = this.servletContext.getResource("/WEB-INF/classes");
- } catch (java.net.MalformedURLException me) {
- this.log.warn("Unable to add WEB-INF/classes to the classpath", me);
- }
- try {
- libDirURL = this.servletContext.getResource("/WEB-INF/lib");
- } catch (java.net.MalformedURLException me) {
- this.log.warn("Unable to add WEB-INF/lib to the classpath", me);
- }
-
File root = null;
- if (libDirURL != null && libDirURL.toExternalForm().startsWith("file:")) {
- root = new File(libDirURL.toExternalForm().substring(5));
- }
+
+ if(servletContextPath != null) {
+ // Old method. There *MUST* be a better method than this...
+
+ String classDir = this.servletContext.getRealPath("/WEB-INF/classes");
+ String libDir = this.servletContext.getRealPath("/WEB-INF/lib");
+
+ if(libDir != null)
+ root = new File(libDir);
+
+ if(classDir != null) {
+ buildClassPath.append(classDir);
+
+ if (this.addClassDirs) {
+ try {
+ classLoader.addDirectory(new File(classDir));
+ } catch (Exception e) {
+ log.debug("Could not add directory" + classDir, e);
+ }
+ }
+ }
+ } else {
+ // New(ish) method for war'd deployments
+ URL classDirURL = null;
+ URL libDirURL = null;
+
+ try {
+ classDirURL = this.servletContext.getResource("/WEB-INF/classes");
+ } catch (java.net.MalformedURLException me) {
+ this.log.warn("Unable to add WEB-INF/classes to the classpath", me);
+ }
+
+ try {
+ libDirURL = this.servletContext.getResource("/WEB-INF/lib");
+ } catch (java.net.MalformedURLException me) {
+ this.log.warn("Unable to add WEB-INF/lib to the classpath", me);
+ }
+
+ if (libDirURL != null &&
libDirURL.toExternalForm().startsWith("file:")) {
+ root = new File(libDirURL.toExternalForm().substring(5));
+ }
- if(classDirURL != null) {
- buildClassPath.append(classDirURL.toExternalForm());
+ if(classDirURL != null) {
+ buildClassPath.append(classDirURL.toExternalForm());
- if (this.addClassDirs) {
- try {
- classLoader.addURL(classDirURL);
- } catch (Exception e) {
- log.debug("Could not add directory " + classDirURL, e);
+ if (this.addClassDirs) {
+ try {
+ classLoader.addURL(classDirURL);
+ } catch (Exception e) {
+ log.debug("Could not add directory " + classDirURL, e);
+ }
}
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]