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 95 public class IISConfig extends BaseJkConfig { 96 97 public static final String WORKERS_CONFIG = "/conf/jk/workers.properties"; 98 public static final String URI_WORKERS_MAP_CONFIG = "/conf/auto/uriworkermap.properties"; 99 public static final String ISAPI_LOG_LOCATION = "/logs/iis_redirect.log"; 100 public static final String ISAPI_REG_FILE = "/conf/auto/iis_redirect.reg"; 101 102 private File regConfig = null; 103 private File uriConfig = null; 104 105 public IISConfig() 106 { 107 } 108 109 111 119 public void setRegConfig(String path){ 120 regConfig= (path==null)?null:new File (path); 121 } 122 123 127 public void setUriConfig(String path){ 128 uriConfig= (path==null?null:new File (path)); 129 } 130 131 133 136 protected void initProperties() { 137 super.initProperties(); 138 139 regConfig=getConfigFile( regConfig, configHome, ISAPI_REG_FILE); 140 workersConfig=getConfigFile( workersConfig, configHome, WORKERS_CONFIG); 141 uriConfig=getConfigFile( uriConfig, configHome, URI_WORKERS_MAP_CONFIG); 142 jkLog=getConfigFile( jkLog, configHome, ISAPI_LOG_LOCATION); 143 } 144 145 147 protected PrintWriter getWriter() throws IOException { 148 String abUriConfig = uriConfig.getAbsolutePath(); 149 return new PrintWriter (new FileWriter (abUriConfig,append)); 150 } 151 protected boolean generateJkHead(PrintWriter mod_jk) { 152 try { 153 PrintWriter regfile = new PrintWriter (new FileWriter (regConfig)); 154 log("Generating IIS registry file = "+regConfig ); 155 generateRegistrySettings(regfile); 156 regfile.close(); 157 } catch(IOException iex) { 158 log("Unable to generate registry file " +regConfig); 159 return false; 160 } 161 log("Generating IIS URI worker map file = "+uriConfig ); 162 generateUriWorkerHeader(mod_jk); 163 return true; 164 } 165 166 168 170 private void generateRegistrySettings(PrintWriter regfile) 171 { 172 regfile.println("REGEDIT4"); 173 regfile.println(); 174 regfile.println("[HKEY_LOCAL_MACHINE\\SOFTWARE\\Apache Software Foundation\\Jakarta Isapi Redirector\\1.0]"); 175 regfile.println("\"extension_uri\"=\"/jakarta/isapi_redirect.dll\""); 176 regfile.println("\"log_file\"=\"" + dubleSlash(jkLog.toString()) +"\""); 177 regfile.println("\"log_level\"=\"" + jkDebug + "\""); 178 regfile.println("\"worker_file\"=\"" + dubleSlash(workersConfig.toString()) +"\""); 179 regfile.println("\"worker_mount_file\"=\"" + dubleSlash(uriConfig.toString()) +"\""); 180 } 181 182 184 private void generateUriWorkerHeader(PrintWriter uri_worker) 185 { 186 uri_worker.println("###################################################################"); 187 uri_worker.println("# Auto generated configuration. Dated: " + new Date ()); 188 uri_worker.println("###################################################################"); 189 uri_worker.println(); 190 191 uri_worker.println("#"); 192 uri_worker.println("# Default worker to be used through our mappings"); 193 uri_worker.println("#"); 194 uri_worker.println("default.worker=" + jkWorker); 195 uri_worker.println(); 196 } 197 198 201 protected void generateStupidMappings(Context context, PrintWriter uri_worker ) 202 { 203 String ctxPath = context.getPath(); 204 String nPath=("".equals(ctxPath)) ? "/" : ctxPath; 205 206 if( noRoot && "".equals(ctxPath) ) { 207 log("Ignoring root context in forward-all mode "); 208 return; 209 } 210 211 uri_worker.println(nPath +"=$(default.worker)"); 213 if( "".equals(ctxPath) ) { 214 uri_worker.println(nPath +"*=$(default.worker)"); 215 uri_worker.println( 216 "# Note: To correctly serve the Tomcat's root context, IIS's Home Directory must"); 217 uri_worker.println( 218 "# must be set to: \"" + getAbsoluteDocBase(context) + "\""); 219 } 220 else 221 uri_worker.println(nPath +"/*=$(default.worker)"); 222 } 223 224 protected void generateContextMappings(Context context, PrintWriter uri_worker ) 225 { 226 String ctxPath = context.getPath(); 227 String nPath=("".equals(ctxPath)) ? "/" : ctxPath; 228 229 if( noRoot && "".equals(ctxPath) ) { 230 log("Ignoring root context in forward-all mode "); 231 return; 232 } 233 234 uri_worker.println(); 236 uri_worker.println("#########################################################"); 237 uri_worker.println("# Auto configuration for the " + nPath + " context."); 238 uri_worker.println("#########################################################"); 239 uri_worker.println(); 240 241 243 246 248 if(context.getLoginConfig() != null) { 249 String loginPage = context.getLoginConfig().getLoginPage(); 250 if(loginPage != null) { 251 int lpos = loginPage.lastIndexOf("/"); 252 String jscurl = loginPage.substring(0,lpos+1) + "j_security_check"; 253 addMapping( ctxPath, jscurl, uri_worker); 254 } 255 } 256 String [] servletMaps=context.findServletMappings(); 257 for( int ii=0; ii < servletMaps.length ; ii++) { 258 addMapping( ctxPath , servletMaps[ii] , uri_worker ); 259 } 260 } 261 262 264 protected boolean addMapping( String ctxPath, String ext, 265 PrintWriter uri_worker ) 266 { 267 if( debug > 0 ) 268 log( "Adding extension map for " + ctxPath + "/*." + ext ); 269 if(! ext.startsWith("/") ) 270 ext = "/" + ext; 271 if(ext.length() > 1) 272 uri_worker.println(ctxPath + "/*." + ext + "=$(default.worker)"); 273 return true; 274 } 275 276 278 protected boolean addMapping( String fullPath, PrintWriter uri_worker ) { 279 if( debug > 0 ) 280 log( "Adding map for " + fullPath ); 281 uri_worker.println(fullPath + "=$(default.worker)" ); 282 return true; 283 } 284 285 287 private String dubleSlash(String in) 288 { 289 StringBuffer sb = new StringBuffer (); 290 291 for(int i = 0 ; i < in.length() ; i++) { 292 char ch = in.charAt(i); 293 if('\\' == ch) { 294 sb.append("\\\\"); 295 } else { 296 sb.append(ch); 297 } 298 } 299 300 return sb.toString(); 301 } 302 303 } 304 | Popular Tags |