1 16 17 package org.apache.jk.config; 18 19 import java.io.File ; 20 import java.io.FileWriter ; 21 import java.io.IOException ; 22 import java.io.PrintWriter ; 23 import java.util.Date ; 24 25 import org.apache.catalina.Context; 26 27 28 98 public class NSConfig extends BaseJkConfig { 99 private static org.apache.commons.logging.Log log = 100 org.apache.commons.logging.LogFactory.getLog(NSConfig.class); 101 102 public static final String WORKERS_CONFIG = "/conf/jk/workers.properties"; 103 public static final String NS_CONFIG = "/conf/auto/obj.conf"; 104 public static final String NSAPI_LOG_LOCATION = "/logs/nsapi_redirect.log"; 105 106 public static final String NSAPI_REDIRECTOR; 107 108 static{ 110 String os = System.getProperty("os.name").toLowerCase(); 111 if(os.indexOf("windows")>=0){ 112 NSAPI_REDIRECTOR = "bin/nsapi_redirect.dll"; 113 }else if(os.indexOf("netware")>=0){ 114 NSAPI_REDIRECTOR = "bin/nsapi_rd.nlm"; 115 }else{ 116 NSAPI_REDIRECTOR = "bin/nsapi_redirector.so"; 117 } 118 } 119 120 private File objConfig = null; 121 private File nsapiJk = null; 122 private String objectName = "servlet"; 123 124 public NSConfig() 125 { 126 } 127 128 130 138 public void setObjConfig(String path) { 139 objConfig= (path==null)?null:new File (path); 140 } 141 142 146 public void setNsapiJk(String path) { 147 nsapiJk=( path==null?null:new File (path)); 148 } 149 150 155 public void setObjectName(String name) { 156 objectName = name; 157 } 158 159 161 164 protected void initProperties() { 165 super.initProperties(); 166 167 objConfig=getConfigFile( objConfig, configHome, NS_CONFIG); 168 workersConfig=getConfigFile( workersConfig, configHome, WORKERS_CONFIG); 169 170 if( nsapiJk == null ) 171 nsapiJk=new File (NSAPI_REDIRECTOR); 172 else 173 nsapiJk =getConfigFile( nsapiJk, configHome, NSAPI_REDIRECTOR ); 174 jkLog=getConfigFile( jkLog, configHome, NSAPI_LOG_LOCATION); 175 } 176 177 protected PrintWriter getWriter() throws IOException { 179 String abObjConfig = objConfig.getAbsolutePath(); 180 return new PrintWriter (new FileWriter (abObjConfig,append)); 181 } 182 protected boolean generateJkHead(PrintWriter mod_jk) { 183 log.info("Generating netscape web server config = "+objConfig ); 184 185 generateNsapiHead( mod_jk ); 186 187 mod_jk.println("<Object name=default>"); 188 return true; 189 } 190 191 private void generateNsapiHead(PrintWriter objfile) 192 { 193 objfile.println("###################################################################"); 194 objfile.println("# Auto generated configuration. Dated: " + new Date ()); 195 objfile.println("###################################################################"); 196 objfile.println(); 197 198 objfile.println("#"); 199 objfile.println("# You will need to merge the content of this file with your "); 200 objfile.println("# regular obj.conf and then restart (=stop + start) your Netscape server. "); 201 objfile.println("#"); 202 objfile.println(); 203 204 objfile.println("#"); 205 objfile.println("# Loading the redirector into your server"); 206 objfile.println("#"); 207 objfile.println(); 208 objfile.println("Init fn=\"load-modules\" funcs=\"jk_init,jk_service\" shlib=\"<put full path to the redirector here>\""); 209 objfile.println("Init fn=\"jk_init\" worker_file=\"" + 210 workersConfig.toString().replace('\\', '/') + 211 "\" log_level=\"" + jkDebug + "\" log_file=\"" + 212 jkLog.toString().replace('\\', '/') + 213 "\""); 214 objfile.println(); 215 } 216 217 protected void generateJkTail(PrintWriter objfile) 218 { 219 objfile.println(); 220 objfile.println("#######################################################"); 221 objfile.println("# Protecting the WEB-INF and META-INF directories."); 222 objfile.println("#######################################################"); 223 objfile.println("PathCheck fn=\"deny-existence\" path=\"*/WEB-INF/*\""); 224 objfile.println("PathCheck fn=\"deny-existence\" path=\"*/META-INF/*\""); 225 objfile.println(); 226 227 objfile.println("</Object>"); 228 objfile.println(); 229 230 objfile.println("#######################################################"); 231 objfile.println("# New object to execute your servlet requests."); 232 objfile.println("#######################################################"); 233 objfile.println("<Object name=" + objectName + ">"); 234 objfile.println("ObjectType fn=force-type type=text/html"); 235 objfile.println("Service fn=\"jk_service\" worker=\""+ jkWorker + "\" path=\"/*\""); 236 objfile.println("</Object>"); 237 objfile.println(); 238 } 239 240 242 245 protected void generateStupidMappings(Context context, PrintWriter objfile ) 246 { 247 String ctxPath = context.getPath(); 248 String nPath=("".equals(ctxPath)) ? "/" : ctxPath; 249 250 if( noRoot && "".equals(ctxPath) ) { 251 log.debug("Ignoring root context in forward-all mode "); 252 return; 253 } 254 objfile.println("<Object name=" + context.getName() + ">"); 255 256 objfile.println("NameTrans fn=\"assign-name\" from=\"" + ctxPath + "\" name=\"" + objectName + "\""); 257 objfile.println("NameTrans fn=\"assign-name\" from=\"" + ctxPath + "/*\" name=\"" + objectName + "\""); 258 objfile.println("</Object>"); 259 } 260 261 262 265 protected void generateContextMappings(Context context, PrintWriter objfile ) 266 { 267 String ctxPath = context.getPath(); 268 String nPath=("".equals(ctxPath)) ? "/" : ctxPath; 269 270 if( noRoot && "".equals(ctxPath) ) { 271 log.debug("Ignoring root context in non-forward-all mode "); 272 return; 273 } 274 objfile.println("<Object name=" + context.getName() + ">"); 275 objfile.println("#########################################################"); 277 objfile.println("# Auto configuration for the " + nPath + " context starts."); 278 objfile.println("#########################################################"); 279 objfile.println(); 280 281 283 286 if(context.getLoginConfig() != null) { 288 String loginPage = context.getLoginConfig().getLoginPage(); 289 if(loginPage != null) { 290 int lpos = loginPage.lastIndexOf("/"); 291 String jscurl = loginPage.substring(0,lpos+1) + "j_security_check"; 292 addMapping( ctxPath, jscurl, objfile); 293 } 294 } 295 296 String [] servletMaps=context.findServletMappings(); 297 for(int ii=0; ii < servletMaps.length; ii++) { 298 addMapping( ctxPath , servletMaps[ii] , objfile ); 299 } 300 objfile.println("</Object>"); 301 } 302 303 305 protected boolean addMapping( String ctxPath, String ext, 306 PrintWriter objfile ) 307 { 308 if( log.isDebugEnabled() ) 309 log.debug( "Adding extension map for " + ctxPath + "/*." + ext ); 310 if(! ext.startsWith("/") ) 311 ext = "/" + ext; 312 if(ext.length() > 1) 313 objfile.println("NameTrans fn=\"assign-name\" from=\"" + 314 ctxPath + ext + "\" name=\"" + objectName + "\""); 315 return true; 316 } 317 318 320 protected boolean addMapping( String fullPath, PrintWriter objfile ) { 321 if( log.isDebugEnabled() ) 322 log.debug( "Adding map for " + fullPath ); 323 objfile.println("NameTrans fn=\"assign-name\" from=\"" + 324 fullPath + "\" name=\"" + objectName + "\""); 325 return true; 326 } 327 328 } 329 | Popular Tags |