costin      01/07/03 16:32:28

  Modified:    src/share/org/apache/tomcat/modules/config ApacheConfig.java
  Log:
  Removed the jserv configuration part, reorganize a bit the code.
  
  The context mappings will be generated only of the user explicitely
  asks that, by default we'll forward all requests to tomcat, including
  static files ( since not all web.xml can be mapped to apache configs ).
  
  Later we can detect if web.xml can be mapped and generate native mappings
  for those contexts, and when mod_jk will finish duplicating the
  mapper we can generate uri_worker_map file.
  
  The second part will probably go in a UriMap.java file that will be shared
  for all servers, ApacheConfig will still generate apache-specific
  configuration.
  
  Revision  Changes    Path
  1.12      +305 -629  
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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ApacheConfig.java 2001/06/21 13:04:19     1.11
  +++ ApacheConfig.java 2001/07/03 23:32:26     1.12
  @@ -1,4 +1,4 @@
  -/* $Id: ApacheConfig.java,v 1.11 2001/06/21 13:04:19 larryi Exp $
  +/* $Id: ApacheConfig.java,v 1.12 2001/07/03 23:32:26 costin Exp $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -90,19 +90,12 @@
                               If not set, this defaults to TOMCAT_HOME. Ignored
                               whenever any of the following paths is absolute.
                                </li>
  -     <li><b>jservconfig</b> - path to write apache jserv conf file to. If
  -                             not set, defaults to
  -                             "conf/jserv/tomcat-apache.conf".</li>
        <li><b>jkconfig</b> - path to write apacke mod_jk conf file to. If
                               not set, defaults to
                               "conf/jk/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>
  -     <li><b>modjserv</b> - path to Apache JServ plugin module file. If not 
  -                           set, defaults to "modules/ApacheModuleJServ.dll"
  -                           on windows, "modules/Jserv.nlm" on netware, and 
  -                           "libexec/mod_jserv.so" everywhere else.</li>
        <li><b>modjk</b> - path to Apache mod_jk plugin file.  If not set,
                           defaults to "modules/mod_jk.dll" on windows,
                           "modules/mod_jk.nlm" on netware, and
  @@ -112,20 +105,16 @@
       <p>
       @author Costin Manolache
       @author Mel Martinez
  -     @version $Revision: 1.11 $ $Date: 2001/06/21 13:04:19 $
  +     @version $Revision: 1.12 $ $Date: 2001/07/03 23:32:26 $
    */
   public class ApacheConfig  extends BaseInterceptor { 
       
  -    /** default path to JServ .conf location */
  -    public static final String APACHE_CONFIG="conf/jserv/tomcat-apache.conf";
       /** default path to mod_jk .conf location */
       public static final String MOD_JK_CONFIG = "conf/jk/mod_jk.conf";
       /** default path to workers.properties file */
       public static final String WORKERS_CONFIG = "conf/jk/workers.properties";
       /** default mod_jk log file location */
       public static final String JK_LOG_LOCATION = "logs/mod_jk.log";
  -    /** default location of mod_jserv Apache plug-in. */
  -    public static final String MOD_JSERV;
       /** default location of mod_jk Apache plug-in. */
       public static final String MOD_JK;
       
  @@ -133,43 +122,38 @@
       static{
           String os = System.getProperty("os.name").toLowerCase();
           if(os.indexOf("windows")>=0){
  -           MOD_JSERV = "modules/ApacheModuleJserv.dll";
              MOD_JK = "modules/mod_jk.dll";
           }else if(os.indexOf("netware")>=0){
  -           MOD_JSERV = "modules/Jserv.nlm";
              MOD_JK = "modules/mod_jk.nlm";
           }else{
  -           MOD_JSERV = "libexec/mod_jserv.so";
              MOD_JK = "libexec/mod_jk.so";
           }
       }
       
  -    public static final String[] JkMount = { "ajp12", "ajp13" };
  -    public static final int AJP12 = 0;
  -    public static final int AJP13 = 1;
  -    public static final String AJPV12 = "ajpv12";
       public static final String JTC_AJP13_INTERCEPTOR =
               "org.apache.ajp.tomcat33.Ajp13Interceptor";
   
  -
       private File configHome = null;
  -    private File jservConfig = null;
       private File jkConfig = null;
       private File workersConfig = null;
  -    private File modJserv = null;
       private File modJk = null;
       private File jkLog = null;
  -
  -    private int jkProtocol = -1;
   
  +    private String jkProto = null;
  +    private int portInt=0;
  +    String tomcatHome;
  +    
  +    // default is true until we can map all web.xml directives
  +    // Or detect only portable directives were used.
  +    boolean forwardAll=true;
       
       public ApacheConfig() {
       }
  -
  -    String findApache() {
  -     return null;
  -    }
   
  +    // -------------------- Tomcat callbacks --------------------
  +    // ApacheConfig should be able to react to dynamic config changes,
  +    // and regenerate the config.
  +    
       /** Generate the apache configuration - only when the server is
        *  completely initialized ( before starting )
        */
  @@ -178,14 +162,13 @@
       {
        if( state != ContextManager.STATE_INIT )
            return;
  -
        execute( cm );
       }
   
       public void contextInit(Context ctx)
        throws TomcatException
       {
  -         ContextManager cm=ctx.getContextManager();
  +     ContextManager cm=ctx.getContextManager();
        if( cm.getState() >= ContextManager.STATE_INIT ) {
            // a context has been added after the server was started.
            // regenerate the config ( XXX send a restart signal to
  @@ -193,21 +176,16 @@
            execute( cm );
        }
       }
  -    
  -    /**
  -        this method helps the context's XMLMapper to work when
  -        setting properties.
  -    */
  -    public void setProperty(String name,String value){
  -        name = name.toLowerCase(); //case-insensitive
  -        if(name.equals("confighome")) setConfigHome(value);
  -        if(name.equals("jservconfig")) setJservConfig(value);
  -        if(name.equals("jkconfig")) setJkConfig(value);
  -        if(name.equals("workersconfig")) setWorkersConfig(value);
  -        if(name.equals("modjserv")) setModJserv(value);
  -        if(name.equals("modjk")) setModJk(value);
  -        if(name.equals("jklog")) setJkLog(value);
  -        if(name.equals("jkprotocol")) setJkProtocol(value);
  +
  +    //-------------------- 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;
       }
       
       /**
  @@ -228,98 +206,17 @@
           @param <b>dir</b> - path to a directory
       */
       public void setConfigHome(String dir){
  -        setConfigHome(dir==null?null:new File(dir));
  -    }
  -    
  -    /**
  -        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>
  -        @param <b>dir</b> - path to a directory
  -    */    
  -    public void setConfigHome(File dir){
  -        if(!dir.isDirectory()){
  +     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 = dir;
  -    }
  -    
  -    /**
  -        @return the parent directory of the conf directory
  -            or null if not set.
  -    */
  -    public File getConfigHome(){
  -        return configHome;
  +        configHome = f;
       }
       
       /**
  -        sets a path pointing to the output file
  -        in which to write the mod_jserv configuration.
  -    */
  -    public void setJservConfig(String path){
  -        setJservConfig(path==null?null:new File(path));
  -    }
  -    
  -    /**
  -        sets a File object pointing to the output file
  -        in which to write the mod_jserv configuration.
  -    */
  -    public void setJservConfig(File path){
  -        jservConfig=path;
  -        
  -    }
  -
  -
  -    /**
  -        return a File object pointing to the output file
  -        in which to write the mod_jserv configuration.
  -        If the path set using setJservConfig() was absolute,
  -        then this simply returns that File object.
  -        If the path set using setJservConfig() was relative
  -        then this method will first try to resolve it
  -        absolutely against the path returned from getConfigHome().
  -        If getConfigHome()==null, then instead the path
  -        will be resolved absolutely against the current
  -        directory (System.getProperty("user.dir")).
  -        <p>
  -        @return a File object.
  -    */
  -    public File getJservConfig(){
  -        if(jservConfig==null){
  -            jservConfig = new File(APACHE_CONFIG);
  -        }
  -        File jservF = jservConfig;
  -        if(!jservF.isAbsolute()){
  -            if(getConfigHome()!=null){
  -                jservF = new File(
  -                    getConfigHome(),jservF.getPath());
  -            }else{ //resolve against user.dir (implicit)
  -                jservF = new File(jservF.getAbsolutePath());
  -            }
  -        }
  -        File parent = new File(jservF.getParent());
  -        if(!parent.exists()){
  -            if(!parent.mkdirs()){
  -                throw new RuntimeException(
  -                    "Unable to create path to config file :"+jservF);
  -            }
  -        }
  -        return jservF;
  -    }
  -  
  -    
  -    /**
           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
  @@ -328,254 +225,89 @@
           @param <b>path</b> String path to a file
       */
       public void setJkConfig(String path){
  -        setJkConfig(path==null?null:new File(path));
  +     jkConfig= (path==null)?null:new File(path);
       }
  -    
  -    /**
  -        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
  -        the getConfigHome() path.
  -        <p>
  -        @param <b>path</b> File object
  -    */
  -    public void setJkConfig(File path){
  -        jkConfig = path;
  -    }
  -    
  -    /**
  -        return a File object pointing to the output file
  -        in which to write the mod_jk configuration.
  -        If the path set using setJkConfig() was absolute,
  -        then this simply returns that File object.
  -        If the path set using setJkConfig() was relative
  -        then this method will first try to resolve it
  -        absolutely against the path returned from getConfigHome().
  -        If getConfigHome()==null, then instead the path
  -        will be resolved absolutely against the current
  -        directory (System.getProperty("user.dir")).
  -        <p>
  -        @return a File object.
  -    */
  -    public File getJkConfig(){
  -        if(jkConfig==null){
  -            jkConfig = new File(MOD_JK_CONFIG+"-auto");
  -        }
  -        File jkF = jkConfig;
  -        if(!jkF.isAbsolute()){
  -            if(getConfigHome()!=null){
  -                jkF = new File(getConfigHome(),jkF.getPath());
  -            }else{//resolve against user.dir
  -                jkF = new File(jkF.getAbsolutePath());
  -            }
  -        }
  -        File parent = new File(jkF.getParent());
  -        if(!parent.exists()){
  -            if(!parent.mkdirs()){
  -                throw new RuntimeException(
  -                    "Unable to create path to config file :"+jkF.getAbsolutePath());
  -            }
  -        }
  -        return jkF;
  -    }
  -    
  +
       /**
           set a path to the workers.properties file.
           @param <b>path</b> String path to workers.properties file
       */
       public void setWorkersConfig(String path){
  -        setWorkersConfig(path==null?null:new File(path));
  -    }
  -    
  -    /**
  -        set a path to the workers.properties file.
  -        @param <b>path</b> a File object pointing to the
  -            workers.properties file.
  -    */
  -    public void setWorkersConfig(File path){
  -        workersConfig = path;
  -    }
  -    
  -    /**
  -        returns the path to the workers.properties file to be used
  -        by mod_jk.  If the path set with setWorkersConfig was relative,
  -        this method will try first to resolve it absolutely against
  -        the return value of getConfigHome().  If that is null, then
  -        it instead will resolve against the current user.dir.
  -        <p>
  -        @return a File object with the path to the workers.properties 
  -                file to be used by mod_jk.
  -    */
  -    public File getWorkersConfig(){
  -        if(workersConfig==null){
  -            workersConfig = new File(WORKERS_CONFIG);
  -        }
  -        File workersF = workersConfig;
  -        if(!workersF.isAbsolute()){
  -            if(getConfigHome()!=null){
  -                workersF = new File(getConfigHome(),workersF.getPath());
  -            }else{//resolve against user.dir
  -                workersF = new File(workersF.getAbsolutePath());
  -            }
  -        }
  -       return workersF;
  +        workersConfig= (path==null?null:new File(path));
       }
       
       /**
  -        set the path to the Jserv Apache Module
  -        @param <b>path</b> String path to a file
  -    */
  -    public void setModJserv(String path){
  -        setModJserv(path==null?null:new File(path));
  -    }
  -    
  -    /**
  -        set the path to the Jserv Apache Module
  -        @param <b>path</b> File object
  -    */
  -    public void setModJserv(File path){
  -        modJserv=path;
  -    }
  -
  -    /**
  -        returns the path to the apache module mod_jserv.  
  -        If the path set with setModJserv() was relative, this method 
  -        will try first to resolve it absolutely 
  -        against the return value of getConfigHome().  If that is null, then
  -        it instead will resolve against the current user.dir.
  -        If this file doesn't exist, the relative path is returned.
  -        <p>
  -        @return a File object with the path to the mod_jserv.so file.
  -    */
  -    public File getModJserv(){
  -        if(modJserv==null){
  -            modJserv=new File(MOD_JSERV);
  -        }
  -        File jservF = modJserv;
  -        if(!jservF.isAbsolute()){
  -            if(getConfigHome()!=null){
  -                jservF = new File(getConfigHome(),jservF.getPath());
  -            }else{//resolve against user.dir
  -                jservF = new File(jservF.getAbsolutePath());
  -            }
  -         if( !jservF.exists() )
  -             jservF = modJserv;
  -        }
  -       return jservF;
  -    }
  -    
  -    /**
           set the path to the mod_jk Apache Module
           @param <b>path</b> String path to a file
       */
       public void setModJk(String path){
  -        setModJk(path==null?null:new File(path));
  -    }
  -    
  -    /**
  -        set the path to the mod_jk Apache Module
  -        @param <b>path</b> File object
  -    */
  -    public void setModJk(File path){
  -        modJk=path;
  -    }
  -    
  -    /**
  -        returns the path to the apache module mod_jk.  
  -        If the path set with setModJk() was relative, this method 
  -        will try first to resolve it absolutely 
  -        against the return value of getConfigHome().  If that is null, then
  -        it instead will resolve against the current user.dir.
  -        If this file doesn't exist, the relative path is returned.
  -        <p>
  -        @return a File object with the path to the mod_jk.so file.
  -    */
  -    public File getModJk(){
  -        if(modJk==null){
  -            modJk=new File(MOD_JK);
  -        }
  -        File jkF = modJk;
  -        if(!jkF.isAbsolute()){
  -            if(getConfigHome()!=null){
  -                jkF = new File(getConfigHome(),jkF.getPath());
  -            }else{//resolve against user.dir
  -                jkF = new File(jkF.getAbsolutePath());
  -            }
  -         if( !jkF.exists() )
  -             jkF = modJk;
  -        }
  -       return jkF;
  +        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){
  -        setJkLog(path==null?null:new File(path));
  +        jkLog= ( path==null?null:new File(path));
       }
       
  -
       /**
  -        set the path to the mod_jk log file.
  -        @param <b>path</b> File object
  -    */
  -    public void setJkLog(File path){
  -        jkLog=path;
  -    }
  -    
  -    /**
  -        returns the path to the mod_jk log file.  
  -        If the path set with setJkLog() was relative, this method 
  -        will try first to resolve it absolutely 
  -        against the return value of getConfigHome().  If that is null, then
  -        it instead will resolve against the current user.dir.
  -        <p>
  -        @return a File object with the path to the mod_jk log file.
  -    */
  -    public File getJkLog(){
  -        if(jkLog==null){
  -            jkLog=new File(JK_LOG_LOCATION);
  -        }
  -        File logF = jkLog;
  -        if(!logF.isAbsolute()){
  -            if(getConfigHome()!=null){
  -                logF = new File(getConfigHome(),logF.getPath());
  -            }else{//resolve against user.dir
  -                logF = new File(logF.getAbsolutePath());
  -            }
  -        }
  -       return logF;
  -    }
  -    
  -    /**
           set the Ajp protocal
           @param <b>protocal</b> String protocol, "ajp12" or "ajp13"
        */
       public void setJkProtocol(String protocol){
  -        jkProtocol = -1;
  -        for( int i=0; i < JkMount.length; i++ ) {
  -            if( JkMount[i].equalsIgnoreCase(protocol) ) {
  -                jkProtocol = i;
  -                break;
  -            }
  -        }
  +        jkProto = protocol;
       }
   
  -    /**
  -        get the Ajp protocol
  -        @return a String for the Ajp protocol
  -     */
  -    public String getJkProtocol(){
  -        if( jkProtocol < 0 || jkProtocol >= JkMount.length )
  -            return JkMount[0];
  -        else
  -            return JkMount[jkProtocol];
  -    }
  +    // -------------------- Initialize/guess defaults --------------------
   
  +    /** Initialize defaults for properties that are not set
  +     explicitely
  +    */
  +    public void initProperties() {
  +     jkConfig=getConfigFile( jkConfig, configHome, MOD_JK_CONFIG+"-auto");
  +     workersConfig=getConfigFile( workersConfig, configHome,
  +                                  WORKERS_CONFIG);
  +     modJk=getConfigFile( modJk, configHome, MOD_JK );
  +     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 --------------------
  +    
       /**
           executes the ApacheConfig interceptor. This method generates apache
  -        configuration files for use with mod_jserv or mod_jk.  If not
  +        configuration files for use with  mod_jk.  If not
           already set, this method will setConfigHome() to the value returned
           from <i>cm.getHome()</i>.
           <p>
  @@ -583,139 +315,31 @@
       */
       public void execute(ContextManager cm) throws TomcatException {
        try {
  -         String tomcatHome = cm.getHome();
  +         initProperties();
  +         initProtocol(cm);
  +         
  +         tomcatHome = cm.getHome();
            File tomcatDir = new File(tomcatHome);
            
  -         if(getConfigHome()==null){
  -             setConfigHome(tomcatDir);
  +         if(configHome==null){
  +             configHome=tomcatDir;
            }
            
  -         //String apacheHome = findApache();
  -         int jkConnector = AJP12;
  -          if( jkProtocol >= 0 && jkProtocol < JkMount.length)
  -              jkConnector = jkProtocol;
  +         PrintWriter mod_jk = new PrintWriter(new FileWriter(jkConfig));
  +         log("Generating apache mod_jk config = "+jkConfig );
   
  -         PrintWriter pw=new PrintWriter(new FileWriter(getJservConfig()));
  -         log("Generating apache mod_jserv config = "+getJservConfig() );
  +         generateJkHead( mod_jk );
   
  -         PrintWriter mod_jk = new PrintWriter(new FileWriter(getJkConfig()));
  -         log("Generating apache mod_jk config = "+getJkConfig() );
  +         // XXX Make those options configurable in server.xml
  +         generateSSLConfig( mod_jk );
   
   
  -            
mod_jk.println("###################################################################");
  -            mod_jk.println("# Auto generated configuration. Dated: " +  new Date());
  -            
mod_jk.println("###################################################################");
  -            mod_jk.println();
  -            
  -            mod_jk.println("#");
  -            mod_jk.println("# The following lines instruct Apache to load the jk 
module");
  -            mod_jk.println("# if it has not already been loaded.  This script 
assumes");
  -            mod_jk.println("# that the module is in the path below.  If you need to 
");
  -            mod_jk.println("# deploy the module in another location, be sure to use 
a  ");
  -            mod_jk.println("# LoadModule statement prior to Include'ing this conf 
file.");
  -            mod_jk.println("# For example:");
  -            mod_jk.println("# ");
  -            mod_jk.println("#   LoadModule jk_module 
d:/mypath/modules/win32/mod_jk.dll");
  -            mod_jk.println("# or");
  -            mod_jk.println("#   LoadModule jk_module 
/mypath/modules/linux/mod_jk.so");
  -            mod_jk.println("#");
  -            
  -            //insert LoadModule calls:
  -            pw.println("<IfModule !mod_jserv.c>");
  -            pw.println("  LoadModule jserv_module "+
  -                     getModJserv().toString().replace('\\','/'));
  -            pw.println("</IfModule>");
  -
  -            mod_jk.println("<IfModule !mod_jk.c>");
  -            mod_jk.println("  LoadModule jk_module "+
  -                         getModJk().toString().replace('\\','/'));
  -            mod_jk.println("</IfModule>");
  -            mod_jk.println();                
  -            mod_jk.println("JkWorkersFile \"" 
  -             + getWorkersConfig().toString().replace('\\', '/') 
  -             + "\"");
  -            mod_jk.println("JkLogFile \"" 
  -             + getJkLog().toString().replace('\\', '/') 
  -             + "\"");
  -
  -         pw.println("ApJServManual on");
  -         pw.println("ApJServDefaultProtocol " + AJPV12);
  -         pw.println("ApJServSecretKey DISABLED");
  -         pw.println("ApJServMountCopy on");
  -         pw.println("ApJServLogLevel notice");
  -         pw.println();
  -
  -         // Find Ajp1? connectors
  -         int portInt=8007;
  -         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
  -                if( jkProtocol < 0 &&
  -                        ( con instanceof  Ajp13Interceptor ||
  -                            ( jtcAjp13 != null && jtcAjp13.isInstance(con) ) ) ) {
  -                         jkConnector = AJP13;
  -                 }
  -         }
  -         pw.println("ApJServDefaultPort " + portInt);
  -         pw.println();
  -
  -         pw.println("AddType text/jsp .jsp");
  -         pw.println("AddHandler jserv-servlet .jsp");
  -         pw.println();
  -
  -            mod_jk.println();
  -            mod_jk.println("#");        
  -            mod_jk.println("# Log level to be used by mod_jk");
  -            mod_jk.println("#");        
  -            mod_jk.println("JkLogLevel error");
  -         mod_jk.println();
  -
  -            
mod_jk.println("###################################################################");
  -            mod_jk.println("#                     SSL configuration                 
          #");
  -            mod_jk.println("# ");                
  -            mod_jk.println("# By default mod_jk is configured to collect SSL 
information from");
  -            mod_jk.println("# the apache environment and send it to the Tomcat 
workers. The");
  -            mod_jk.println("# problem is that there are many SSL solutions for 
Apache and as");
  -            mod_jk.println("# a result the environment variable names may change.");
  -            mod_jk.println("#");        
  -            mod_jk.println("# The following (commented out) JK related SSL 
configureation");        
  -            mod_jk.println("# can be used to customize mod_jk's SSL behaviour.");   
     
  -            mod_jk.println("# ");        
  -            mod_jk.println("# Should mod_jk send SSL information to Tomact (default 
is On)");        
  -            mod_jk.println("# JkExtractSSL Off");        
  -            mod_jk.println("# ");        
  -            mod_jk.println("# What is the indicator for SSL (default is HTTPS)");   
     
  -            mod_jk.println("# JkHTTPSIndicator HTTPS");        
  -            mod_jk.println("# ");        
  -            mod_jk.println("# What is the indicator for SSL session (default is 
SSL_SESSION_ID)");        
  -            mod_jk.println("# JkSESSIONIndicator SSL_SESSION_ID");        
  -            mod_jk.println("# ");        
  -            mod_jk.println("# What is the indicator for client SSL cipher suit 
(default is SSL_CIPHER)");        
  -            mod_jk.println("# JkCIPHERIndicator SSL_CIPHER");
  -            mod_jk.println("# ");        
  -            mod_jk.println("# What is the indicator for the client SSL certificated 
(default is SSL_CLIENT_CERT)");        
  -            mod_jk.println("# JkCERTSIndicator SSL_CLIENT_CERT");
  -            mod_jk.println("# ");        
  -            mod_jk.println("#                                                       
          #");        
  -            
mod_jk.println("###################################################################");
  -            mod_jk.println();
  -
  -
  -            mod_jk.println("#");        
  +            // XXX
  +         mod_jk.println("#");        
               mod_jk.println("# Root context mounts for Tomcat");
               mod_jk.println("#");        
  -            mod_jk.println("JkMount /*.jsp " + JkMount[jkConnector]);
  -            mod_jk.println("JkMount /servlet/* " + JkMount[jkConnector]);
  +            mod_jk.println("JkMount /*.jsp " + jkProto);
  +            mod_jk.println("JkMount /servlet/* " + jkProto);
               mod_jk.println();
   
            // Set up contexts
  @@ -723,169 +347,221 @@
            Enumeration  enum = cm.getContexts();
            while (enum.hasMoreElements()) {
                   Context context = (Context)enum.nextElement();
  -                String path  = context.getPath();
  -                String vhost = context.getHost();
  -
  -                if( vhost != null ) {
  -                    // Generate Apache VirtualHost section for this host
  -                    // You'll have to do it manually right now
  -                    // XXX
  -                    continue;
  -                }
  -                if( path.length() > 1) {
  -
  -                    // It's not the root context
  -                    // assert path.startsWith( "/" )
  -
  -                    // Calculate the absolute path of the document base
  -                    String docBase = context.getDocBase();
  -                    if (!FileUtil.isAbsolute(docBase)){
  -                         docBase = tomcatHome + "/" + docBase;
  -                    }
  -                    docBase = FileUtil.patch(docBase);
  -                     if (File.separatorChar == '\\')
  -                             docBase = docBase.replace('\\','/');// use separator 
preferred by Apache
  -
  -                    // Static files will be served by Apache
  -                    pw.println("Alias " + path + " \"" + docBase + "\"");
  -                    pw.println("<Directory \"" + docBase + "\">");
  -                    pw.println("    Options Indexes FollowSymLinks");
  -                    pw.println("</Directory>");
  -
  -                    // Dynamic /servet pages go to Tomcat
  -                    pw.println("ApJServMount " + path +"/servlet" + " " + path);
  -
  -                    // Deny serving any files from WEB-INF
  -                    pw.println("<Location \"" + path + "/WEB-INF/\">");
  -                    pw.println("    AllowOverride None");
  -                    pw.println("    deny from all");
  -                    pw.println("</Location>");
  -                     // For Windows, use Directory too. Location doesn't work 
unless case matches
  -                     if (File.separatorChar == '\\') {
  -                             pw.println("<Directory \"" + docBase + "/WEB-INF/\">");
  -                             pw.println("    AllowOverride None");
  -                             pw.println("    deny from all");
  -                             pw.println("</Directory>");
  -                     }
  -
  -                    // Deny serving any files from META-INF
  -                     pw.println("<Location \"" + path + "/META-INF/\">");
  -                     pw.println("    AllowOverride None");
  -                     pw.println("    deny from all");
  -                     pw.println("</Location>");
  -                     // For Windows, use Directory too. Location doesn't work 
unless case matches
  -                     if (File.separatorChar  == '\\') {
  -                             pw.println("<Directory \"" + docBase + 
"/META-INF/\">");
  -                             pw.println("    AllowOverride None");
  -                             pw.println("    deny from all");
  -                             pw.println("</Directory>");
  -                     }
  -                    pw.println();
  -
  -
  -                    // Static files will be served by Apache
  -                    
mod_jk.println("#########################################################");           
      
  -                    mod_jk.println("# Auto configuration for the " + path + " 
context starts.");
  -                    
mod_jk.println("#########################################################");           
      
  -                    mod_jk.println();
  -
  -                    mod_jk.println("#");                 
  -                    mod_jk.println("# The following line makes apache aware of the 
location of the " + path + " context");
  -                    mod_jk.println("#");                        
  -                    mod_jk.println("Alias " + path + " \"" + docBase + "\"");
  -                    mod_jk.println("<Directory \"" + docBase + "\">");
  -                    mod_jk.println("    Options Indexes FollowSymLinks");
  -                    mod_jk.println("</Directory>");
  -                    mod_jk.println();            
  -
  -                    // Dynamic /servet pages go to Tomcat
  -                    mod_jk.println("#");                 
  -                    mod_jk.println("# The following line mounts all JSP files and 
the /servlet/ uri to tomcat");
  -                    mod_jk.println("#");                        
  -                    mod_jk.println("JkMount " + path +"/servlet/* " + 
JkMount[jkConnector]);
  -                    mod_jk.println("JkMount " + path +"/*.jsp " + 
JkMount[jkConnector]);
  -                 mod_jk.println("# The following line mounts the " +
  -                                "form-based authenticator for the "+
  -                                path+" context");
  -                 mod_jk.println("#");
  -                 mod_jk.println("JkMount " + path +
  -                                "/*j_security_check " +
  -                                JkMount[jkConnector]);
  -
  -
  -
  -                    // Deny serving any files from WEB-INF
  -                    mod_jk.println();            
  -                    mod_jk.println("#");                 
  -                    mod_jk.println("# The following line prohibits users from 
directly accessing WEB-INF");
  -                    mod_jk.println("#");                        
  -                    mod_jk.println("<Location \"" + path + "/WEB-INF/\">");
  -                    mod_jk.println("    AllowOverride None");
  -                    mod_jk.println("    deny from all");
  -                    mod_jk.println("</Location>");
  -                     if (File.separatorChar == '\\') {
  -                             mod_jk.println("#");                
  -                             mod_jk.println("# Use Directory too. On Windows, 
Location doesn't work unless case matches");
  -                             mod_jk.println("#");                        
  -                             mod_jk.println("<Directory \"" + docBase + 
"/WEB-INF/\">");
  -                             mod_jk.println("    AllowOverride None");
  -                             mod_jk.println("    deny from all");
  -                             mod_jk.println("</Directory>");
  -                     }
  -
  -                     // Deny serving any files from META-INF
  -                    mod_jk.println();            
  -                    mod_jk.println("#");                 
  -                    mod_jk.println("# The following line prohibits users from 
directly accessing META-INF");
  -                    mod_jk.println("#");                        
  -                     mod_jk.println("<Location \"" + path + "/META-INF/\">");
  -                     mod_jk.println("    AllowOverride None");
  -                     mod_jk.println("    deny from all");
  -                     mod_jk.println("</Location>");
  -                     if (File.separatorChar == '\\') {
  -                             mod_jk.println("#");                
  -                             mod_jk.println("# Use Directory too. On Windows, 
Location doesn't work unless case matches");
  -                             mod_jk.println("#");                        
  -                             mod_jk.println("<Directory \"" + docBase + 
"/META-INF/\">");
  -                             mod_jk.println("    AllowOverride None");
  -                             mod_jk.println("    deny from all");
  -                             mod_jk.println("</Directory>");
  -                     }
  -                    mod_jk.println();
  -
  -                    
mod_jk.println("#######################################################");             
      
  -                    mod_jk.println("# Auto configuration for the " + path + " 
context ends.");
  -                    
mod_jk.println("#######################################################");             
      
  -                    mod_jk.println();
  -
  -                    // XXX check security
  -                    if( false ) {
  -                     pw.println("<Location " + path + "/servlet/ >");
  -                     pw.println("    AllowOverride None");
  -                     pw.println("   AuthName \"restricted \"");
  -                     pw.println("    AuthType Basic");
  -                     pw.println("    AuthUserFile conf/users");
  -                     pw.println("    require valid-user");
  -                     pw.println("</Location>");
  -                    }
  -
  -                   // XXX ErrorDocument
  -
  -                    // XXX mime types - AddEncoding, AddLanguage, TypesConfig
  -                } else {
  -                    // the root context
  -                    // XXX use a non-conflicting name
  -                    pw.println("ApJServMount /servlet /ROOT");
  -                }
  -
  -         }//end while(enum)
  +             generateContextMappings( context, mod_jk );
  +         }
   
  -         pw.close();
            mod_jk.close();        
        } catch( Exception ex ) {
               Log loghelper = Log.getLog("tc_log", this);
            loghelper.log("Error generating automatic apache configuration", ex);
        }
       }//end execute()
  -    
  +
  +    // -------------------- Config sections  --------------------
  +
  +    /** Generate the loadModule and general options
  +     */
  +    private void generateJkHead(PrintWriter mod_jk) {
  +     
mod_jk.println("###################################################################");
  +     mod_jk.println("# Auto generated configuration. Dated: " +  new Date());
  +     
mod_jk.println("###################################################################");
  +     mod_jk.println();
  +     
  +     mod_jk.println("#");
  +     mod_jk.println("# The following lines instruct Apache to load the jk module");
  +     mod_jk.println("# if it has not already been loaded.  This script assumes");
  +     mod_jk.println("# that the module is in the path below.  If you need to ");
  +     mod_jk.println("# deploy the module in another location, be sure to use a  ");
  +     mod_jk.println("# LoadModule statement prior to Include'ing this conf file.");
  +     mod_jk.println("# For example:");
  +     mod_jk.println("# ");
  +     mod_jk.println("#   LoadModule jk_module d:/mypath/modules/win32/mod_jk.dll");
  +     mod_jk.println("# or");
  +     mod_jk.println("#   LoadModule jk_module /mypath/modules/linux/mod_jk.so");
  +     mod_jk.println("#");
  +            
  +     // Verify the file exists !!
  +     mod_jk.println("<IfModule !mod_jk.c>");
  +     mod_jk.println("  LoadModule jk_module "+
  +                    modJk.toString().replace('\\','/'));
  +     mod_jk.println("</IfModule>");
  +     mod_jk.println();                
  +     mod_jk.println("JkWorkersFile \"" 
  +                    + workersConfig.toString().replace('\\', '/') 
  +                    + "\"");
  +     mod_jk.println("JkLogFile \"" 
  +                    + jkLog.toString().replace('\\', '/') 
  +                    + "\"");
  +     mod_jk.println();
  +     mod_jk.println("#");        
  +     mod_jk.println("# Log level to be used by mod_jk");
  +     mod_jk.println("#");
  +
  +     // XXX Make it configurable 
  +     mod_jk.println("JkLogLevel error");
  +     mod_jk.println();
  +
  +    }
  +
  +    private void generateSSLConfig(PrintWriter mod_jk) {
  +     
mod_jk.println("###################################################################");
  +     mod_jk.println("#                     SSL configuration                        
   #");
  +     mod_jk.println("# ");                
  +     mod_jk.println("# By default mod_jk is configured to collect SSL information 
from");
  +     mod_jk.println("# the apache environment and send it to the Tomcat workers. 
The");
  +     mod_jk.println("# problem is that there are many SSL solutions for Apache and 
as");
  +     mod_jk.println("# a result the environment variable names may change.");
  +     mod_jk.println("#");        
  +     mod_jk.println("# The following (commented out) JK related SSL 
configureation");        
  +     mod_jk.println("# can be used to customize mod_jk's SSL behaviour.");        
  +     mod_jk.println("# ");        
  +     mod_jk.println("# Should mod_jk send SSL information to Tomact (default is 
On)");        
  +     mod_jk.println("# JkExtractSSL Off");        
  +     mod_jk.println("# ");        
  +     mod_jk.println("# What is the indicator for SSL (default is HTTPS)");        
  +     mod_jk.println("# JkHTTPSIndicator HTTPS");        
  +     mod_jk.println("# ");        
  +     mod_jk.println("# What is the indicator for SSL session (default is 
SSL_SESSION_ID)");        
  +     mod_jk.println("# JkSESSIONIndicator SSL_SESSION_ID");        
  +     mod_jk.println("# ");        
  +     mod_jk.println("# What is the indicator for client SSL cipher suit (default is 
SSL_CIPHER)");        
  +     mod_jk.println("# JkCIPHERIndicator SSL_CIPHER");
  +     mod_jk.println("# ");        
  +     mod_jk.println("# What is the indicator for the client SSL 
certificated(default is SSL_CLIENT_CERT)");        
  +     mod_jk.println("# JkCERTSIndicator SSL_CLIENT_CERT");
  +     mod_jk.println("# ");        
  +     mod_jk.println("#                                                              
   #");        
  +     
mod_jk.println("###################################################################");
  +     mod_jk.println();
  +    }
  +
  +    private void generateContextMappings(Context context, PrintWriter mod_jk ) {
  +     String path  = context.getPath();
  +     String vhost = context.getHost();
  +     
  +     if( vhost != null ) {
  +         // Generate Apache VirtualHost section for this host
  +         // You'll have to do it manually right now
  +         // XXX
  +         return;
  +     }
  +     if( path.length() > 1) {
  +         
  +         // It's not the root context
  +         // assert path.startsWith( "/" )
  +         
  +         // Calculate the absolute path of the document base
  +         String docBase = context.getDocBase();
  +         if (!FileUtil.isAbsolute(docBase)){
  +             docBase = tomcatHome + "/" + docBase;
  +         }
  +         docBase = FileUtil.patch(docBase);
  +         if (File.separatorChar == '\\')
  +             docBase = docBase.replace('\\','/');// use separator preferred by 
Apache
  +         
  +         // Static files will be served by Apache
  +         
mod_jk.println("#########################################################");           
         
  +         mod_jk.println("# Auto configuration for the " + path + " context 
starts.");
  +         
mod_jk.println("#########################################################");           
         
  +         mod_jk.println();
  +         
  +         mod_jk.println("#");                    
  +         mod_jk.println("# The following line makes apache aware of the location of 
the " + path + " context");
  +         mod_jk.println("#");                        
  +         mod_jk.println("Alias " + path + " \"" + docBase + "\"");
  +         mod_jk.println("<Directory \"" + docBase + "\">");
  +         mod_jk.println("    Options Indexes FollowSymLinks");
  +         mod_jk.println("</Directory>");
  +         mod_jk.println();            
  +         
  +         // Dynamic /servet pages go to Tomcat
  +         mod_jk.println("#");                    
  +         mod_jk.println("# The following line mounts all JSP files and the 
/servlet/ uri to tomcat");
  +         mod_jk.println("#");                        
  +         mod_jk.println("JkMount " + path +"/servlet/* " + jkProto);
  +         mod_jk.println("JkMount " + path +"/*.jsp " + jkProto);
  +         mod_jk.println("# The following line mounts the " +
  +                        "form-based authenticator for the "+
  +                        path+" context");
  +         mod_jk.println("#");
  +         mod_jk.println("JkMount " + path + "/*j_security_check " + jkProto);
  +         
  +         
  +         
  +         // Deny serving any files from WEB-INF
  +         mod_jk.println();            
  +         mod_jk.println("#");                    
  +         mod_jk.println("# The following line prohibits users from directly 
accessing WEB-INF");
  +         mod_jk.println("#");                        
  +         mod_jk.println("<Location \"" + path + "/WEB-INF/\">");
  +         mod_jk.println("    AllowOverride None");
  +         mod_jk.println("    deny from all");
  +         mod_jk.println("</Location>");
  +         if (File.separatorChar == '\\') {
  +             mod_jk.println("#");                
  +             mod_jk.println("# Use Directory too. On Windows, Location doesn't work 
unless case matches");
  +             mod_jk.println("#");                        
  +             mod_jk.println("<Directory \"" + docBase + "/WEB-INF/\">");
  +             mod_jk.println("    AllowOverride None");
  +             mod_jk.println("    deny from all");
  +             mod_jk.println("</Directory>");
  +         }
  +         
  +         // Deny serving any files from META-INF
  +         mod_jk.println();            
  +         mod_jk.println("#");                    
  +         mod_jk.println("# The following line prohibits users from directly 
accessing META-INF");
  +         mod_jk.println("#");                        
  +         mod_jk.println("<Location \"" + path + "/META-INF/\">");
  +         mod_jk.println("    AllowOverride None");
  +         mod_jk.println("    deny from all");
  +         mod_jk.println("</Location>");
  +         if (File.separatorChar == '\\') {
  +             mod_jk.println("#");                
  +             mod_jk.println("# Use Directory too. On Windows, Location doesn't work 
unless case matches");
  +             mod_jk.println("#");                        
  +             mod_jk.println("<Directory \"" + docBase + "/META-INF/\">");
  +             mod_jk.println("    AllowOverride None");
  +             mod_jk.println("    deny from all");
  +             mod_jk.println("</Directory>");
  +         }
  +         mod_jk.println();
  +         
  +         mod_jk.println("#######################################################"); 
             
  +         mod_jk.println("# Auto configuration for the " + path + " context ends.");
  +         mod_jk.println("#######################################################"); 
             
  +         mod_jk.println();
  +         
  +         
  +         // XXX ErrorDocument
  +         
  +         // XXX mime types - AddEncoding, AddLanguage, TypesConfig
  +     } else {
  +         // the root context
  +         // XXX use a non-conflicting name
  +     }
  +    }    
  +
  +    // -------------------- Utils --------------------
  +
  +    private 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 
:"+jkConfig.getAbsolutePath());
  +            }
  +        }
  +     return base;
  +    }
  +
   }//end class ApacheConfig
  
  
  

Reply via email to