cziegeler 01/07/12 06:33:53 Modified: . Tag: cocoon_20_branch changes.xml todo.xml src/org/apache/cocoon/servlet Tag: cocoon_20_branch CocoonServlet.java ParanoidCocoonServlet.java Log: Added reloading of jar files when the cocoon-reload parameters is specified. Updated changes and todo Revision Changes Path No revision No revision 1.2.2.18 +15 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.2.2.17 retrieving revision 1.2.2.18 diff -u -r1.2.2.17 -r1.2.2.18 --- changes.xml 2001/07/10 08:16:43 1.2.2.17 +++ changes.xml 2001/07/12 13:33:41 1.2.2.18 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: changes.xml,v 1.2.2.17 2001/07/10 08:16:43 cziegeler Exp $ + $Id: changes.xml,v 1.2.2.18 2001/07/12 13:33:41 cziegeler Exp $ --> <changes title="History of Changes"> @@ -25,6 +25,20 @@ </devs> <release version="2.0b1-dev" date="@date@"> + <action dev="CZ" type="add"> + Added reloading of jar files. When cocoon is reloaded by specifying + cocoon-reload parameter, the class-path is new build and used. + </action> + <action dev="CZ" type="add"> + Added caching of cocoon: urls. + </action> + <action dev="CZ" type="add"> + Redirects are handled when the cocoon: url points to a redirect in + the sitemaps. + </action> + <action dev="CZ" type="fix"> + Fixed proper setting of content length for pdf and images. + </action> <action dev="VG" type="fix"> Fixed parsing and reporting of Java compilation errors using Javac and Jikes compilers. 1.1.1.1.2.5 +1 -18 xml-cocoon2/todo.xml Index: todo.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/todo.xml,v retrieving revision 1.1.1.1.2.4 retrieving revision 1.1.1.1.2.5 diff -u -r1.1.1.1.2.4 -r1.1.1.1.2.5 --- todo.xml 2001/07/10 08:16:46 1.1.1.1.2.4 +++ todo.xml 2001/07/12 13:33:42 1.1.1.1.2.5 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: todo.xml,v 1.1.1.1.2.4 2001/07/10 08:16:46 cziegeler Exp $ + $Id: todo.xml,v 1.1.1.1.2.5 2001/07/12 13:33:42 cziegeler Exp $ --> @@ -28,15 +28,6 @@ <actions priority="high"> <action context="code" assigned-to="open"> - Reloading of jar-files. - The class-path for the Cocoon-Servlet is only build once when the servlet - is initialised. If you want to deploy other jar files you have to restart - the servlet. A reloading of the Cocoon is not sufficient. This is not - very convenient. Suggestion: When Cocoon is reloaded (a new cocoon instance - is created then) the classpath is rebuild and used. - </action> - - <action context="code" assigned-to="open"> Complete (means put everything we know of into even if it has to be commented) the cocoon.xconf file and put descriptions into it </action> @@ -50,14 +41,6 @@ </actions> <actions priority="medium"> - - <action context="code" assigned-to="open"> - Caching of cocoon: urls. - </action> - - <action context="code" assigned-to="open"> - Handling of redirects when the cocoon: url is used. - </action> <action context="code" assigned-to="GF"> Extend the Store to keep the most fequently used objects in the No revision No revision 1.13.2.4 +48 -36 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.13.2.3 retrieving revision 1.13.2.4 diff -u -r1.13.2.3 -r1.13.2.4 --- CocoonServlet.java 2001/07/12 12:23:52 1.13.2.3 +++ CocoonServlet.java 2001/07/12 13:33:48 1.13.2.4 @@ -58,7 +58,8 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> - * @version CVS $Revision: 1.13.2.3 $ $Date: 2001/07/12 12:23:52 $ + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @version CVS $Revision: 1.13.2.4 $ $Date: 2001/07/12 13:33:48 $ */ public class CocoonServlet extends HttpServlet { @@ -69,10 +70,16 @@ static final float minute = 60 * second; static final float hour = 60 * minute; + /** The time the cocoon instance was created */ protected long creationTime = 0; + + /** The <code>Cocoon</code> instance */ protected Cocoon cocoon; + protected Exception exception; + protected DefaultContext appContext = new DefaultContext(); + /** Allow reloading of cocoon by specifying the cocoon-reload parameter with a request */ protected boolean allowReload; @@ -86,6 +93,8 @@ protected ServletContext servletContext; protected RepositoryClassLoader classLoader; + protected String forceLoadParameter; + /** * Initialize this <code>CocoonServlet</code> instance. You will * notice that I have broken the init into sub methods to make it @@ -103,22 +112,12 @@ super.init(conf); - classLoader = buildInitClassLoader(); - - /* HACK for reducing class loader problems. */ - /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */ - try { - Thread.currentThread().setContextClassLoader(classLoader); - } catch (Exception e){} - this.servletContext = conf.getServletContext(); - - this.appContext.put(Constants.CONTEXT_CLASS_LOADER, classLoader); - this.appContext.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, new HttpContext(this.servletContext)); - this.initLogger(this.servletContext); + + this.initLogger(); - this.forceLoad(conf.getInitParameter("load-class")); + this.forceLoadParameter = conf.getInitParameter("load-class"); String workDirParam = conf.getInitParameter("work-directory"); if ((workDirParam != null) && (workDirParam.trim().equals("") == false)) { @@ -129,7 +128,6 @@ } this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir); - this.appContext.put(Constants.CONTEXT_CLASSPATH, this.getClassPath(this.servletContext)); String uploadDirParam = conf.getInitParameter("upload-directory"); if ((uploadDirParam != null) && (uploadDirParam.trim().equals("") == false)) { @@ -142,7 +140,7 @@ this.uploadDir.mkdirs(); this.appContext.put(Constants.CONTEXT_CONFIG_URL, - this.getConfigFile(conf.getInitParameter("configurations"), this.servletContext)); + this.getConfigFile(conf.getInitParameter("configurations"))); // get allow reload parameter, default is true String value = conf.getInitParameter("allow-reload"); @@ -187,12 +185,12 @@ * * @throws ServletException */ - protected String getClassPath(final ServletContext context) + protected String getClassPath() throws ServletException { StringBuffer buildClassPath = new StringBuffer(); - String classDir = context.getRealPath("/WEB-INF/classes"); - String libDir = context.getRealPath("/WEB-INF/lib"); + String classDir = this.servletContext.getRealPath("/WEB-INF/classes"); + String libDir = this.servletContext.getRealPath("/WEB-INF/lib"); File root = null; if(libDir != null) @@ -228,8 +226,7 @@ .append(System.getProperty("java.class.path")); buildClassPath.append(File.pathSeparatorChar) - .append(getExtraClassPath(context)); - + .append(getExtraClassPath()); return buildClassPath.toString(); } @@ -242,9 +239,9 @@ * * @throws ServletException */ - protected String getExtraClassPath(final ServletContext context) + protected String getExtraClassPath() throws ServletException { - String extraClassPath = getInitParameter("extra-classpath"); + String extraClassPath = this.getInitParameter("extra-classpath"); if ((extraClassPath != null) && (extraClassPath.trim().equals("") == false)) { StringBuffer sb = new StringBuffer(); StringTokenizer st = new StringTokenizer(extraClassPath, System.getProperty("path.separator"), false); @@ -258,8 +255,8 @@ log.debug ("extraClassPath is absolute: " + extraClassPath); sb.append(s); } else { - log.debug ("extraClassPath is not absolute: " + context.getRealPath("/") + extraClassPath); - sb.append(context.getRealPath("/") + extraClassPath); + log.debug ("extraClassPath is not absolute: " + this.servletContext.getRealPath("/") + extraClassPath); + sb.append(this.servletContext.getRealPath("/") + extraClassPath); } } return sb.toString(); @@ -281,7 +278,7 @@ * * @throws ServletException */ - private void initLogger(final ServletContext context) + private void initLogger() throws ServletException { final Priority logPriority; String logDir = getInitParameter("log-dir"); @@ -291,8 +288,8 @@ } if (logDir == null) { - if(context.getRealPath("/") != null) { - logDir = context.getRealPath("/"); + if(this.servletContext.getRealPath("/") != null) { + logDir = this.servletContext.getRealPath("/"); if (logDir.endsWith(File.separator) == false) logDir += File.separator; logDir = logDir + "WEB-INF"+File.separator+"logs"+File.separator; } else @@ -324,7 +321,7 @@ this.log.setPriority(logPriority); FileOutputLogTarget fileTarget = new FileOutputLogTarget(path); - ServletOutputLogTarget servTarget = new ServletOutputLogTarget(context); + ServletOutputLogTarget servTarget = new ServletOutputLogTarget(this.servletContext); fileTarget.setFormatter(formatter); servTarget.setFormatter(formatter); @@ -346,7 +343,7 @@ * * @throws ServletException */ - private URL getConfigFile(final String configFileName, final ServletContext context) + private URL getConfigFile(final String configFileName) throws ServletException { final String usedFileName; @@ -360,7 +357,7 @@ log.debug("Using configuration file: " + usedFileName); try { - return context.getResource(usedFileName); + return this.servletContext.getResource(usedFileName); } catch (Exception mue) { log.error("Servlet initialization argument 'configurations' not found at " + usedFileName, mue); throw new ServletException("Servlet initialization argument 'configurations' not found at " + usedFileName); @@ -407,9 +404,9 @@ * * @throws ServletException */ - private void forceLoad(final String forceLoading) { - if (forceLoading != null) { - StringTokenizer fqcnTokenizer = new StringTokenizer(forceLoading, " \t\r\n\f;,", false); + private void forceLoad() { + if (this.forceLoadParameter != null) { + StringTokenizer fqcnTokenizer = new StringTokenizer(forceLoadParameter, " \t\r\n\f;,", false); while (fqcnTokenizer.hasMoreTokens()) { final String fqcn = fqcnTokenizer.nextToken().trim(); @@ -593,8 +590,22 @@ /** * Creates the Cocoon object and handles exception handling. */ - private synchronized void createCocoon() { + private synchronized void createCocoon() + throws ServletException { + this.classLoader = this.buildInitClassLoader(); + + /* HACK for reducing class loader problems. */ + /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */ try { + Thread.currentThread().setContextClassLoader(this.classLoader); + } catch (Exception e){} + + this.appContext.put(Constants.CONTEXT_CLASS_LOADER, classLoader); + this.appContext.put(Constants.CONTEXT_CLASSPATH, this.getClassPath()); + + this.forceLoad(); + + try { URL configFile = (URL) this.appContext.get(Constants.CONTEXT_CONFIG_URL); log.info("Reloading from: " + configFile.toExternalForm()); Cocoon c = (Cocoon) ClassUtils.newInstance("org.apache.cocoon.Cocoon"); @@ -650,7 +661,8 @@ * * @returns Cocoon */ - private Cocoon getCocoon(final String pathInfo, final String reloadParam) { + private Cocoon getCocoon(final String pathInfo, final String reloadParam) + throws ServletException { if (this.cocoon != null && this.allowReload == true) { if (this.cocoon.modifiedSince(this.creationTime)) { log.info("Configuration changed reload attempt"); 1.2.2.1 +5 -5 xml-cocoon2/src/org/apache/cocoon/servlet/ParanoidCocoonServlet.java Index: ParanoidCocoonServlet.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/servlet/ParanoidCocoonServlet.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- ParanoidCocoonServlet.java 2001/05/22 19:23:07 1.2 +++ ParanoidCocoonServlet.java 2001/07/12 13:33:50 1.2.2.1 @@ -28,7 +28,7 @@ * of it. * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> - * @version CVS $Revision: 1.2 $ $Date: 2001/05/22 19:23:07 $ + * @version CVS $Revision: 1.2.2.1 $ $Date: 2001/07/12 13:33:50 $ */ public class ParanoidCocoonServlet extends CocoonServlet { @@ -49,7 +49,7 @@ * * @throws ServletException */ - protected String getClassPath(final ServletContext context) + protected String getClassPath() throws ServletException { StringBuffer buildClassPath = new StringBuffer(); @@ -61,13 +61,13 @@ if ((classDirPath != null) && (classDirPath.trim().equals("") == false)) { classDir = classDirPath; } else { - classDir = context.getRealPath("/WEB-INF/classes"); + classDir = this.servletContext.getRealPath("/WEB-INF/classes"); } if ((libDirPath != null) && (libDirPath.trim().equals("") == false)) { root = new File(libDirPath); } else { - root = new File(context.getRealPath("/WEB-INF/lib")); + root = new File(this.servletContext.getRealPath("/WEB-INF/lib")); } try { @@ -97,7 +97,7 @@ .append(System.getProperty("java.class.path")); buildClassPath.append(File.pathSeparatorChar) - .append(getExtraClassPath(context)); + .append(getExtraClassPath()); return buildClassPath.toString(); } ---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]