tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lar...@apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/config ApacheConfig.java BaseJkConfig.java IISConfig.java
Date Fri, 10 Aug 2001 20:55:38 GMT
larryi      01/08/10 13:55:38

  Modified:    src/share/org/apache/tomcat/modules/config ApacheConfig.java
                        BaseJkConfig.java IISConfig.java
  Log:
  More refactoring.  Handle forwardAll and noRoot in IISConfig.  Still
  needs some debugging.
  
  Revision  Changes    Path
  1.22      +12 -27    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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ApacheConfig.java	2001/08/10 03:57:07	1.21
  +++ ApacheConfig.java	2001/08/10 20:55:38	1.22
  @@ -1,4 +1,4 @@
  -/* $Id: ApacheConfig.java,v 1.21 2001/08/10 03:57:07 larryi Exp $
  +/* $Id: ApacheConfig.java,v 1.22 2001/08/10 20:55:38 larryi Exp $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -146,7 +146,7 @@
       @author Costin Manolache
       @author Larry Isaacs
       @author Mel Martinez
  -	@version $Revision: 1.21 $ $Date: 2001/08/10 03:57:07 $
  +	@version $Revision: 1.22 $ $Date: 2001/08/10 20:55:38 $
    */
   public class ApacheConfig  extends BaseJkConfig { 
       
  @@ -417,7 +417,7 @@
       /** Forward all requests for a context to tomcat.
   	The default.
        */
  -    private boolean generateStupidMappings(Context context,
  +    private void generateStupidMappings(Context context,
   					   PrintWriter mod_jk )
       {
   	String ctxPath  = context.getPath();
  @@ -426,7 +426,7 @@
   	
           if( noRoot &&  "".equals(ctxPath) ) {
               log("Ignoring root context in forward-all mode  ");
  -            return true;
  +            return;
           } 
   	if( vhost != null ) {
   	    generateNameVirtualHost(mod_jk );
  @@ -455,7 +455,6 @@
   	    mod_jk.println("</VirtualHost>");
   	    indent="";
   	}
  -	return true;
       }    
   
       
  @@ -527,37 +526,23 @@
   	    indent="";
   	}
       }
  -
  -    private boolean addMapping( Context ctx, Container ct,
  -				PrintWriter mod_jk )
  -    {
  -	int type=ct.getMapType();
  -	String ctPath=ct.getPath();
  -	String ctxPath=ctx.getPath();
  -
  -	if( type==Container.EXTENSION_MAP ) {
  -	    if( ctPath.length() < 3 ) return false;
  -	    String ext=ctPath.substring( 2 );
  -	    return addExtensionMapping( ctxPath, ext , mod_jk );
  -	}
  -	String fullPath=null;
  -	if( ctPath.startsWith("/" ))
  -	    fullPath=ctxPath+ ctPath;
  -	else
  -	    fullPath=ctxPath + "/" + ctPath;
  -	return addMapping( fullPath, mod_jk);
  -    }
   
  -    private boolean addExtensionMapping( String ctxPath, String ext,
  +    /** Add an Apache extension mapping.
  +     */
  +    protected boolean addExtensionMapping( String ctxPath, String ext,
   					 PrintWriter mod_jk )
       {
  +        if( debug > 0 )
  +            log( "Adding extension map for " + ctxPath + "/*." + ext );
   	mod_jk.println(indent + "JkMount " + ctxPath + "/*." + ext
   		       + " " + jkProto);
   	return true;
       }
       
       
  -    private boolean addMapping( String fullPath, PrintWriter mod_jk ) {
  +    /** Add a fulling specified Appache mapping.
  +     */
  +    protected boolean addMapping( String fullPath, PrintWriter mod_jk ) {
           if( debug > 0 )
               log( "Adding map for " + fullPath );
   	mod_jk.println(indent + "JkMount " + fullPath + "  " + jkProto );
  
  
  
  1.2       +44 -5     jakarta-tomcat/src/share/org/apache/tomcat/modules/config/BaseJkConfig.java
  
  Index: BaseJkConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/BaseJkConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseJkConfig.java	2001/08/10 03:57:07	1.1
  +++ BaseJkConfig.java	2001/08/10 20:55:38	1.2
  @@ -1,4 +1,4 @@
  -/* $Id: BaseJkConfig.java,v 1.1 2001/08/10 03:57:07 larryi Exp $
  +/* $Id: BaseJkConfig.java,v 1.2 2001/08/10 20:55:38 larryi Exp $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -117,7 +117,7 @@
       <p>
       @author Costin Manolache
       @author Larry Isaacs
  -	@version $Revision: 1.1 $
  +	@version $Revision: 1.2 $
    */
   public class BaseJkConfig  extends BaseInterceptor { 
       protected File configHome = null;
  @@ -192,14 +192,14 @@
       }
   
       /**
  -        set the path to the mod_jk log file
  +        set the path to the 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.
  +    /** Set the verbosity level
           ( use debug, error, etc. ) If not set, no log is written.
        */
       public void setJkDebug( String level ) {
  @@ -243,7 +243,46 @@
   	if( jkProto==null ) jkProto="ajp12";
       }
   
  -    // -------------------- Utils --------------------
  +    // -------------------- Config Utils  --------------------
  +
  +    protected boolean addMapping( Context ctx, Container ct,
  +				PrintWriter pw )
  +    {
  +	int type=ct.getMapType();
  +	String ctPath=ct.getPath();
  +	String ctxPath=ctx.getPath();
  +
  +	if( type==Container.EXTENSION_MAP ) {
  +	    if( ctPath.length() < 3 ) return false;
  +	    String ext=ctPath.substring( 2 );
  +	    return addExtensionMapping( ctxPath, ext , pw );
  +	}
  +	String fullPath=null;
  +	if( ctPath.startsWith("/" ))
  +	    fullPath=ctxPath+ ctPath;
  +	else
  +	    fullPath=ctxPath + "/" + ctPath;
  +	return addMapping( fullPath, pw);
  +    }
  +
  +    /** Add an extension mapping. Override with method to generate
  +        web server specific configuration
  +     */
  +    protected boolean addExtensionMapping( String ctxPath, String ext,
  +					 PrintWriter pw )
  +    {
  +	return true;
  +    }
  +    
  +    
  +    /** Add a fulling specified mapping.  Override with method to generate
  +        web server specific configuration
  +     */
  +    protected boolean addMapping( String fullPath, PrintWriter pw ) {
  +	return true;
  +    }
  +
  +    // -------------------- General Utils --------------------
   
       protected File getConfigFile( File base, File configDir, String defaultF )
       {
  
  
  
  1.6       +161 -86   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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- IISConfig.java	2001/08/10 03:57:07	1.5
  +++ IISConfig.java	2001/08/10 20:55:38	1.6
  @@ -59,7 +59,8 @@
   package org.apache.tomcat.modules.config;
   
   import org.apache.tomcat.core.*;
  -import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.io.FileUtil;
  +//import org.apache.tomcat.util.*;
   import org.apache.tomcat.util.log.*;
   import java.io.*;
   import java.util.*;
  @@ -127,20 +128,18 @@
       @author Costin Manolache
       @author Larry Isaacs
       @author Gal Shachor
  -	@version $Revision: 1.5 $
  +	@version $Revision: 1.6 $
    */
   public class IISConfig extends BaseJkConfig  { 
   
       public static final String WORKERS_CONFIG = "/conf/jk/workers.properties";
       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";    
  +    public static final String ISAPI_LOG_LOCATION = "/logs/iis_redirect.log";
  +    public static final String ISAPI_REG_FILE = "/conf/auto/iis_redirect.reg";    
   
       private File regConfig = null;
       private File uriConfig = null;
   
  -    Log loghelper = Log.getLog("tc_log", "IISConfig");
  -
       public IISConfig() 
       {
       }
  @@ -204,91 +203,155 @@
   
               PrintWriter regfile = new PrintWriter(new FileWriter(regConfig));
               PrintWriter uri_worker = new PrintWriter(new FileWriter(uriConfig));      
 
  +
  +            generateRegistrySettings(regfile);
  +
  +            generateUriWorkerHeader(uri_worker);            
  +
  +            // Set up contexts
  +            // XXX deal with Virtual host configuration !!!!
  +            Enumeration enum = cm.getContexts();
  +            while (enum.hasMoreElements()) {
  +                Context context = (Context)enum.nextElement();
  +
  +                String vhost = context.getHost();
  +                if(vhost != null) {
  +                    // Vhosts are not supported yet for IIS
  +                    continue;
  +                }
  +
  +		if( forwardAll )
  +		    generateStupidMappings( context, uri_worker );
  +		else
  +		    generateContextMappings( context, uri_worker );
  +            }
  +
  +            regfile.close();
  +            uri_worker.close();
  +
  +        } catch(Exception ex) {
  +            Log loghelper = Log.getLog("tc_log", this);
  +            loghelper.log("Error generating automatic IIS configuration", ex);
  +        }
  +    }
  +
  +    // -------------------- Config sections  --------------------
  +
  +    /** Writes the registry settings required by the IIS connector
  +     */
  +    private void generateRegistrySettings(PrintWriter regfile)
  +    {
  +        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(jkLog.toString()) +"\"");
  +        regfile.println("\"log_level\"=\"" + jkDebug + "\"");
  +        regfile.println("\"worker_file\"=\"" + dubleSlash(workersConfig.toString()) +"\"");
  +        regfile.println("\"worker_mount_file\"=\"" + dubleSlash(uriConfig.toString()) +"\"");
  +    }
  +
  +    /** Writes the header information to the uriworkermap file
  +     */
  +    private void generateUriWorkerHeader(PrintWriter uri_worker)
  +    {
  +        uri_worker.println("###################################################################");
	    
  +        uri_worker.println("# Auto generated configuration. Dated: " +  new Date());
  +        uri_worker.println("###################################################################");
	    
  +        uri_worker.println();
  +
  +        uri_worker.println("#");        
  +        uri_worker.println("# Default worker to be used through our mappings");
  +        uri_worker.println("#");        
  +        uri_worker.println("default.worker=" + jkProto);        
  +        uri_worker.println();
  +    }
  +
  +    /** Forward all requests for a context to tomcat.
  +	The default.
  +     */
  +    private void generateStupidMappings(Context context, PrintWriter uri_worker )
  +    {
  +        String ctxPath  = context.getPath();
  +	String nPath=("".equals(ctxPath)) ? "/" : ctxPath;
   
  -            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(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("###################################################################");
	    
  -            uri_worker.println("# Auto generated configuration. Dated: " +  new Date());
  -            uri_worker.println("###################################################################");
	    
  -            uri_worker.println();
  -
  -            uri_worker.println("#");        
  -            uri_worker.println("# Default worker to be used through our mappings");
  -            uri_worker.println("#");        
  -            uri_worker.println("default.worker=" + jkProto);        
  -            uri_worker.println();
  -            
  -            uri_worker.println("#");                    
  -            uri_worker.println("# Root context mounts for Tomcat");
  -            uri_worker.println("#");        
  -		    uri_worker.println("/servlet/*=$(default.worker)");
  -		    uri_worker.println("/*.jsp=$(default.worker)");
  -            uri_worker.println();            
  -
  -
  -	        // Set up contexts
  -	        // XXX deal with Virtual host configuration !!!!
  -	        Enumeration enum = cm.getContexts();
  -	        while (enum.hasMoreElements()) {
  -		        Context context = (Context)enum.nextElement();
  -		        String path  = context.getPath();
  -		        String vhost = context.getHost();
  -
  -		        if(vhost != null) {
  -		            // Vhosts are not supported yet for IIS
  -		            continue;
  -		        }
  -		        if(path.length() > 1) {
  -                    // Static files will be served by IIS
  -                    uri_worker.println("#########################################################");
	    
  -                    uri_worker.println("# Auto configuration for the " + path + " context
starts.");
  -                    uri_worker.println("#########################################################");
	    
  -                    uri_worker.println();
  -            
  -
  -                    uri_worker.println("#");		    
  -                    uri_worker.println("# The following line mounts all JSP file and the
/servlet/ uri to tomcat");
  -                    uri_worker.println("#");                        
  -		            uri_worker.println(path +"/servlet/*=$(default.worker)");
  -		            uri_worker.println(path +"/*.jsp=$(default.worker)");
  -                    uri_worker.println();            
  -
  -                    uri_worker.println("#");		    
  -                    uri_worker.println("# The following line specifies that tomcat should
serve all the resources");
  -                    uri_worker.println("# (including static) that are port of the " + path
+ " context.  This insures");
  -                    uri_worker.println("# that behavior specified in the web.xml functions
correctly.  If you want");
  -                    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("#######################################################");
	    
  -                    uri_worker.println("# Auto configuration for the " + path + " context
ends.");
  -                    uri_worker.println("#######################################################");
	    
  -                    uri_worker.println();
  -		        }
  -	        }
  -
  -	        regfile.close();
  -	        uri_worker.close();
  -	        
  -	    } catch(Exception ex) {
  -	        loghelper.log("Error generating automatic IIS configuration", ex);
  -	    }
  +        if( noRoot &&  "".equals(ctxPath) ) {
  +            log("Ignoring root context in forward-all mode  ");
  +            return;
  +        } 
  +
  +        // map all requests for this context to Tomcat
  +        uri_worker.println(nPath +"=$(default.worker)");
  +        if( "".equals(ctxPath) ) {
  +            uri_worker.println(nPath +"*=$(default.worker)");
  +            uri_worker.println(
  +                    "# Note: To correctly serve the Tomcat's root context, IIS's Home Directory
must");
  +            uri_worker.println(
  +                    "# must be set to: \"" + getAbsoluteDocBase(context) + "\"");
  +        }
  +        else
  +            uri_worker.println(nPath +"/*=$(default.worker)");
       }
   
  +    private void generateContextMappings(Context context, PrintWriter uri_worker )
  +    {
  +        String ctxPath  = context.getPath();
  +	String nPath=("".equals(ctxPath)) ? "/" : ctxPath;
  +
  +        if( noRoot &&  "".equals(ctxPath) ) {
  +            log("Ignoring root context in forward-all mode  ");
  +            return;
  +        } 
  +
  +        // Static files will be served by IIS
  +        uri_worker.println();
  +        uri_worker.println("#########################################################");
	    
  +        uri_worker.println("# Auto configuration for the " + nPath + " context.");
  +        uri_worker.println("#########################################################");
	    
  +        uri_worker.println();
  +
  +        // Static mappings are not set in uriworkermap, but must be set with IIS admin.
  +
  +	// InvokerInterceptor - it doesn't have a container,
  +	// but it's implemented using a special module.
  +
  +	// XXX we need to better collect all mappings
  +	addMapping( ctxPath + "/servlet/*", uri_worker );
  +
  +	Enumeration servletMaps=context.getContainers();
  +	while( servletMaps.hasMoreElements() ) {
  +	    Container ct=(Container)servletMaps.nextElement();
  +	    addMapping( context, ct , uri_worker );
  +	}
  +
  +	// XXX ErrorDocument
  +	// Security and filter mappings
  +
  +    }
  +
  +    /** Add an IIS extension mapping.
  +     */
  +    protected boolean addExtensionMapping( String ctxPath, String ext,
  +					 PrintWriter uri_worker )
  +    {
  +        if( debug > 0 )
  +            log( "Adding extension map for " + ctxPath + "/*." + ext );
  +	uri_worker.println(ctxPath + "/*." + ext + " " + jkProto);
  +        return true;
  +    }
  +
  +    /** Add a fulling specified IIS mapping.
  +     */
  +    protected boolean addMapping( String fullPath, PrintWriter uri_worker ) {
  +        if( debug > 0 )
  +            log( "Adding map for " + fullPath );
  +        uri_worker.println(fullPath + "=$(default.worker)" );
  +        return true;
  +    }
  +
       // -------------------- Utils --------------------
   
  -    protected String dubleSlash(String in) 
  +    private String dubleSlash(String in) 
       {
           StringBuffer sb = new StringBuffer();
           
  @@ -303,4 +366,16 @@
           
           return sb.toString();
       }
  +
  +    private String getAbsoluteDocBase(Context context)
  +    {
  +	// Calculate the absolute path of the document base
  +	String docBase = context.getDocBase();
  +	if (!FileUtil.isAbsolute(docBase)){
  +	    docBase = tomcatHome + "/" + docBase;
  +	}
  +	docBase = FileUtil.patch(docBase);
  +        return docBase;
  +    }
  +
   }
  
  
  

Mime
View raw message