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