Modified: turbine/core/trunk/src/java/org/apache/turbine/Turbine.java URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/Turbine.java?rev=1845811&r1=1845810&r2=1845811&view=diff ============================================================================== --- turbine/core/trunk/src/java/org/apache/turbine/Turbine.java (original) +++ turbine/core/trunk/src/java/org/apache/turbine/Turbine.java Mon Nov 5 15:18:22 2018 @@ -19,17 +19,18 @@ package org.apache.turbine; * under the License. */ -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -61,6 +62,7 @@ import org.apache.commons.lang3.exceptio import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.text.StringSubstitutor; +import org.apache.log4j.LogManager; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.xml.DOMConfigurator; import org.apache.turbine.modules.PageLoader; @@ -360,16 +362,16 @@ public class Turbine extends HttpServlet Path targetPathDirectory = targetPath.getParent(); if ( targetPathDirectory != null ) { - // set the configuration path - confPath = targetPathDirectory.normalize().toFile(); + // set the configuration path + confPath = targetPathDirectory.normalize().toFile(); Path targetFilePath = targetPath.getFileName(); if ( targetFilePath != null ) { - // set the configuration file name - confFile = targetFilePath.toString(); + // set the configuration file name + confFile = targetFilePath.toString(); } - + } switch (confStyle) @@ -431,10 +433,10 @@ public class Turbine extends HttpServlet // Retrieve the pipeline class and then initialize it. The pipeline // handles the processing of a webrequest/response cycle. - String descriptorPath = - configuration.getString( - "pipeline.default.descriptor", - TurbinePipeline.CLASSIC_PIPELINE); + String descriptorPath = + configuration.getString( + "pipeline.default.descriptor", + TurbinePipeline.CLASSIC_PIPELINE); if (log.isDebugEnabled()) { @@ -444,7 +446,7 @@ public class Turbine extends HttpServlet // context resource path has to begin with slash, cft. context.getResource if (!descriptorPath.startsWith( "/" )) { - descriptorPath = "/" + descriptorPath; + descriptorPath = "/" + descriptorPath; } try (InputStream reader = context.getResourceAsStream(descriptorPath)) @@ -454,9 +456,9 @@ public class Turbine extends HttpServlet pipeline = (Pipeline) unmarshaller.unmarshal(reader); } - log.debug("Initializing pipeline"); + log.debug("Initializing pipeline"); - pipeline.initialize(); + pipeline.initialize(); } /** @@ -479,10 +481,10 @@ public class Turbine extends HttpServlet Path logConfPath = targetPath.getParent(); if ( logConfPath != null ) { - Path logFilePath = logConfPath.resolve( log4jFile ); - if ( logFilePath != null ) - { - log4jTarget = logFilePath.normalize(); + Path logFilePath = logConfPath.resolve( log4jFile ); + if ( logFilePath != null ) + { + log4jTarget = logFilePath.normalize(); } } @@ -499,17 +501,25 @@ public class Turbine extends HttpServlet // NOTE: Only system property expansion available try { - // do a substitute application root + // NOTE: expand application root explicitely Map<String,String> valMap = new HashMap<>(); // just always use slashes, TODO make it configurable? valMap.put(TurbineConstants.APPLICATION_ROOT_KEY, getApplicationRoot().replace( '\\', '/' )); StringSubstitutor sub = new StringSubstitutor(valMap); String log4jTemplate = new String(Files.readAllBytes(Paths.get(log4jFile))); String resolvedString = sub.replace(log4jTemplate); - String log4jFileTarget = log4jFile.replaceFirst( "\\.xml$", "-gen.xml"); - Files.copy( new ByteArrayInputStream(resolvedString.getBytes()), - new File(log4jFileTarget).toPath(), StandardCopyOption.REPLACE_EXISTING); - DOMConfigurator.configure(log4jFileTarget); + + // just always use slashes + String winFS = "\\"; + if (FileSystems.getDefault().getSeparator().equals( winFS ) + && resolvedString.contains( winFS )) { + System.out.println( FileSystems.getDefault().getClass().getName() + " with fsep ('"+ FileSystems.getDefault().getSeparator() + "') in " + log4jFile + ", changing to forward slash ('/')." ); + resolvedString = resolvedString.replace( '\\', '/' ); + } + Reader memoryConfiguration = new StringReader(resolvedString); + DOMConfigurator log4jDOMConf = new DOMConfigurator(); + log4jDOMConf.doConfigure(memoryConfiguration, LogManager.getLoggerRepository()); + success = true; } catch (FactoryConfigurationError e) @@ -616,20 +626,20 @@ public class Turbine extends HttpServlet for (Iterator<String> i = services.getServiceNames(); i.hasNext();) { - String serviceName = i.next(); - Object service = services.getService(serviceName); + String serviceName = i.next(); + Object service = services.getService(serviceName); - if (service instanceof Initable) - { - try - { - ((Initable)service).init(data); - } - catch (InitializationException e) - { - log.warn("Could not initialize Initable " + serviceName + " with PipelineData", e); - } - } + if (service instanceof Initable) + { + try + { + ((Initable)service).init(data); + } + catch (InitializationException e) + { + log.warn("Could not initialize Initable " + serviceName + " with PipelineData", e); + } + } } // Mark that we're done.
