|
What this is
Other links
The source code/* * 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 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; /** Generates automatic Netscape nsapi_redirect configurations based on the Tomcat server.xml settings and the war contexts initialized during startup.
@author Costin Manolache @author Larry Isaacs @author Gal Shachor @version $Revision: 1.12 $ */ 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 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); public NSConfig() { } //-------------------- Properties -------------------- /** set the path to the output file for the auto-generated isapi_redirect registry file. If this path is relative then getRegConfig() will resolve it absolutely against the getConfigHome() path. @param path String path to a file */ public void setObjConfig(String path) { objConfig= (path==null)?null:new File(path); } /** set the path to the nsapi plugin module @param path 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 name Name of the obj.conf Object */ public void setObjectName(String name) { objectName = name; } // -------------------- Initialize/guess defaults -------------------- /** Initialize defaults for properties that are not set explicitely */ protected void initProperties(ContextManager cm) { super.initProperties(cm); 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); } // -------------------- Generate config -------------------- /** executes the NSConfig interceptor. This method generates Netscape configuration files for use with nsapi_redirect. 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); PrintWriter objfile = new PrintWriter(new FileWriter(objConfig)); log("Generating netscape web server config = "+objConfig ); generateNsapiHead( objfile ); objfile.println(""); objfile.println(); objfile.println("#######################################################"); objfile.println("# New object to execute your servlet requests."); objfile.println("#######################################################"); objfile.println(""); objfile.println(); if( !forwardAll ) { objfile.println("#######################################################"); objfile.println("# New object to execute URLs containing \";jsessionid=\""); objfile.println("#######################################################"); objfile.println(""); 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 ); if( fullPath.endsWith("/*") ) { objfile.println("NameTrans fn=\"assign-name\" from=\"" + fullPath.substring(0, fullPath.length() - 2) + "\" name=\"" + objectName + "\""); } objfile.println("NameTrans fn=\"assign-name\" from=\"" + fullPath + "\" name=\"" + objectName + "\""); return true; } } |
... 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.