larryi 01/08/09 20:57:08 Modified: src/share/org/apache/tomcat/modules/config ApacheConfig.java IISConfig.java NSConfig.java Added: src/share/org/apache/tomcat/modules/config BaseJkConfig.java Log: Some refactoring to make "jk" based auto-config generators consistent as far as features. Removed check in ApacheConfig for Ajp13Interceptor from jakarta-tomcat-connectors. Still need to update IISConfig.java and NSConfig.java to support the forwardAll and noRoot attributes. Revision Changes Path 1.21 +10 -172 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ApacheConfig.java Index: ApacheConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ApacheConfig.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ApacheConfig.java 2001/08/02 10:33:02 1.20 +++ ApacheConfig.java 2001/08/10 03:57:07 1.21 @@ -1,4 +1,4 @@ -/* $Id: ApacheConfig.java,v 1.20 2001/08/02 10:33:02 larryi Exp $ +/* $Id: ApacheConfig.java,v 1.21 2001/08/10 03:57:07 larryi Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -62,13 +62,8 @@ import org.apache.tomcat.util.io.FileUtil; import org.apache.tomcat.util.log.*; import java.io.*; -import java.net.*; import java.util.*; -// Used to find Ajp1? connector port -import org.apache.tomcat.modules.server.Ajp12Interceptor; -import org.apache.tomcat.modules.server.Ajp13Interceptor; - /* The idea is to keep all configuration in server.xml and the normal apache config files. We don't want people to touch apache ( or IIS, NES ) config files unless they @@ -90,7 +85,7 @@ */ /** - Generates automatic apache configurations based on + Generates automatic apache mod_jk configurations based on the Tomcat server.xml settings and the war contexts initialized during startup. <p> @@ -112,7 +107,7 @@ </li> <li><b>jkConfig</b> - path to use for writing Apache mod_jk conf file. If not set, defaults to - "conf/jk/mod_jk.conf".</li> + "conf/auto/mod_jk.conf".</li> <li><b>workersConfig</b> - path to workers.properties file used by mod_jk. If not set, defaults to "conf/jk/workers.properties".</li> @@ -122,7 +117,7 @@ "libexec/mod_jk.so" everywhere else.</li> <li><b>jkLog</b> - path to log file to be used by mod_jk.</li> <li><b>jkDebug</b> - JK Loglevel setting. May be debug, info, error, or emerg. - If not set, defaults to no log.</li> + If not set, defaults to emerg.</li> <li><b>jkProtocol</b> The desired protocal, "ajp12" or "ajp13". If not specified, defaults to "ajp13" if an Ajp13Interceptor is in use, otherwise it defaults to "ajp12".</li> @@ -149,10 +144,11 @@ </ul> <p> @author Costin Manolache + @author Larry Isaacs @author Mel Martinez - @version $Revision: 1.20 $ $Date: 2001/08/02 10:33:02 $ + @version $Revision: 1.21 $ $Date: 2001/08/10 03:57:07 $ */ -public class ApacheConfig extends BaseInterceptor { +public class ApacheConfig extends BaseJkConfig { /** default path to mod_jk .conf location */ public static final String MOD_JK_CONFIG = "conf/auto/mod_jk.conf"; @@ -177,23 +173,8 @@ } } - public static final String JTC_AJP13_INTERCEPTOR = - "org.apache.ajp.tomcat33.Ajp13Interceptor"; - - private File configHome = null; private File jkConfig = null; - private File workersConfig = null; private File modJk = null; - private File jkLog = null; - - private String jkProto = null; - private int portInt=0; - String tomcatHome; - private boolean useJkMount=true; - - private String jkDebug=null; - - private boolean noRoot=true; // ssl settings private boolean sslExtract=true; @@ -202,10 +183,6 @@ private String sslCipherIndicator="SSL_CIPHER"; private String sslCertsIndicator="SSL_CLIENT_CERT"; - // default is true until we can map all web.xml directives - // Or detect only portable directives were used. - boolean forwardAll=true; - public ApacheConfig() { } @@ -238,60 +215,10 @@ //-------------------- Properties -------------------- - /** 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. - */ - public void setForwardAll( boolean b ) { - 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 Apache's root remains intact but isn't completely - servlet/JSP enabled. If the ROOT webapp can be configured with - apache serving static files, there's no problem setting this - option to false. If not, then setting it false means Apache 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 setJservConfig(), setJkConfig() - and setWorkerConfig() paths would be resolved against - if relative. For example if ConfigHome is set to "/home/tomcat" - and JkConfig is set to "conf/mod_jk.conf" then the resulting - path returned from getJkConfig() would be: - "/home/tomcat/conf/mod_jk.conf".</p> - <p> - However, if JkConfig, JservConfig or WorkersConfig - are set to absolute paths, this attribute is ignored. - <p> - If not set, execute() will set this to TOMCAT_HOME. - <p> - @param <b>dir</b> - path to a directory - */ - public void setConfigHome(String dir){ - if( dir==null ) return; - File f=new File(dir); - if(!f.isDirectory()){ - throw new IllegalArgumentException( - "ApacheConfig.setConfigHome(): "+ - "Configuration Home must be a directory! : "+dir); - } - configHome = f; - } - - /** set the path to the output file for the auto-generated mod_jk configuration file. If this path is relative - then getJkConfig() will resolve it absolutely against + then it will be resolved absolutely against the getConfigHome() path. <p> @param <b>path</b> String path to a file @@ -301,43 +228,12 @@ } /** - set a path to the workers.properties file. - @param <b>path</b> String path to workers.properties file - */ - public void setWorkersConfig(String path){ - workersConfig= (path==null?null:new File(path)); - } - - /** set the path to the mod_jk Apache Module @param <b>path</b> String path to a file */ public void setModJk(String path){ modJk=( path==null?null:new File(path)); } - /** - set the path to the mod_jk log file - @param <b>path</b> String path to a file - */ - public void setJkLog(String path){ - jkLog= ( path==null?null:new File(path)); - } - - /** - set the Ajp protocal - @param <b>protocal</b> String protocol, "ajp12" or "ajp13" - */ - public void setJkProtocol(String protocol){ - jkProto = protocol; - } - - - /** Set the verbosity level for mod_jk. - ( use debug, error, etc, off or none disables ) - */ - public void setJkDebug( String level ) { - jkDebug=null; - } /** By default mod_jk is configured to collect SSL information from the apache environment and send it to the Tomcat workers. The @@ -383,12 +279,8 @@ /** Initialize defaults for properties that are not set explicitely */ - public void initProperties(ContextManager cm) { - tomcatHome = cm.getHome(); - File tomcatDir = new File(tomcatHome); - if(configHome==null){ - configHome=tomcatDir; - } + protected void initProperties(ContextManager cm) { + super.initProperties(cm); jkConfig=getConfigFile( jkConfig, configHome, MOD_JK_CONFIG); workersConfig=getConfigFile( workersConfig, configHome, @@ -400,37 +292,6 @@ jkLog=getConfigFile( jkLog, configHome, JK_LOG_LOCATION); } - private void initProtocol(ContextManager cm) { - if( portInt == 0 ) - portInt=8007; - - // Find Ajp1? connectors - BaseInterceptor ci[]=cm.getContainer().getInterceptors(); - // try to get jakarta-tomcat-connectors Ajp13 Interceptor class - Class jtcAjp13 = null; - try { - jtcAjp13 = Class.forName(JTC_AJP13_INTERCEPTOR); - } catch ( ClassNotFoundException e ) { } - - for( int i=0; i<ci.length; i++ ) { - Object con=ci[i]; - if( con instanceof Ajp12Interceptor ) { - Ajp12Interceptor tcpCon=(Ajp12Interceptor) con; - portInt=tcpCon.getPort(); - } - // if jkProtocol not specified and Ajp13 Interceptor found, use Ajp13 - // ??? XXX - if( jkProto == null && - ( con instanceof Ajp13Interceptor || - ( jtcAjp13 != null && jtcAjp13.isInstance(con) ) ) ) { - jkProto = "ajp13"; - } - } - - // default to ajp12 - if( jkProto==null ) jkProto="ajp12"; - } - // -------------------- Generate config -------------------- /** @@ -523,7 +384,6 @@ + "\""); mod_jk.println(); - // XXX Make it configurable if( jkDebug != null ) { mod_jk.println("JkLogLevel " + jkDebug); mod_jk.println(); @@ -785,28 +645,6 @@ } // -------------------- Utils -------------------- - - private File getConfigFile( File base, File configDir, String defaultF ) - { - //log( "getConfigFile " + base + " " + configDir + " " +defaultF ); - if( base==null ) - base=new File( defaultF ); - if( ! base.isAbsolute() ) { - if( configDir != null ) - base=new File( configDir, base.getPath()); - else - base=new File( base.getAbsolutePath()); //?? - } - File parent=new File(base.getParent()); - if(!parent.exists()){ - if(!parent.mkdirs()){ - throw new RuntimeException( - "Unable to create path to config file :"+ - jkConfig.getAbsolutePath()); - } - } - return base; - } private String getApacheDocBase(Context context) { 1.5 +131 -20 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/IISConfig.java Index: IISConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/IISConfig.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- IISConfig.java 2001/07/20 12:47:44 1.4 +++ IISConfig.java 2001/08/10 03:57:07 1.5 @@ -62,22 +62,83 @@ import org.apache.tomcat.util.*; import org.apache.tomcat.util.log.*; import java.io.*; -import java.net.*; import java.util.*; /** - * Used by ContextManager to generate automatic IIS configurations - * - * @author Gal Shachor [EMAIL PROTECTED] + Generates automatic IIS isapi_redirect configurations based on + the Tomcat server.xml settings and the war contexts + initialized during startup. + <p> + This config interceptor is enabled by inserting an IISConfig + element in the <b><ContextManager></b> tag body inside + the server.xml file like so: + <pre> + * < ContextManager ... > + * ... + * <<b>IISConfig</b> <i>options</i> /> + * ... + * < /ContextManager > + </pre> + where <i>options</i> can include any of the following attributes: + <ul> + <li><b>configHome</b> - default parent directory for the following paths. + If not set, this defaults to TOMCAT_HOME. Ignored + whenever any of the following paths is absolute. + </li> + <li><b>regConfig</b> - path to use for writing IIS isapi_redirect registry + file. If not set, defaults to + "conf/auto/iis_redirect.reg".</li> + <li><b>workersConfig</b> - path to workers.properties file used by + isapi_redirect. If not set, defaults to + "conf/jk/workers.properties".</li> + <li><b>uriConfig</b> - path to use for writing IIS isapi_redirect uriworkermap + file. If not set, defaults to + "conf/auto/uriworkermap.properties".</li> + <li><b>jkLog</b> - path to log file to be used by isapi_redirect.</li> + <li><b>jkDebug</b> - Loglevel setting. May be debug, info, error, or emerg. + If not set, defaults to emerg.</li> + <li><b>jkProtocol</b> The desired protocal, "ajp12" or "ajp13". If not + specified, defaults to "ajp13" if an Ajp13Interceptor + is in use, otherwise it defaults to "ajp12".</li> + <li><b>forwardAll</b> - If true, forward all requests to Tomcat. This helps + insure that all the behavior configured in the web.xml + file functions correctly. If false, let IIS serve + static resources assuming it has been configured + to do so. The default is true. + Warning: When false, some configuration in + the web.xml may not be duplicated in IIS. + Review the uriworkermap file to see what + configuration is actually being set in IIS.</li> + <li><b>noRoot</b> - If true, the root context is not mapped to + Tomcat. If false and forwardAll is true, all requests + to the root context are mapped to Tomcat. If false and + forwardAll is false, only JSP and servlets requests to + the root context are mapped to Tomcat. When false, + to correctly serve Tomcat's root context you must also + modify the Home Directory setting in IIS + to point to Tomcat's root context directory. + Otherwise some content, such as the root index.html, + will be served by IIS before isapi_redirect gets a chance + to claim the request and pass it to Tomcat. + The default is true.</li> + </ul> + <p> + @author Costin Manolache + @author Larry Isaacs + @author Gal Shachor + @version $Revision: 1.5 $ */ -public class IISConfig extends BaseInterceptor { +public class IISConfig extends BaseJkConfig { public static final String WORKERS_CONFIG = "/conf/jk/workers.properties"; - public static final String URL_WORKERS_MAP_CONFIG = "/conf/jk/uriworkermap.properties"; - public static final String JK_LOG_LOCATION = "/logs/iis_redirect.log"; - public static final String IIS_REG_FILE = "/conf/jk/iis_redirect.reg"; + public static final String URI_WORKERS_MAP_CONFIG = "/conf/auto/uriworkermap.properties"; + public static final String ISAPI_LOG_LOCATION = "/logs/isapi_redirect.log"; + public static final String ISAPI_REG_FILE = "/conf/auto/isapi_redirect.reg"; + private File regConfig = null; + private File uriConfig = null; + Log loghelper = Log.getLog("tc_log", "IISConfig"); public IISConfig() @@ -87,24 +148,71 @@ public void engineInit(ContextManager cm) throws TomcatException { execute( cm ); + } + + //-------------------- Properties -------------------- + + /** + set the path to the output file for the auto-generated + isapi_redirect registry file. If this path is relative + then getRegConfig() will resolve it absolutely against + the getConfigHome() path. + <p> + @param <b>path</b> String path to a file + */ + public void setRegConfig(String path){ + regConfig= (path==null)?null:new File(path); + } + + /** + set a path to the uriworkermap.properties file. + @param <b>path</b> String path to uriworkermap.properties file + */ + public void setUriConfig(String path){ + uriConfig= (path==null?null:new File(path)); + } + + // -------------------- Initialize/guess defaults -------------------- + + /** Initialize defaults for properties that are not set + explicitely + */ + protected void initProperties(ContextManager cm) { + super.initProperties(cm); + + regConfig=getConfigFile( regConfig, configHome, ISAPI_REG_FILE); + workersConfig=getConfigFile( workersConfig, configHome, WORKERS_CONFIG); + uriConfig=getConfigFile( uriConfig, configHome, URI_WORKERS_MAP_CONFIG); + jkLog=getConfigFile( jkLog, configHome, ISAPI_LOG_LOCATION); } - + + // -------------------- Generate config -------------------- + + /** + executes the IISConfig interceptor. This method generates IIS + configuration files for use with isapi_redirect. If not + already set, this method will setConfigHome() to the value returned + from <i>cm.getHome()</i>. + <p> + @param <b>cm</b> a ContextManager object. + */ public void execute(ContextManager cm) throws TomcatException { - try { - String tomcatHome = cm.getHome(); + try { + initProperties(cm); + initProtocol(cm); - PrintWriter regfile = new PrintWriter(new FileWriter(tomcatHome + IIS_REG_FILE + "-auto")); - PrintWriter uri_worker = new PrintWriter(new FileWriter(tomcatHome + URL_WORKERS_MAP_CONFIG + "-auto")); + PrintWriter regfile = new PrintWriter(new FileWriter(regConfig)); + PrintWriter uri_worker = new PrintWriter(new FileWriter(uriConfig)); regfile.println("REGEDIT4"); regfile.println(); regfile.println("[HKEY_LOCAL_MACHINE\\SOFTWARE\\Apache Software Foundation\\Jakarta Isapi Redirector\\1.0]"); regfile.println("\"extension_uri\"=\"/jakarta/isapi_redirect.dll\""); - regfile.println("\"log_file\"=\"" + dubleSlash(new File(tomcatHome, JK_LOG_LOCATION).toString()) +"\""); - regfile.println("\"log_level\"=\"debug\""); - regfile.println("\"worker_file\"=\"" + dubleSlash(new File(tomcatHome, WORKERS_CONFIG).toString()) +"\""); - regfile.println("\"worker_mount_file\"=\"" + dubleSlash(new File(tomcatHome, URL_WORKERS_MAP_CONFIG).toString()) +"\""); + regfile.println("\"log_file\"=\"" + dubleSlash(jkLog.toString()) +"\""); + regfile.println("\"log_level\"=\"" + jkDebug + "\""); + regfile.println("\"worker_file\"=\"" + dubleSlash(workersConfig.toString()) +"\""); + regfile.println("\"worker_mount_file\"=\"" + dubleSlash(uriConfig.toString()) +"\""); uri_worker.println("###################################################################"); @@ -115,7 +223,7 @@ uri_worker.println("#"); uri_worker.println("# Default worker to be used through our mappings"); uri_worker.println("#"); - uri_worker.println("default.worker=ajp12"); + uri_worker.println("default.worker=" + jkProto); uri_worker.println(); uri_worker.println("#"); @@ -139,7 +247,7 @@ continue; } if(path.length() > 1) { - // Static files will be served by Apache + // Static files will be served by IIS uri_worker.println("#########################################################"); uri_worker.println("# Auto configuration for the " + path + " context starts."); uri_worker.println("#########################################################"); @@ -160,6 +268,7 @@ uri_worker.println("# IIS to serve static resources, comment out this line and replace with"); uri_worker.println("# appropriate mappings. Then update the IIS configuration as needed."); uri_worker.println("#"); + uri_worker.println(path +"=$(default.worker)"); uri_worker.println(path +"/*=$(default.worker)"); uri_worker.println("#######################################################"); @@ -176,7 +285,9 @@ loghelper.log("Error generating automatic IIS configuration", ex); } } - + + // -------------------- Utils -------------------- + protected String dubleSlash(String in) { StringBuffer sb = new StringBuffer(); 1.4 +114 -19 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/NSConfig.java Index: NSConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/NSConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- NSConfig.java 2001/03/02 04:49:14 1.3 +++ NSConfig.java 2001/08/10 03:57:07 1.4 @@ -62,21 +62,78 @@ import org.apache.tomcat.util.io.FileUtil; import org.apache.tomcat.util.log.*; import java.io.*; -import java.net.*; import java.util.*; /** - * Used by ContextManager to generate automatic Netscape configurations - * - * @author Gal Shachor [EMAIL PROTECTED] + Generates automatic Netscape nsapi_redirect configurations based on + the Tomcat server.xml settings and the war contexts + initialized during startup. + <p> + This config interceptor is enabled by inserting an NSConfig + element in the <b><ContextManager></b> tag body inside + the server.xml file like so: + <pre> + * < ContextManager ... > + * ... + * <<b>NSConfig</b> <i>options</i> /> + * ... + * < /ContextManager > + </pre> + where <i>options</i> can include any of the following attributes: + <ul> + <li><b>configHome</b> - default parent directory for the following paths. + If not set, this defaults to TOMCAT_HOME. Ignored + whenever any of the following paths is absolute. + </li> + <li><b>objConfig</b> - path to use for writing Netscape obj.conf + file. If not set, defaults to + "conf/auto/obj.conf".</li> + <li><b>workersConfig</b> - path to workers.properties file used by + nsapi_redirect. If not set, defaults to + "conf/jk/workers.properties".</li> + <li><b>jkLog</b> - path to log file to be used by nsapi_redirect.</li> + <li><b>jkDebug</b> - Loglevel setting. May be debug, info, error, or emerg. + If not set, defaults to emerg.</li> + <li><b>jkProtocol</b> The desired protocal, "ajp12" or "ajp13". If not + specified, defaults to "ajp13" if an Ajp13Interceptor + is in use, otherwise it defaults to "ajp12".</li> + <li><b>forwardAll</b> - If true, forward all requests to Tomcat. This helps + insure that all the behavior configured in the web.xml + file functions correctly. If false, let Netscape serve + static resources assuming it has been configured + to do so. The default is true. + Warning: When false, some configuration in + the web.xml may not be duplicated in Netscape. + Review the uriworkermap file to see what + configuration is actually being set in Netscape.</li> + <li><b>noRoot</b> - If true, the root context is not mapped to + Tomcat. If false and forwardAll is true, all requests + to the root context are mapped to Tomcat. If false and + forwardAll is false, only JSP and servlets requests to + the root context are mapped to Tomcat. When false, + to correctly serve Tomcat's root context you must also + modify the Home Directory setting in Netscape + to point to Tomcat's root context directory. + Otherwise some content, such as the root index.html, + will be served by Netscape before nsapi_redirect gets a chance + to claim the request and pass it to Tomcat. + The default is true.</li> + </ul> + <p> + @author Costin Manolache + @author Larry Isaacs + @author Gal Shachor + @version $Revision: 1.4 $ */ -public class NSConfig extends BaseInterceptor { +public class NSConfig extends BaseJkConfig { public static final String WORKERS_CONFIG = "/conf/jk/workers.properties"; - public static final String NS_CONFIG = "/conf/jk/obj.conf"; - public static final String JK_LOG_LOCATION = "/logs/netscape_redirect.log"; + public static final String NS_CONFIG = "/conf/auto/obj.conf"; + public static final String NSAPI_LOG_LOCATION = "/logs/nsapi_redirect.log"; + private File objConfig = null; + Log loghelper = Log.getLog("tc_log", this); public NSConfig() @@ -88,12 +145,50 @@ execute( cm ); } + //-------------------- Properties -------------------- + + /** + set the path to the output file for the auto-generated + isapi_redirect registry file. If this path is relative + then getRegConfig() will resolve it absolutely against + the getConfigHome() path. + <p> + @param <b>path</b> String path to a file + */ + public void setObjConfig(String path){ + objConfig= (path==null)?null:new File(path); + } + + // -------------------- Initialize/guess defaults -------------------- + + /** Initialize defaults for properties that are not set + explicitely + */ + protected void initProperties(ContextManager cm) { + super.initProperties(cm); + + objConfig=getConfigFile( objConfig, configHome, NS_CONFIG); + workersConfig=getConfigFile( workersConfig, configHome, WORKERS_CONFIG); + jkLog=getConfigFile( jkLog, configHome, NSAPI_LOG_LOCATION); + } + + // -------------------- Generate config -------------------- + + /** + executes the NSConfig interceptor. This method generates Netscape + configuration files for use with nsapi_redirect. If not + already set, this method will setConfigHome() to the value returned + from <i>cm.getHome()</i>. + <p> + @param <b>cm</b> a ContextManager object. + */ public void execute(ContextManager cm) throws TomcatException { - try { - String tomcatHome = cm.getHome(); + try { + initProperties(cm); + initProtocol(cm); - PrintWriter objfile = new PrintWriter(new FileWriter(tomcatHome + NS_CONFIG + "-auto")); + PrintWriter objfile = new PrintWriter(new FileWriter(objConfig)); objfile.println("###################################################################"); objfile.println("# Auto generated configuration. Dated: " + new Date()); @@ -112,9 +207,9 @@ objfile.println(); objfile.println("Init fn=\"load-modules\" funcs=\"jk_init,jk_service\" shlib=\"<put full path to the redirector here>\""); objfile.println("Init fn=\"jk_init\" worker_file=\"" + - new File(tomcatHome, WORKERS_CONFIG).toString().replace('\\', '/') + - "\" log_level=\"debug\" log_file=\"" + - new File(tomcatHome, JK_LOG_LOCATION).toString().replace('\\', '/') + + workersConfig.toString().replace('\\', '/') + + "\" log_level=\"" + jkDebug + "\" log_file=\"" + + jkLog.toString().replace('\\', '/') + "\""); objfile.println(); @@ -135,7 +230,7 @@ String vhost = context.getHost(); if(vhost != null) { - // Vhosts are not supported yet for IIS + // Vhosts are not supported yet for Netscape continue; } if(path.length() > 1) { @@ -180,14 +275,14 @@ objfile.println("#######################################################"); objfile.println("<Object name=servlet>"); objfile.println("ObjectType fn=force-type type=text/html"); - objfile.println("Service fn=\"jk_service\" worker=\"ajp12\" path=\"/*\""); + objfile.println("Service fn=\"jk_service\" worker=\""+ jkProto + "\" path=\"/*\""); objfile.println("</Object>"); objfile.println(); - objfile.close(); - } catch(Exception ex) { - loghelper.log("Error generating automatic Netscape configuration", ex); - } + objfile.close(); + } catch(Exception ex) { + loghelper.log("Error generating automatic Netscape configuration", ex); + } } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/BaseJkConfig.java Index: BaseJkConfig.java =================================================================== /* $Id: BaseJkConfig.java,v 1.1 2001/08/10 03:57:07 larryi Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.modules.config; import org.apache.tomcat.core.*; import java.io.*; import org.apache.tomcat.modules.server.Ajp13Interceptor; /** Base class for automatic jk based configurations based on the Tomcat server.xml settings and the war contexts initialized during startup. <p> This config interceptor is enabled by inserting a Config element in the <b><ContextManager></b> tag body inside the server.xml file like so: <pre> * < ContextManager ... > * ... * <<b>???Config</b> <i>options</i> /> * ... * < /ContextManager > </pre> where <i>options</i> can include any of the following attributes: <ul> <li><b>configHome</b> - default parent directory for the following paths. If not set, this defaults to TOMCAT_HOME. Ignored whenever any of the following paths is absolute. </li> <li><b>workersConfig</b> - path to workers.properties file used by jk connector. If not set, defaults to "conf/jk/workers.properties".</li> <li><b>jkLog</b> - path to log file to be used by jk connector.</li> <li><b>jkDebug</b> - Loglevel setting. May be debug, info, error, or emerg. If not set, defaults to emerg.</li> <li><b>jkProtocol</b> The desired protocal, "ajp12" or "ajp13". If not specified, defaults to "ajp13" if an Ajp13Interceptor is in use, otherwise it defaults to "ajp12".</li> <li><b>forwardAll</b> - If true, forward all requests to Tomcat. This helps insure that all the behavior configured in the web.xml file functions correctly. If false, let Apache serve static resources. The default is true. Warning: When false, some configuration in the web.xml may not be duplicated in Apache. Review the mod_jk conf file to see what configuration is actually being set in Apache.</li> <li><b>noRoot</b> - If true, the root context is not mapped to Tomcat. If false and forwardAll is true, all requests to the root context are mapped to Tomcat. If false and forwardAll is false, only JSP and servlets requests to the root context are mapped to Tomcat. When false, to correctly serve Tomcat's root context you may also need to modify the web server to point it's home directory to Tomcat's root context directory. Otherwise some content, such as the root index.html, may be served by the web server before the connector gets a chance to claim the request and pass it to Tomcat. The default is true.</li> </ul> <p> @author Costin Manolache @author Larry Isaacs @version $Revision: 1.1 $ */ public class BaseJkConfig extends BaseInterceptor { protected File configHome = null; protected File workersConfig = null; protected File jkLog = null; protected String jkDebug="emerg"; protected String jkProto = null; protected boolean noRoot=true; protected boolean forwardAll=true; protected String tomcatHome; //-------------------- Properties -------------------- /** 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. */ public void setForwardAll( boolean b ) { 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. */ 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 <b>dir</b> - path to a directory */ public void setConfigHome(String dir){ if( dir==null ) return; File f=new File(dir); if(!f.isDirectory()){ throw new IllegalArgumentException( "BaseConfig.setConfigHome(): "+ "Configuration Home must be a directory! : "+dir); } configHome = f; } /** set a path to the workers.properties file. @param <b>path</b> String path to workers.properties file */ public void setWorkersConfig(String path){ workersConfig= (path==null?null:new File(path)); } /** set the path to the mod_jk log file @param <b>path</b> String path to a file */ public void setJkLog(String path){ jkLog= ( path==null?null:new File(path)); } /** Set the verbosity level for mod_jk. ( use debug, error, etc. ) If not set, no log is written. */ public void setJkDebug( String level ) { jkDebug=level; } /** set the Ajp protocal @param <b>protocal</b> String protocol, "ajp12" or "ajp13" */ public void setJkProtocol(String protocol){ jkProto = protocol; } // -------------------- Initialize/guess defaults -------------------- /** Initialize defaults for properties that are not set explicitely */ protected void initProperties(ContextManager cm) { tomcatHome = cm.getHome(); File tomcatDir = new File(tomcatHome); if(configHome==null){ configHome=tomcatDir; } } protected void initProtocol(ContextManager cm) { // Find Ajp1? connectors BaseInterceptor ci[]=cm.getContainer().getInterceptors(); for( int i=0; i<ci.length; i++ ) { Object con=ci[i]; // if jkProto not specified and Ajp13 Interceptor found, use Ajp13 if( jkProto == null && (con instanceof Ajp13Interceptor) ) { jkProto = "ajp13"; } } // default to ajp12 if( jkProto==null ) jkProto="ajp12"; } // -------------------- Utils -------------------- protected File getConfigFile( File base, File configDir, String defaultF ) { if( base==null ) base=new File( defaultF ); if( ! base.isAbsolute() ) { if( configDir != null ) base=new File( configDir, base.getPath()); else base=new File( base.getAbsolutePath()); //?? } File parent=new File(base.getParent()); if(!parent.exists()){ if(!parent.mkdirs()){ throw new RuntimeException( "Unable to create path to config file :"+ base.getAbsolutePath()); } } return base; } }