larryi 02/01/30 19:34:10 Modified: src/facade22/org/apache/tomcat/facade JspInterceptor.java Log: Make behavior added in the last patch configurable using an added "useWebAppCL" attribute. If set true, the new behavior of running the Java compilation out of the web application's classloader is enabled. If false, Java compilation runs in the "container" classloader. Running in the webapp's classloader has the effect of reducing the permissions for "sun.tools.javac.Main" when running with a security manager. Currently, this will cause JSPs to be unable to compile. Because of this, the default for useWebAppCL is false. Revision Changes Path 1.37 +58 -46 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java Index: JspInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- JspInterceptor.java 23 Jan 2002 23:58:38 -0000 1.36 +++ JspInterceptor.java 31 Jan 2002 03:34:10 -0000 1.37 @@ -103,6 +103,7 @@ Properties args=new Properties(); // args for jasper boolean useJspServlet=false; + boolean useWebAppCL=false; String jspServletCN=JSP_SERVLET; String runtimePackage; @@ -243,6 +244,14 @@ public void setRuntimePackage(String rp ) { runtimePackage=rp; } + + /** Compile using the web application classloader. This + was added as part of dealing a problem with + tools.jar on some HP-UX systems. + */ + public void setUseWebAppCL(boolean b) { + useWebAppCL=b; + } // -------------------- Hooks -------------------- @@ -279,7 +288,8 @@ } } - if( !ctx.isTrusted() ) { + if( (useJspServlet && !ctx.isTrusted()) + || useWebAppCL ) { try { File f=new File( cm.getInstallDir(), "lib/container/jasper.jar" ); @@ -287,33 +297,28 @@ f.getAbsolutePath().replace('\\','/') ); ctx.addClassPath( url ); if( debug > 9 ) log( "Added to classpath: " + url ); - } catch( MalformedURLException ex ) { - ex.printStackTrace(); - } - } - // Add tools.jar in any case - try { - File f=new File( System.getProperty( "java.home" ) + - "/../lib/tools.jar"); - if( ! f.exists() ) { - // On some systems java.home gets set to the root of jdk. - // That's a bug, but we can work around and be nice. f=new File( System.getProperty( "java.home" ) + - "/lib/tools.jar"); + "/../lib/tools.jar"); if( ! f.exists() ) { - log("Tools.jar not found " + - System.getProperty( "java.home" )); - } else { - log("Detected wrong java.home value " + - System.getProperty( "java.home" )); + // On some systems java.home gets set to the root of jdk. + // That's a bug, but we can work around and be nice. + f=new File( System.getProperty( "java.home" ) + + "/lib/tools.jar"); + if( ! f.exists() ) { + log("Tools.jar not found " + + System.getProperty( "java.home" )); + } else { + log("Detected wrong java.home value " + + System.getProperty( "java.home" )); + } } + url=new URL( "file", "" , f.getAbsolutePath() ); + ctx.addClassPath( url ); + if( debug > 9 ) log( "Added to classpath: " + url ); + } catch( MalformedURLException ex ) { + ex.printStackTrace(); } - URL url=new URL( "file", "" , f.getAbsolutePath() ); - ctx.addClassPath( url ); - if( debug > 9 ) log( "Added to classpath: " + url ); - } catch( MalformedURLException ex ) { - ex.printStackTrace(); } } @@ -361,12 +366,14 @@ ctx.addServlet( new JspPrecompileH()); } - //Extra test/warnings for tools.jar - try { - ctx.getClassLoader().loadClass( "sun.tools.javac.Main" ); - if( debug>0) log( "Found javac in context init"); - } catch( ClassNotFoundException ex ) { - if( debug>0) log( "javac not found in context init"); + if( useWebAppCL ) { + //Extra test/warnings for tools.jar + try { + ctx.getClassLoader().loadClass( "sun.tools.javac.Main" ); + if( debug>0) log( "Found javac in context init"); + } catch( ClassNotFoundException ex ) { + if( debug>0) log( "javac not found in context init"); + } } } @@ -494,7 +501,8 @@ Dependency dep= handler.getServletInfo().getDependency(); if( (dep==null || dep.isExpired()) && do_compile ) { // we need to compile... ( or find previous .class ) - JasperLiaison liasion=new JasperLiaison(getLog(), debug); + JasperLiaison liasion=new JasperLiaison(getLog(), debug, + useWebAppCL); liasion.processJspFile(req, jspFile, handler, args); } @@ -596,10 +604,12 @@ final class JasperLiaison { Log log; final int debug; + boolean useWebAppCL; - JasperLiaison( Log log, int debug ) { + JasperLiaison( Log log, int debug, boolean useWebAppCL ) { this.log=log; this.debug=debug; + this.useWebAppCL=useWebAppCL; } /** Generate mangled names, check for previous versions, @@ -693,21 +703,23 @@ ClassLoader savedContextCL= containerCCL( ctx.getContextManager() .getContainerLoader() ); - try { - ctx.getClassLoader().loadClass( "sun.tools.javac.Main" ); - if(debug>0) log.log( "Found javac using context loader"); - } catch( ClassNotFoundException ex ) { - if(debug>0) log.log( "javac not found using context loader"); - } + if( useWebAppCL ) { + try { + ctx.getClassLoader().loadClass( "sun.tools.javac.Main" ); + if(debug>0) log.log( "Found javac using context loader"); + } catch( ClassNotFoundException ex ) { + if(debug>0) log.log( "javac not found using context loader"); + } - try { - ctx.getContextManager().getContainerLoader(). - loadClass( "sun.tools.javac.Main" ); - if( debug > 0 ) - log.log( "Found javac using container loader"); - } catch( ClassNotFoundException ex ) { - if( debug > 0 ) - log.log( "javac not found using container loader"); + try { + ctx.getContextManager().getContainerLoader(). + loadClass( "sun.tools.javac.Main" ); + if( debug > 0 ) + log.log( "Found javac using container loader"); + } catch( ClassNotFoundException ex ) { + if( debug > 0 ) + log.log( "javac not found using container loader"); + } } try { @@ -817,7 +829,7 @@ javac.setClasspath( cp ); javac.setOutputDir(ctxt.getOutputDir()); - if( javac instanceof SunJavaCompiler ) { + if( javac instanceof SunJavaCompiler && useWebAppCL ) { ClassLoader cl=req.getContext().getClassLoader(); ((SunJavaCompiler)javac).setLoader( cl ); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>