billbarker 2004/12/04 22:29:15 Modified: jk/java/org/apache/jk/config ApacheConfig.java BaseJkConfig.java IISConfig.java NSConfig.java Log: Allow ApacheConfig and friends to live under an Engine. Using an Engine gives the all-in config generation like with TC 3.3 (except for the generate every time at startup :), so it shouldn't be mixed with Host/Context instances. Also convert to c-l, and a couple of formatting changes. Revision Changes Path 1.5 +17 -14 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/ApacheConfig.java Index: ApacheConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/config/ApacheConfig.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ApacheConfig.java 29 Aug 2004 17:14:41 -0000 1.4 +++ ApacheConfig.java 5 Dec 2004 06:29:15 -0000 1.5 @@ -115,7 +115,10 @@ @author Bill Barker */ public class ApacheConfig extends BaseJkConfig { - + + private static org.apache.commons.logging.Log log = + org.apache.commons.logging.LogFactory.getLog(ApacheConfig.class); + /** default path to mod_jk .conf location */ public static final String MOD_JK_CONFIG = "conf/auto/mod_jk.conf"; /** default path to workers.properties file @@ -254,10 +257,10 @@ // Fail if mod_jk not found, let the user know the problem // instead of running into problems later. if( ! modJk.exists() ) { - log( "mod_jk location: " + modJk ); - log( "Make sure it is installed corectly or " + + log.info( "mod_jk location: " + modJk ); + log.info( "Make sure it is installed corectly or " + " set the config location" ); - log( "Using <Listener className=\""+getClass().getName()+"\" modJk=\"PATH_TO_MOD_JK.SO_OR_DLL\" />" ); + log.info( "Using <Listener className=\""+getClass().getName()+"\" modJk=\"PATH_TO_MOD_JK.SO_OR_DLL\" />" ); } // Verify the file exists !! @@ -272,10 +275,10 @@ // Fail if workers file not found, let the user know the problem // instead of running into problems later. if( ! workersConfig.exists() ) { - log( "Can't find workers.properties at " + workersConfig ); - log( "Please install it in the default location or " + + log.warn( "Can't find workers.properties at " + workersConfig ); + log.warn( "Please install it in the default location or " + " set the config location" ); - log( "Using <Listener className=\"" + getClass().getName() + "\" workersConfig=\"FULL_PATH\" />" ); + log.warn( "Using <Listener className=\"" + getClass().getName() + "\" workersConfig=\"FULL_PATH\" />" ); return false; } @@ -393,7 +396,7 @@ Host vhost = getHost(context); if( noRoot && "".equals(ctxPath) ) { - log("Ignoring root context in non-forward-all mode "); + log.debug("Ignoring root context in non-forward-all mode "); return; } @@ -431,8 +434,8 @@ protected boolean addExtensionMapping( String ctxPath, String ext, PrintWriter mod_jk ) { - if( debug > 0 ) - log( "Adding extension map for " + ctxPath + "/*." + ext ); + if( log.isDebugEnabled() ) + log.debug( "Adding extension map for " + ctxPath + "/*." + ext ); mod_jk.println(indent + "JkMount " + ctxPath + "/*." + ext + " " + jkWorker); return true; @@ -442,16 +445,16 @@ /** Add a fulling specified Appache mapping. */ protected boolean addMapping( String fullPath, PrintWriter mod_jk ) { - if( debug > 0 ) - log( "Adding map for " + fullPath ); + if( log.isDebugEnabled() ) + log.debug( "Adding map for " + fullPath ); mod_jk.println(indent + "JkMount " + fullPath + " " + jkWorker ); return true; } /** Add a partially specified Appache mapping. */ protected boolean addMapping( String ctxP, String ext, PrintWriter mod_jk ) { - if( debug > 0 ) - log( "Adding map for " + ext ); + if( log.isDebugEnabled() ) + log.debug( "Adding map for " + ext ); if(! ext.startsWith("/") ) ext = "/" + ext; if(ext.length() > 1) 1.4 +206 -181 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/BaseJkConfig.java Index: BaseJkConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/config/BaseJkConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- BaseJkConfig.java 29 Aug 2004 17:14:41 -0000 1.3 +++ BaseJkConfig.java 5 Dec 2004 06:29:15 -0000 1.4 @@ -88,10 +88,12 @@ @author Costin Manolache @author Larry Isaacs @author Bill Barker - @version $Revision$ + @version $Revision$ */ public class BaseJkConfig implements LifecycleListener { - protected int debug=0; + private static org.apache.commons.logging.Log log = + org.apache.commons.logging.LogFactory.getLog(BaseJkConfig.class); + protected File configHome = null; protected File workersConfig = null; @@ -105,7 +107,7 @@ protected String tomcatHome; protected boolean regenerate=false; protected boolean append=false; - protected boolean legacy=false; + protected boolean legacy=true; // -------------------- Tomcat callbacks -------------------- @@ -113,147 +115,170 @@ // Auto-config should be able to react to dynamic config changes, // and regenerate the config. - /** Generate the configuration - only when the server is + /** + * Generate the configuration - only when the server is * completely initialized ( before starting ) */ - public void lifecycleEvent(LifecycleEvent evt) - { - if(Lifecycle.START_EVENT.equals(evt.getType())) { - execute( evt ); - } - } - - /** Generate configuration files. Override with method to generate - web server specific configuration. - */ - public void execute(LifecycleEvent evt) - { - initProperties(); - PrintWriter mod_jk = null; - try { - mod_jk = getWriter(); - } catch(IOException iex) { - log("Unable to open config file"); - return; - } - Lifecycle who = evt.getLifecycle(); - if( who instanceof Server ) { - executeServer((Server)who, mod_jk); - } else if ( who instanceof Host ) { - executeHost((Host)who, mod_jk); - } else if( who instanceof Context ) { - executeContext((Context)who, mod_jk); - } - mod_jk.close(); + public void lifecycleEvent(LifecycleEvent evt) { + if(Lifecycle.START_EVENT.equals(evt.getType())) { + execute( evt ); + } + } + + /** + * Generate configuration files. Override with method to generate + * web server specific configuration. + */ + public void execute(LifecycleEvent evt) { + initProperties(); + PrintWriter mod_jk = null; + try { + mod_jk = getWriter(); + } catch(IOException iex) { + log.warn("Unable to open config file"); + return; + } + Lifecycle who = evt.getLifecycle(); + if( who instanceof Server ) { + executeServer((Server)who, mod_jk); + } else if(who instanceof Engine) { + executeEngine((Engine)who, mod_jk); + } else if ( who instanceof Host ) { + executeHost((Host)who, mod_jk); + } else if( who instanceof Context ) { + executeContext((Context)who, mod_jk); + } + mod_jk.close(); } - /** Generate configuration files. Override with method to generate - web server specific configuration. + /** + * Generate configuration files. Override with method to generate + * web server specific configuration. */ public void executeServer(Server svr, PrintWriter mod_jk) { - if(! append ) { - if( ! generateJkHead(mod_jk) ) - return; - generateSSLConfig(mod_jk); - generateJkTail(mod_jk); - } + if(! append ) { + if( ! generateJkHead(mod_jk) ) + return; + generateSSLConfig(mod_jk); + generateJkTail(mod_jk); + } } - /** Generate SSL options + /** + * Generate SSL options */ - protected void generateSSLConfig(PrintWriter mod_jk) - { + protected void generateSSLConfig(PrintWriter mod_jk) { } - /** Generate general options + + /** + * Generate general options */ - protected boolean generateJkHead(PrintWriter mod_jk) - { - return true; + protected boolean generateJkHead(PrintWriter mod_jk) { + return true; } - /** Generate general options + + /** + * Generate general options */ - protected void generateJkTail(PrintWriter mod_jk) - { + protected void generateJkTail(PrintWriter mod_jk) { } - /** Generate Virtual Host start + + /** + * Generate Virtual Host start */ protected void generateVhostHead(Host host, PrintWriter mod_jk) { } - /** Generate Virtual Host end + + /** + * Generate Virtual Host end */ protected void generateVhostTail(Host host, PrintWriter mod_jk) { } - /** Generate configuration files. Override with method to generate - web server specific configuration. + + /** + * Generate configuration files. Override with method to generate + * web server specific configuration. */ protected void executeEngine(Engine egn, PrintWriter mod_jk) { - Container [] children = egn.findChildren(); - for(int ii=0; ii < children.length; ii++) { - if( children[ii] instanceof Host ) { - executeHost((Host)children[ii], mod_jk); - } else if( children[ii] instanceof Context ) { - executeContext((Context)children[ii], mod_jk); - } - } + if(egn.getJvmRoute() != null) { + jkWorker = egn.getJvmRoute(); + } + executeServer(egn.getService().getServer(), mod_jk); + Container [] children = egn.findChildren(); + for(int ii=0; ii < children.length; ii++) { + if( children[ii] instanceof Host ) { + executeHost((Host)children[ii], mod_jk); + } else if( children[ii] instanceof Context ) { + executeContext((Context)children[ii], mod_jk); + } + } } - /** Generate configuration files. Override with method to generate - web server specific configuration. + /** + * Generate configuration files. Override with method to generate + * web server specific configuration. */ protected void executeHost(Host hst, PrintWriter mod_jk) { - generateVhostHead(hst, mod_jk); - Container [] children = hst.findChildren(); - for(int ii=0; ii < children.length; ii++) { - if(children[ii] instanceof Context) { - executeContext((Context)children[ii],mod_jk); - } - } - generateVhostTail(hst, mod_jk); + generateVhostHead(hst, mod_jk); + Container [] children = hst.findChildren(); + for(int ii=0; ii < children.length; ii++) { + if(children[ii] instanceof Context) { + executeContext((Context)children[ii],mod_jk); + } + } + generateVhostTail(hst, mod_jk); } /** - executes the ApacheConfig interceptor. This method generates apache - configuration files for use with mod_jk. - <p> - @param context a Context object. - @param mod_jk Writer for output. + * executes the ApacheConfig interceptor. This method generates apache + * configuration files for use with mod_jk. + * @param context a Context object. + * @param mod_jk Writer for output. */ public void executeContext(Context context, PrintWriter mod_jk){ - if(context.getPath().length() > 0 || ! noRoot ) { - String docRoot = context.getServletContext().getRealPath("/"); - if( forwardAll || docRoot == null) - generateStupidMappings( context, mod_jk ); - else - generateContextMappings( context, mod_jk); - } + if(context.getPath().length() > 0 || ! noRoot ) { + String docRoot = context.getServletContext().getRealPath("/"); + if( forwardAll || docRoot == null) + generateStupidMappings( context, mod_jk ); + else + generateContextMappings( context, mod_jk); + } } + protected void generateStupidMappings(Context context, PrintWriter mod_jk){ } protected void generateContextMappings(Context context, PrintWriter mod_jk){ } - /** Get the output Writer. Override with method to generate - web server specific configuration. + + /** + * Get the output Writer. Override with method to generate + * web server specific configuration. */ protected PrintWriter getWriter() throws IOException { - return null; + return null; } - /** Get the host associated with this Container (if any). + + /** + * Get the host associated with this Container (if any). */ protected Host getHost(Container child) { - while(child != null && ! (child instanceof Host) ) { - child = child.getParent(); - } - return (Host)child; + while(child != null && ! (child instanceof Host) ) { + child = child.getParent(); + } + return (Host)child; } //-------------------- Properties -------------------- - /** Append to config file. + /** + * Append to config file. * Set to <code>true</code> if the config information should be * appended. */ public void setAppend(boolean apnd) { - append = apnd; + append = apnd; } - /** If false, we'll try to generate a config that will + + /** + * If false, we'll try to generate a config that will * let apache serve static files. * The default is true, forward all requests in a context * to tomcat. @@ -262,35 +287,35 @@ forwardAll=b; } - /** Special option - do not generate mappings for the ROOT - context. The default is true, and will not generate the mappings, - not redirecting all pages to tomcat (since /* matches everything). - This means that the web server's root remains intact but isn't - completely servlet/JSP enabled. If the ROOT webapp can be configured - with the web server serving static files, there's no problem setting - this option to false. If not, then setting it true means the web - server will be out of picture for all requests. - */ + /** + * Special option - do not generate mappings for the ROOT + * context. The default is true, and will not generate the mappings, + * not redirecting all pages to tomcat (since /* matches everything). + * This means that the web server's root remains intact but isn't + * completely servlet/JSP enabled. If the ROOT webapp can be configured + * with the web server serving static files, there's no problem setting + * this option to false. If not, then setting it true means the web + * server will be out of picture for all requests. + */ public void setNoRoot( boolean b ) { noRoot=b; } /** - set a path to the parent directory of the - conf folder. That is, the parent directory - within which path setters would be resolved against, - if relative. For example if ConfigHome is set to "/home/tomcat" - and regConfig is set to "conf/mod_jk.conf" then the resulting - path used would be: - "/home/tomcat/conf/mod_jk.conf".</p> - <p> - However, if the path is set to an absolute path, - this attribute is ignored. - <p> - If not set, execute() will set this to TOMCAT_HOME. - <p> - @param dir - path to a directory - */ + * set a path to the parent directory of the + * conf folder. That is, the parent directory + * within which path setters would be resolved against, + * if relative. For example if ConfigHome is set to "/home/tomcat" + * and regConfig is set to "conf/mod_jk.conf" then the resulting + * path used would be: + * "/home/tomcat/conf/mod_jk.conf".</p> + * <p> + * However, if the path is set to an absolute path, + * this attribute is ignored. + * <p> + * If not set, execute() will set this to TOMCAT_HOME. + * @param dir - path to a directory + */ public void setConfigHome(String dir){ if( dir==null ) return; File f=new File(dir); @@ -303,31 +328,32 @@ } /** - set a path to the workers.properties file. - @param path String path to workers.properties file - */ + * set a path to the workers.properties file. + * @param path String path to workers.properties file + */ public void setWorkersConfig(String path){ workersConfig= (path==null?null:new File(path)); } /** - set the path to the log file - @param path String path to a file - */ + * set the path to the log file + * @param path String path to a file + */ public void setJkLog(String path){ jkLog = ( path==null ? null : new File(path)); } - /** Set the verbosity level - ( use debug, error, etc. ) If not set, no log is written. + /** + * Set the verbosity level + * ( use debug, error, etc. ) If not set, no log is written. */ public void setJkDebug( String level ) { jkDebug=level; } /** - Sets the JK worker. - @param worker The worker + * Sets the JK worker. + * @param worker The worker */ public void setJkWorker(String worker){ jkWorker = worker; @@ -339,9 +365,10 @@ // -------------------- Initialize/guess defaults -------------------- - /** Initialize defaults for properties that are not set - explicitely - */ + /** + * Initialize defaults for properties that are not set + * explicitely + */ protected void initProperties() { tomcatHome = System.getProperty("catalina.home"); File tomcatDir = new File(tomcatHome); @@ -353,34 +380,34 @@ // -------------------- Config Utils -------------------- - /** Add an extension mapping. Override with method to generate - web server specific configuration + /** + * Add an extension mapping. Override with method to generate + * web server specific configuration */ protected boolean addExtensionMapping( String ctxPath, String ext, - PrintWriter pw ) - { - return true; + PrintWriter pw ) { + return true; } - /** Add a fulling specified mapping. Override with method to generate - web server specific configuration + /** + * Add a fulling specified mapping. Override with method to generate + * web server specific configuration */ protected boolean addMapping( String fullPath, PrintWriter pw ) { - return true; + return true; } // -------------------- General Utils -------------------- - protected String getAbsoluteDocBase(Context context) - { - // Calculate the absolute path of the document base - String docBase = context.getServletContext().getRealPath("/"); - docBase = docBase.substring(0,docBase.length()-1); - if (!isAbsolute(docBase)){ - docBase = tomcatHome + "/" + docBase; - } - docBase = patch(docBase); + protected String getAbsoluteDocBase(Context context) { + // Calculate the absolute path of the document base + String docBase = context.getServletContext().getRealPath("/"); + docBase = docBase.substring(0,docBase.length()-1); + if (!isAbsolute(docBase)){ + docBase = tomcatHome + "/" + docBase; + } + docBase = patch(docBase); return docBase; } @@ -405,6 +432,7 @@ } return base; } + public static String patch(String path) { String patchPath = path; @@ -417,7 +445,7 @@ } // Eliminate consecutive slashes after the drive spec - if (patchPath.length() >= 2 && + if (patchPath.length() >= 2 && Character.isLetter(patchPath.charAt(0)) && patchPath.charAt(1) == ':') { char[] ca = patchPath.replace('/', '\\').toCharArray(); @@ -445,46 +473,43 @@ patchPath = sb.toString(); } - // fix path on NetWare - all '/' become '\\' and remove duplicate '\\' - if (System.getProperty("os.name").startsWith("NetWare") && - path.length() >=3 && - path.indexOf(':') > 0) { - char[] ca = patchPath.replace('/', '\\').toCharArray(); - StringBuffer sb = new StringBuffer(); - - for (int i = 0; i < ca.length; i++) { - if ((ca[i] != '\\') || - (ca[i] == '\\' && i > 0 && ca[i - 1] != '\\')) { - sb.append(ca[i]); - } - } - patchPath = sb.toString(); - } + // fix path on NetWare - all '/' become '\\' and remove duplicate '\\' + if (System.getProperty("os.name").startsWith("NetWare") && + path.length() >=3 && + path.indexOf(':') > 0) { + char[] ca = patchPath.replace('/', '\\').toCharArray(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < ca.length; i++) { + if ((ca[i] != '\\') || + (ca[i] == '\\' && i > 0 && ca[i - 1] != '\\')) { + sb.append(ca[i]); + } + } + patchPath = sb.toString(); + } return patchPath; } public static boolean isAbsolute( String path ) { - // normal file - if( path.startsWith("/" ) ) return true; + // normal file + if( path.startsWith("/" ) ) return true; - if( path.startsWith(File.separator ) ) return true; + if( path.startsWith(File.separator ) ) return true; - // win c: - if (path.length() >= 3 && + // win c: + if (path.length() >= 3 && Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') - return true; + return true; - // NetWare volume: - if (System.getProperty("os.name").startsWith("NetWare") && - path.length() >=3 && - path.indexOf(':') > 0) - return true; + // NetWare volume: + if (System.getProperty("os.name").startsWith("NetWare") && + path.length() >=3 && + path.indexOf(':') > 0) + return true; - return false; - } - protected void log(String msg) { - System.err.println(msg); + return false; } } 1.4 +11 -9 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/IISConfig.java Index: IISConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/config/IISConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- IISConfig.java 29 Aug 2004 17:14:41 -0000 1.3 +++ IISConfig.java 5 Dec 2004 06:29:15 -0000 1.4 @@ -93,6 +93,8 @@ @author Bill Barker */ public class IISConfig extends BaseJkConfig { + private static org.apache.commons.logging.Log log = + org.apache.commons.logging.LogFactory.getLog(IISConfig.class); public static final String WORKERS_CONFIG = "/conf/jk/workers.properties"; public static final String URI_WORKERS_MAP_CONFIG = "/conf/auto/uriworkermap.properties"; @@ -151,14 +153,14 @@ protected boolean generateJkHead(PrintWriter mod_jk) { try { PrintWriter regfile = new PrintWriter(new FileWriter(regConfig)); - log("Generating IIS registry file = "+regConfig ); + log.info("Generating IIS registry file = "+regConfig ); generateRegistrySettings(regfile); regfile.close(); } catch(IOException iex) { - log("Unable to generate registry file " +regConfig); + log.warn("Unable to generate registry file " +regConfig); return false; } - log("Generating IIS URI worker map file = "+uriConfig ); + log.info("Generating IIS URI worker map file = "+uriConfig ); generateUriWorkerHeader(mod_jk); return true; } @@ -204,7 +206,7 @@ String nPath=("".equals(ctxPath)) ? "/" : ctxPath; if( noRoot && "".equals(ctxPath) ) { - log("Ignoring root context in forward-all mode "); + log.debug("Ignoring root context in forward-all mode "); return; } @@ -227,7 +229,7 @@ String nPath=("".equals(ctxPath)) ? "/" : ctxPath; if( noRoot && "".equals(ctxPath) ) { - log("Ignoring root context in forward-all mode "); + log.debug("Ignoring root context in forward-all mode "); return; } @@ -264,8 +266,8 @@ protected boolean addMapping( String ctxPath, String ext, PrintWriter uri_worker ) { - if( debug > 0 ) - log( "Adding extension map for " + ctxPath + "/*." + ext ); + if( log.isDebugEnabled() ) + log.debug( "Adding extension map for " + ctxPath + "/*." + ext ); if(! ext.startsWith("/") ) ext = "/" + ext; if(ext.length() > 1) @@ -276,8 +278,8 @@ /** Add a fulling specified IIS mapping. */ protected boolean addMapping( String fullPath, PrintWriter uri_worker ) { - if( debug > 0 ) - log( "Adding map for " + fullPath ); + if( log.isDebugEnabled() ) + log.debug( "Adding map for " + fullPath ); uri_worker.println(fullPath + "=$(default.worker)" ); return true; } 1.4 +9 -7 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/NSConfig.java Index: NSConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/config/NSConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- NSConfig.java 29 Aug 2004 17:14:41 -0000 1.3 +++ NSConfig.java 5 Dec 2004 06:29:15 -0000 1.4 @@ -96,6 +96,8 @@ @author Bill Barker */ public class NSConfig extends BaseJkConfig { + private static org.apache.commons.logging.Log log = + org.apache.commons.logging.LogFactory.getLog(NSConfig.class); public static final String WORKERS_CONFIG = "/conf/jk/workers.properties"; public static final String NS_CONFIG = "/conf/auto/obj.conf"; @@ -178,7 +180,7 @@ return new PrintWriter(new FileWriter(abObjConfig,append)); } protected boolean generateJkHead(PrintWriter mod_jk) { - log("Generating netscape web server config = "+objConfig ); + log.info("Generating netscape web server config = "+objConfig ); generateNsapiHead( mod_jk ); @@ -246,7 +248,7 @@ String nPath=("".equals(ctxPath)) ? "/" : ctxPath; if( noRoot && "".equals(ctxPath) ) { - log("Ignoring root context in forward-all mode "); + log.debug("Ignoring root context in forward-all mode "); return; } objfile.println("<Object name=" + context.getName() + ">"); @@ -266,7 +268,7 @@ String nPath=("".equals(ctxPath)) ? "/" : ctxPath; if( noRoot && "".equals(ctxPath) ) { - log("Ignoring root context in non-forward-all mode "); + log.debug("Ignoring root context in non-forward-all mode "); return; } objfile.println("<Object name=" + context.getName() + ">"); @@ -303,8 +305,8 @@ protected boolean addMapping( String ctxPath, String ext, PrintWriter objfile ) { - if( debug > 0 ) - log( "Adding extension map for " + ctxPath + "/*." + ext ); + if( log.isDebugEnabled() ) + log.debug( "Adding extension map for " + ctxPath + "/*." + ext ); if(! ext.startsWith("/") ) ext = "/" + ext; if(ext.length() > 1) @@ -316,8 +318,8 @@ /** Add a fulling specified Netscape mapping. */ protected boolean addMapping( String fullPath, PrintWriter objfile ) { - if( debug > 0 ) - log( "Adding map for " + fullPath ); + if( log.isDebugEnabled() ) + log.debug( "Adding map for " + fullPath ); objfile.println("NameTrans fn=\"assign-name\" from=\"" + fullPath + "\" name=\"" + objectName + "\""); return true;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]