|
What this is
Other links
The source code/* $Id: BaseJkConfig.java,v 1.9 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.PrintWriter; import org.apache.tomcat.core.BaseInterceptor; 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.modules.server.Ajp13Interceptor; import org.apache.tomcat.util.io.FileUtil; /** Base class for automatic jk based configurations based on the Tomcat server.xml settings and the war contexts initialized during startup.
@author Costin Manolache @author Larry Isaacs @version $Revision: 1.9 $ */ public class BaseJkConfig extends BaseInterceptor { protected File configHome = null; protected File workersConfig = null; protected File jkLog = null; protected String jkDebug="emerg"; protected String jkWorker = null; protected boolean noRoot=true; protected boolean forwardAll=true; protected String tomcatHome; protected boolean regenerate=false; // -------------------- Tomcat callbacks -------------------- public void addInterceptor( ContextManager cm, Context ctx, BaseInterceptor bi ) throws TomcatException { if( cm.getProperty( "jkconf" ) != null ) { // we are in config generation mode - prevent tomcat // from starting. //??? cm.setNote("nostart", this ); } } // Auto-config should be able to react to dynamic config changes, // and regenerate the config. /** Generate the configuration - only when the server is * completely initialized ( before starting ) */ public void engineState( ContextManager cm, int state ) throws TomcatException { if( state != ContextManager.STATE_INIT ) return; // Generate the config only if "regenerate" property is // set on the module or if an explicit "jkconf" option has // been set on context manager. if( regenerate || cm.getProperty("jkconf") !=null) { execute( cm ); } } public void contextInit(Context ctx) throws TomcatException { 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 // the server ) // Generate the config only if "regenerate" property is // set on the module or if an explicit "jkconf" option has // been set on context manager. if( regenerate || cm.getProperty("jkconf") !=null) { execute( cm ); } } } /** Generate configuration files. Override with method to generate web server specific configuration. */ public void execute(ContextManager cm) throws TomcatException { } //-------------------- 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". However, if the path is set to an absolute path, this attribute is ignored. If not set, execute() will set this to TOMCAT_HOME.
@param dir - path to a directory
*/
public void setConfigHome(String dir){
if( dir==null ) return;
File f=new File(dir);
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 path String path to workers.properties file
*/
public void setWorkersConfig(String path){
workersConfig= (path==null?null:new File(path));
}
/**
set the path to the log file
@param path String path to a file
*/
public void setJkLog(String path){
jkLog= ( path==null?null:new File(path));
}
/** Set the verbosity level
( use debug, error, etc. ) If not set, no log is written.
*/
public void setJkDebug( String level ) {
jkDebug=level;
}
/**
set the Ajp protocal
@param protocal String protocol, "ajp12" or "ajp13"
*/
public void setJkWorker(String worker){
jkWorker = worker;
}
// -------------------- 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 initWorker(ContextManager cm) {
// Find Ajp1? connectors
BaseInterceptor ci[]=cm.getContainer().getInterceptors();
for( int i=0; i |
... 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.