You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by la...@apache.org on 2001/10/08 07:27:18 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/config NSConfig.java IISConfig.java BaseJkConfig.java ApacheConfig.java
larryi 01/10/07 22:27:18
Modified: src/share/org/apache/tomcat/modules/config NSConfig.java
IISConfig.java BaseJkConfig.java ApacheConfig.java
Log:
Bring NSConfig.java up to approximately the same level as IISConfig.java
and ApacheConfig.java. Also, change initProtocal method to initWorker
to more accurately identify its function.
Revision Changes Path
1.7 +206 -95 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NSConfig.java 2001/10/02 11:46:31 1.6
+++ NSConfig.java 2001/10/08 05:27:18 1.7
@@ -89,9 +89,15 @@
<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>objectName</b> - Name of the Object to execute the requests.
+ Defaults to "servlet".</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>nsapiJk</b> - path to Netscape mod_jk plugin file. If not set,
+ defaults to "bin/nsapi_redirect.dll" on windows,
+ "bin/nsapi_rd.nlm" on netware, and
+ "bin/nsapi_redirector.so" everywhere else.</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>
@@ -127,15 +133,31 @@
@author Costin Manolache
@author Larry Isaacs
@author Gal Shachor
- @version $Revision: 1.6 $
+ @version $Revision: 1.7 $
*/
public class NSConfig extends BaseJkConfig {
public static final String WORKERS_CONFIG = "/conf/jk/workers.properties";
public static final String NS_CONFIG = "/conf/auto/obj.conf";
public static final String NSAPI_LOG_LOCATION = "/logs/nsapi_redirect.log";
+ /** default location of nsapi plug-in. */
+ public static final String NSAPI_REDIRECTOR;
+
+ //set up some defaults based on OS type
+ static{
+ String os = System.getProperty("os.name").toLowerCase();
+ if(os.indexOf("windows")>=0){
+ NSAPI_REDIRECTOR = "bin/nsapi_redirect.dll";
+ }else if(os.indexOf("netware")>=0){
+ NSAPI_REDIRECTOR = "bin/nsapi_rd.nlm";
+ }else{
+ NSAPI_REDIRECTOR = "bin/nsapi_redirector.so";
+ }
+ }
private File objConfig = null;
+ private File nsapiJk = null;
+ private String objectName = "servlet";
Log loghelper = Log.getLog("tc_log", this);
@@ -153,10 +175,27 @@
<p>
@param <b>path</b> String path to a file
*/
- public void setObjConfig(String path){
+ public void setObjConfig(String path) {
objConfig= (path==null)?null:new File(path);
}
+ /**
+ set the path to the nsapi plugin module
+ @param <b>path</b> String path to a file
+ */
+ public void setNsapiJk(String path) {
+ nsapiJk=( path==null?null:new File(path));
+ }
+
+ /**
+ Set the name for the Object that implements the
+ jk_service call.
+ @param <b>name</b> Name of the obj.conf Object
+ */
+ public void setObjectName(String name) {
+ objectName = name;
+ }
+
// -------------------- Initialize/guess defaults --------------------
/** Initialize defaults for properties that are not set
@@ -167,6 +206,11 @@
objConfig=FileUtil.getConfigFile( objConfig, configHome, NS_CONFIG);
workersConfig=FileUtil.getConfigFile( workersConfig, configHome, WORKERS_CONFIG);
+
+ if( nsapiJk == null )
+ nsapiJk=new File(NSAPI_REDIRECTOR);
+ else
+ nsapiJk =FileUtil.getConfigFile( nsapiJk, configHome, NSAPI_REDIRECTOR );
jkLog=FileUtil.getConfigFile( jkLog, configHome, NSAPI_LOG_LOCATION);
}
@@ -184,103 +228,170 @@
{
try {
initProperties(cm);
- initProtocol(cm);
+ initWorker(cm);
PrintWriter objfile = new PrintWriter(new FileWriter(objConfig));
-
- objfile.println("###################################################################");
- objfile.println("# Auto generated configuration. Dated: " + new Date());
- objfile.println("###################################################################");
- objfile.println();
-
- objfile.println("#");
- objfile.println("# You will need to merge the content of this file with your ");
- objfile.println("# regular obj.conf and then restart (=stop + start) your Netscape server. ");
- objfile.println("#");
- objfile.println();
-
- objfile.println("#");
- objfile.println("# Loading the redirector into your server");
- objfile.println("#");
- 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=\"" +
- workersConfig.toString().replace('\\', '/') +
- "\" log_level=\"" + jkDebug + "\" log_file=\"" +
- jkLog.toString().replace('\\', '/') +
- "\"");
- objfile.println();
-
- objfile.println("<Object name=default>");
- objfile.println("#");
- objfile.println("# Redirecting the root context requests to tomcat.");
- objfile.println("#");
- objfile.println("NameTrans fn=\"assign-name\" from=\"/servlet/*\" name=\"servlet\"");
- objfile.println("NameTrans fn=\"assign-name\" from=\"/*.jsp\" name=\"servlet\"");
- objfile.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 Netscape
- continue;
- }
- if(path.length() > 1) {
- // Calculate the absolute path of the document base
- String docBase = context.getDocBase();
- if (!FileUtil.isAbsolute(docBase))
- docBase = tomcatHome + "/" + docBase;
- docBase = FileUtil.patch(docBase).replace('\\', '/');
-
- // Static files will be served by Apache
- objfile.println("#########################################################");
- objfile.println("# Auto configuration for the " + path + " context starts.");
- objfile.println("#########################################################");
- objfile.println();
-
- objfile.println("#");
- objfile.println("# The following line mounts all JSP file and the /servlet/ uri to tomcat");
- objfile.println("#");
- objfile.println("NameTrans fn=\"assign-name\" from=\"" + path + "/servlet/*\" name=\"servlet\"");
- objfile.println("NameTrans fn=\"assign-name\" from=\"" + path + "/*.jsp\" name=\"servlet\"");
- objfile.println("NameTrans fn=pfx2dir from=\"" + path + "\" dir=\"" + docBase + "\"");
- objfile.println();
- objfile.println("#######################################################");
- objfile.println("# Auto configuration for the " + path + " context ends.");
- objfile.println("#######################################################");
- objfile.println();
- }
- }
-
- objfile.println("#######################################################");
- objfile.println("# Protecting the web inf directory.");
- objfile.println("#######################################################");
- objfile.println("PathCheck fn=\"deny-existence\" path=\"*/WEB-INF/*\"");
- objfile.println();
-
- objfile.println("</Object>");
- objfile.println();
-
-
- objfile.println("#######################################################");
- objfile.println("# New object to execute your servlet requests.");
- objfile.println("#######################################################");
- objfile.println("<Object name=servlet>");
- objfile.println("ObjectType fn=force-type type=text/html");
- objfile.println("Service fn=\"jk_service\" worker=\""+ jkWorker + "\" path=\"/*\"");
- objfile.println("</Object>");
- objfile.println();
+ log("Generating netscape web server config = "+objConfig );
+
+ generateNsapiHead( objfile );
+
+ objfile.println("<Object name=default>");
-
- objfile.close();
+ // 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 Netscape
+ continue;
+ }
+
+ if( forwardAll )
+ generateStupidMappings( context, objfile );
+ else
+ generateContextMappings( context, objfile );
+ }
+
+ generateNsapiTail(objfile);
+
+ objfile.close();
} catch(Exception ex) {
loghelper.log("Error generating automatic Netscape configuration", ex);
}
- }
+ }
+
+ private void generateNsapiHead(PrintWriter objfile)
+ throws TomcatException
+ {
+ objfile.println("###################################################################");
+ objfile.println("# Auto generated configuration. Dated: " + new Date());
+ objfile.println("###################################################################");
+ objfile.println();
+
+ objfile.println("#");
+ objfile.println("# You will need to merge the content of this file with your ");
+ objfile.println("# regular obj.conf and then restart (=stop + start) your Netscape server. ");
+ objfile.println("#");
+ objfile.println();
+
+ objfile.println("#");
+ objfile.println("# Loading the redirector into your server");
+ objfile.println("#");
+ 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=\"" +
+ workersConfig.toString().replace('\\', '/') +
+ "\" log_level=\"" + jkDebug + "\" log_file=\"" +
+ jkLog.toString().replace('\\', '/') +
+ "\"");
+ objfile.println();
+ }
+
+ private void generateNsapiTail(PrintWriter objfile)
+ throws TomcatException
+ {
+ objfile.println();
+ objfile.println("#######################################################");
+ objfile.println("# Protecting the WEB-INF and META-INF directories.");
+ objfile.println("#######################################################");
+ objfile.println("PathCheck fn=\"deny-existence\" path=\"*/WEB-INF/*\"");
+ objfile.println("PathCheck fn=\"deny-existence\" path=\"*/META-INF/*\"");
+ objfile.println();
+
+ objfile.println("</Object>");
+ objfile.println();
+
+ objfile.println("#######################################################");
+ objfile.println("# New object to execute your servlet requests.");
+ objfile.println("#######################################################");
+ objfile.println("<Object name=" + objectName + ">");
+ objfile.println("ObjectType fn=force-type type=text/html");
+ objfile.println("Service fn=\"jk_service\" worker=\""+ jkWorker + "\" path=\"/*\"");
+ objfile.println("</Object>");
+ objfile.println();
+ }
+
+ // -------------------- Forward all mode --------------------
+
+ /** Forward all requests for a context to tomcat.
+ The default.
+ */
+ private void generateStupidMappings(Context context, PrintWriter objfile )
+ {
+ String ctxPath = context.getPath();
+ String nPath=("".equals(ctxPath)) ? "/" : ctxPath;
+
+ if( noRoot && "".equals(ctxPath) ) {
+ log("Ignoring root context in forward-all mode ");
+ return;
+ }
+
+ objfile.println("NameTrans fn=\"assign-name\" from=\"" + ctxPath + "\" name=\"" + objectName + "\"");
+ objfile.println("NameTrans fn=\"assign-name\" from=\"" + ctxPath + "/*\" name=\"" + objectName + "\"");
+ }
+
+
+ // -------------------- Netscape serves static mode --------------------
+ // This is not going to work for all apps. We fall back to stupid mode.
+
+ private void generateContextMappings(Context context, PrintWriter objfile )
+ {
+ String ctxPath = context.getPath();
+ String nPath=("".equals(ctxPath)) ? "/" : ctxPath;
+
+ if( noRoot && "".equals(ctxPath) ) {
+ log("Ignoring root context in non-forward-all mode ");
+ return;
+ }
+
+ // Static files will be served by Netscape
+ objfile.println("#########################################################");
+ objfile.println("# Auto configuration for the " + nPath + " context starts.");
+ objfile.println("#########################################################");
+ objfile.println();
+
+ // XXX Need to determine what if/how static mappings are done
+
+ // 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/*", objfile );
+
+ Enumeration servletMaps=context.getContainers();
+ while( servletMaps.hasMoreElements() ) {
+ Container ct=(Container)servletMaps.nextElement();
+ addMapping( context, ct , objfile );
+ }
+
+ // XXX ErrorDocument
+ // Security and filter mappings
+
+ }
+
+ /** Add a Netscape extension mapping.
+ */
+ protected boolean addExtensionMapping( String ctxPath, String ext,
+ PrintWriter objfile )
+ {
+ if( debug > 0 )
+ log( "Adding extension map for " + ctxPath + "/*." + ext );
+ objfile.println("NameTrans fn=\"assign-name\" from=\"" +
+ ctxPath + "/*." + ext + "\" name=\"" + objectName + "\"");
+ return true;
+ }
+
+ /** Add a fulling specified Netscape mapping.
+ */
+ protected boolean addMapping( String fullPath, PrintWriter objfile ) {
+ if( debug > 0 )
+ log( "Adding map for " + fullPath );
+ objfile.println("NameTrans fn=\"assign-name\" from=\"" +
+ fullPath + "\" name=\"" + objectName + "\"");
+ return true;
+ }
+
}
1.10 +2 -2 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- IISConfig.java 2001/10/02 02:55:13 1.9
+++ IISConfig.java 2001/10/08 05:27:18 1.10
@@ -131,7 +131,7 @@
@author Costin Manolache
@author Larry Isaacs
@author Gal Shachor
- @version $Revision: 1.9 $
+ @version $Revision: 1.10 $
*/
public class IISConfig extends BaseJkConfig {
@@ -197,7 +197,7 @@
{
try {
initProperties(cm);
- initProtocol(cm);
+ initWorker(cm);
PrintWriter regfile = new PrintWriter(new FileWriter(regConfig));
PrintWriter uri_worker = new PrintWriter(new FileWriter(uriConfig));
1.6 +3 -3 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BaseJkConfig.java 2001/10/02 02:55:13 1.5
+++ BaseJkConfig.java 2001/10/08 05:27:18 1.6
@@ -1,4 +1,4 @@
-/* $Id: BaseJkConfig.java,v 1.5 2001/10/02 02:55:13 larryi Exp $
+/* $Id: BaseJkConfig.java,v 1.6 2001/10/08 05:27:18 larryi Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -121,7 +121,7 @@
<p>
@author Costin Manolache
@author Larry Isaacs
- @version $Revision: 1.5 $
+ @version $Revision: 1.6 $
*/
public class BaseJkConfig extends BaseInterceptor {
protected File configHome = null;
@@ -286,7 +286,7 @@
}
}
- protected void initProtocol(ContextManager cm) {
+ protected void initWorker(ContextManager cm) {
// Find Ajp1? connectors
BaseInterceptor ci[]=cm.getContainer().getInterceptors();
1.28 +3 -3 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.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- ApacheConfig.java 2001/10/02 02:55:13 1.27
+++ ApacheConfig.java 2001/10/08 05:27:18 1.28
@@ -1,4 +1,4 @@
-/* $Id: ApacheConfig.java,v 1.27 2001/10/02 02:55:13 larryi Exp $
+/* $Id: ApacheConfig.java,v 1.28 2001/10/08 05:27:18 larryi Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -149,7 +149,7 @@
@author Costin Manolache
@author Larry Isaacs
@author Mel Martinez
- @version $Revision: 1.27 $ $Date: 2001/10/02 02:55:13 $
+ @version $Revision: 1.28 $ $Date: 2001/10/08 05:27:18 $
*/
public class ApacheConfig extends BaseJkConfig {
@@ -283,7 +283,7 @@
public void execute(ContextManager cm) throws TomcatException {
try {
initProperties(cm);
- initProtocol(cm);
+ initWorker(cm);
NamedVirtualHosts = new Hashtable();