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