You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/03/24 00:34:37 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/servlets InvokerServlet.java
costin 00/03/23 15:34:37
Modified: src/share/org/apache/tomcat/context DefaultCMSetter.java
src/share/org/apache/tomcat/core ServletWrapper.java
src/share/org/apache/tomcat/loader AdaptiveClassLoader.java
src/share/org/apache/tomcat/servlets InvokerServlet.java
Log:
Hard one - thanks Stefano for clue about loading resources from zip files.
Fixed 83, 59 and the error reported by Stefano, now loading from lib/*.jar
should work for classes and resources.
Thanks:
msanchez@liaison.com
katkere@praja.com
fergus.gallagher@orbisuk.com
Stefano
Revision Changes Path
1.26 +2 -1 jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java
Index: DefaultCMSetter.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- DefaultCMSetter.java 2000/03/16 20:43:22 1.25
+++ DefaultCMSetter.java 2000/03/23 23:34:35 1.26
@@ -173,7 +173,8 @@
for(int i=0; i < jars.size(); ++i) {
String jarfile = (String) jars.elementAt(i);
- loader.addRepository( new File(f, jarfile ));
+ File jarF=new File(f, jarfile );
+ loader.addRepository( getAbsolute( jarF, context) );
}
}
1.33 +27 -11 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
Index: ServletWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- ServletWrapper.java 2000/02/22 22:53:23 1.32
+++ ServletWrapper.java 2000/03/23 23:34:36 1.33
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.32 2000/02/22 22:53:23 costin Exp $
- * $Revision: 1.32 $
- * $Date: 2000/02/22 22:53:23 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.33 2000/03/23 23:34:36 costin Exp $
+ * $Revision: 1.33 $
+ * $Date: 2000/03/23 23:34:36 $
*
* ====================================================================
*
@@ -97,6 +97,8 @@
protected String description = null;
boolean initialized=false;
+ boolean available=true;
+
// Usefull info for class reloading
protected boolean isReloadable = false;
// information + make sure destroy is called when no other servlet
@@ -268,9 +270,17 @@
}
servlet = (Servlet)servletClass.newInstance();
+ // System.out.println("Loading " + servletClassName + " " + servlet );
config.setServletClassName(servlet.getClass().getName());
- initServlet();
+ try {
+ initServlet();
+ } catch( UnavailableException ex ) {
+ available=false;
+ } catch( ServletException ex ) {
+ available=false;
+ }
+ // System.out.println("Init ok " + available);
}
@@ -278,7 +288,7 @@
throws ClassNotFoundException, InstantiationException,
IllegalAccessException, ServletException
{
- try {
+ // try {
final Servlet sinstance = servlet;
final ServletConfigImpl servletConfig = config;
@@ -303,10 +313,10 @@
}
initialized=true;
- } catch(Exception ioe) {
- ioe.printStackTrace();
+ // } catch(IOException ioe) {
+ // ioe.printStackTrace();
// Should never come here...
- }
+ // }
}
// Reloading
@@ -357,18 +367,24 @@
}
handleReload();
-
+ // System.out.println(" SW " + initialized );
if( ! initialized ) {
try {
loadServlet();
} catch(Exception ex ) {
// return not found
res.setStatus( 404 );
- contextM.handleError( req, res, null, 404 );
+ contextM.handleError( req, res, ex, 404 );
return;
}
}
-
+
+ // If servlet was not initialized
+ if( ! available ) {
+ // XXX ADD code to handle this case XXX BUG 67
+ // res.setStatus(404);
+ // contextM.handleError( req, res, ex, 404 );
+ }
// XXX to expensive per/request, un-load is not so frequent and
// the API doesn't require a special state for destroy
// synchronized(this) {
1.4 +24 -14 jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveClassLoader.java
Index: AdaptiveClassLoader.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveClassLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AdaptiveClassLoader.java 2000/02/09 20:36:11 1.3
+++ AdaptiveClassLoader.java 2000/03/23 23:34:36 1.4
@@ -116,7 +116,7 @@
* @author Martin Pool
* @author Jim Heintz
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.3 $ $Date: 2000/02/09 20:36:11 $
+ * @version $Revision: 1.4 $ $Date: 2000/03/23 23:34:36 $
* @see java.lang.ClassLoader
*/
public class AdaptiveClassLoader extends ClassLoader {
@@ -413,7 +413,7 @@
// Cache entry.
ClassCacheEntry classCache = new ClassCacheEntry();
while (repEnum.hasMoreElements()) {
- byte[] classData;
+ byte[] classData=null;
File file = (File) repEnum.nextElement();
try {
@@ -421,14 +421,16 @@
classData =
loadClassFromDirectory(file, name, classCache);
} else {
- classData =
+ classData =
loadClassFromZipfile(file, name, classCache);
- }
+ }
} catch(IOException ioe) {
// Error while reading in data, consider it as not found
classData = null;
- }
-
+ } catch( Exception ex ) {
+ ex.printStackTrace();
+ }
+
if (classData != null) {
// Define the class
c = defineClass(name, classData, 0, classData.length);
@@ -439,8 +441,7 @@
cache.put(name, classCache);
// Resolve it if necessary
- if (resolve) resolveClass(c);
-
+ if (resolve) resolveClass(c);
return c;
}
}
@@ -563,6 +564,7 @@
try {
ZipEntry entry = zipfile.getEntry(classFileName);
+ // System.out.println("XXX Found " + classFileName + " " + entry + " " + entry.getSize() );
if (entry != null) {
cache.origin = file;
return loadBytesFromStream(zipfile.getInputStream(entry),
@@ -624,7 +626,7 @@
} else {
s = loadResourceFromZipfile(file, name);
}
-
+ // System.out.println("LOADING " + file + " " + name + " " + s );
if (s != null) {
break;
}
@@ -663,20 +665,28 @@
ZipEntry entry = zipfile.getEntry(name);
if (entry != null) {
- return zipfile.getInputStream(entry);
- } else {
- return null;
+ // workaround - the better solution is to not close the
+ // zipfile !!!!
+ byte[] data= loadBytesFromStream(zipfile.getInputStream(entry),
+ (int) entry.getSize());
+ if(data != null) {
+ InputStream istream = new ByteArrayInputStream(data);
+ return istream;
+ }
}
} catch(IOException e) {
- return null;
} finally {
- if ( zipfile != null ) {
+ // if we close the zipfile bad things will happen - we can't read the stream
+ // on some VMs
+ if ( zipfile != null ) {
try {
zipfile.close();
} catch ( IOException ignored ) {
}
}
}
+ // default case
+ return null;
}
/**
1.7 +6 -5 jakarta-tomcat/src/share/org/apache/tomcat/servlets/InvokerServlet.java
Index: InvokerServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/servlets/InvokerServlet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- InvokerServlet.java 2000/02/14 04:59:40 1.6
+++ InvokerServlet.java 2000/03/23 23:34:36 1.7
@@ -195,8 +195,8 @@
// support
}
- // System.out.println("CL: " + context.getServletLoader().getClassLoader() +
- // " wrapper: " + wrapper);
+ // System.out.println("CL: " + context.getServletLoader().getClassLoader() +
+ // " wrapper: " + wrapper);
// Can't be null - loadServlet creates a new wrapper .
@@ -255,7 +255,7 @@
}
wrapper.handleRequest(requestfacade, responsefacade);
-
+
if (!inInclude) {
realRequest.setServletPath( savedServletPath);
realRequest.setPathInfo(savedPathInfo);
@@ -279,7 +279,8 @@
}
public void doError(HttpServletResponse response, String msg)
- throws ServletException, IOException {
- response.sendError(404, msg);
+ throws ServletException, IOException
+ {
+ response.sendError(404, msg);
}
}