|
What this is
Other links
The source code/* $Id: ApacheConfig.java,v 1.32 2004/02/25 07:06:59 billbarker Exp $ * ==================================================================== * * * Copyright 1999-2004 The Apache Sofware Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.modules.config; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; import java.util.Date; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import org.apache.tomcat.core.Container; import org.apache.tomcat.core.Context; import org.apache.tomcat.core.ContextManager; import org.apache.tomcat.core.TomcatException; import org.apache.tomcat.util.io.FileUtil; import org.apache.tomcat.util.log.Log; /* 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 want to and know what they're doing ( better than we do :-). One nice feature ( if someone sends it ) would be to also edit httpd.conf to add the include. We'll generate a number of configuration files - this one is trying to generate a native apache config file. Some web.xml mappings do not "map" to server configuration - in this case we need to fallback to forward all requests to tomcat. Ajp14 will add to that the posibility to have tomcat and apache on different machines, and many other improvements - but this should also work for Ajp12, Ajp13 and Jni. */ /** Generates automatic apache mod_jk configurations based on the Tomcat server.xml settings and the war contexts initialized during startup.
@author Costin Manolache @author Larry Isaacs @author Mel Martinez @version $Revision: 1.32 $ $Date: 2004/02/25 07:06:59 $ */ public class ApacheConfig extends BaseJkConfig { /** default path to mod_jk .conf location */ public static final String MOD_JK_CONFIG = "conf/auto/mod_jk.conf"; /** default path to workers.properties file This should be also auto-generated from server.xml. */ 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_jk Apache plug-in. */ public static String MOD_JK; //set up some defaults based on OS type static{ String os = System.getProperty("os.name").toLowerCase(); if(os.indexOf("windows")>=0){ MOD_JK = "modules/mod_jk.dll"; }else if(os.indexOf("netware")>=0){ MOD_JK = "modules/mod_jk.nlm"; }else{ MOD_JK = "libexec/mod_jk.so"; } } private File jkConfig = null; private File modJk = null; // ssl settings private boolean sslExtract=true; private String sslHttpsIndicator="HTTPS"; private String sslSessionIndicator="SSL_SESSION_ID"; private String sslCipherIndicator="SSL_CIPHER"; private String sslCertsIndicator="SSL_CLIENT_CERT"; Hashtable NamedVirtualHosts=null; public ApacheConfig() { } //-------------------- Properties -------------------- /** set the path to the output file for the auto-generated mod_jk configuration file. If this path is relative then it will be resolved absolutely against the getConfigHome() path. @param path String path to a file */ public void setJkConfig(String path){ jkConfig= (path==null)?null:new File(path); } /** set the path to the mod_jk Apache Module @param path String path to a file */ public void setModJk(String path){ modJk=( path==null?null:new File(path)); } /** By default mod_jk is configured to collect SSL information from the apache environment and send it to the Tomcat workers. The problem is that there are many SSL solutions for Apache and as a result the environment variable names may change. The following JK related SSL configureation can be used to customize mod_jk's SSL behaviour. Should mod_jk send SSL information to Tomact (default is On) */ public void setExtractSSL( boolean sslMode ) { this.sslExtract=sslMode; } /** What is the indicator for SSL (default is HTTPS) */ public void setHttpsIndicator( String s ) { sslHttpsIndicator=s; } /**What is the indicator for SSL session (default is SSL_SESSION_ID) */ public void setSessionIndicator( String s ) { sslSessionIndicator=s; } /**What is the indicator for client SSL cipher suit (default is SSL_CIPHER) */ public void setCipherIndicator( String s ) { sslCipherIndicator=s; } /** What is the indicator for the client SSL certificated(default is SSL_CLIENT_CERT */ public void setCertsIndicator( String s ) { sslCertsIndicator=s; } // -------------------- Initialize/guess defaults -------------------- /** Initialize defaults for properties that are not set explicitely */ protected void initProperties(ContextManager cm) { super.initProperties(cm); jkConfig=FileUtil.getConfigFile( jkConfig, configHome, MOD_JK_CONFIG); workersConfig=FileUtil.getConfigFile( workersConfig, configHome, WORKERS_CONFIG); if( modJk == null ) modJk=new File(MOD_JK); else modJk=FileUtil.getConfigFile( modJk, configHome, MOD_JK ); jkLog=FileUtil.getConfigFile( jkLog, configHome, JK_LOG_LOCATION); } // -------------------- Generate config -------------------- /** executes the ApacheConfig interceptor. This method generates apache configuration files for use with mod_jk. If not already set, this method will setConfigHome() to the value returned from cm.getHome().
@param cm a ContextManager object.
*/
public void execute(ContextManager cm) throws TomcatException {
try {
initProperties(cm);
initWorker(cm);
NamedVirtualHosts = new Hashtable();
StringBuffer sb=new StringBuffer();
PrintWriter mod_jk = new PrintWriter(new FileWriter(jkConfig));
log("Generating apache mod_jk config = "+jkConfig );
generateJkHead( mod_jk );
// XXX Make those options configurable in server.xml
generateSSLConfig( mod_jk );
Hashtable vhosts = new Hashtable();
// Set up contexts
// XXX deal with Virtual host configuration !!!!
Enumeration enum = cm.getContexts();
while (enum.hasMoreElements()) {
Context context = (Context)enum.nextElement();
String host = context.getHost();
if( host == null ) {
if( forwardAll )
generateStupidMappings( context, mod_jk );
else
generateContextMappings( context, mod_jk );
} else {
Vector vhostContexts = (Vector)vhosts.get(host);
if ( vhostContexts == null ) {
vhostContexts = new Vector();
vhosts.put(host,vhostContexts);
}
vhostContexts.addElement(context);
}
}
enum = vhosts.elements();
while( enum.hasMoreElements() ) {
Vector vhostContexts = (Vector)enum.nextElement();
for( int i = 0; i < vhostContexts.size(); i++ ) {
Context context = (Context)vhostContexts.elementAt(i);
if( i == 0 )
generateVhostHead( context, mod_jk );
if( forwardAll )
generateStupidMappings( context, mod_jk );
else
generateContextMappings( context, mod_jk );
}
generateVhostTail( mod_jk );
}
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 boolean generateJkHead(PrintWriter mod_jk)
throws TomcatException
{
mod_jk.println("########## Auto generated on " + new Date() +
"##########" );
mod_jk.println();
// Fail if mod_jk not found, let the user know the problem
// instead of running into problems later.
if( ! modJk.exists() ) {
log( "mod_jk location: " + modJk );
log( "Make sure it is installed corectly or " +
" set the config location" );
log( "Using |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.