You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2012/01/14 23:20:16 UTC

svn commit: r1231590 - in /camel/branches/camel-2.9.x/components/camel-velocity: ./ src/main/java/org/apache/camel/component/velocity/ src/test/java/org/apache/camel/component/velocity/ src/test/resources/ src/test/resources/org/apache/camel/component/...

Author: cmueller
Date: Sat Jan 14 22:20:15 2012
New Revision: 1231590

URL: http://svn.apache.org/viewvc?rev=1231590&view=rev
Log:
CAMEL-4884: Make velocity logging configurable

Added:
    camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityOverridesPropertiesTest.java
    camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity-logging.properties
      - copied, changed from r1231137, camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties
Modified:
    camel/branches/camel-2.9.x/components/camel-velocity/pom.xml
    camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
    camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties

Modified: camel/branches/camel-2.9.x/components/camel-velocity/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/pom.xml?rev=1231590&r1=1231589&r2=1231590&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/pom.xml (original)
+++ camel/branches/camel-2.9.x/components/camel-velocity/pom.xml Sat Jan 14 22:20:15 2012
@@ -63,6 +63,12 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+        	<groupId>commons-io</groupId>
+        	<artifactId>commons-io</artifactId>
+        	<version>${commons-io-version}</version>
+        	<scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>

Modified: camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java?rev=1231590&r1=1231589&r2=1231590&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java (original)
+++ camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java Sat Jan 14 22:20:15 2012
@@ -70,9 +70,20 @@ public class VelocityEndpoint extends Re
     private synchronized VelocityEngine getVelocityEngine() throws Exception {
         if (velocityEngine == null) {
             velocityEngine = new VelocityEngine();
+
+            // set the class resolver as a property so we can access it from CamelVelocityClasspathResourceLoader
+            velocityEngine.addProperty("CamelClassResolver", getCamelContext().getClassResolver());
+
+            // set default properties
             Properties properties = new Properties();
+            properties.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, isLoaderCache() ? "true" : "false");
+            properties.setProperty(Velocity.RESOURCE_LOADER, "file, class");
+            properties.setProperty("class.resource.loader.description", "Camel Velocity Classpath Resource Loader");
+            properties.setProperty("class.resource.loader.class", CamelVelocityClasspathResourceLoader.class.getName());
+            properties.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class.getName());
+            properties.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, VelocityEndpoint.class.getName());
 
-            // load the velocity properties from property file
+            // load the velocity properties from property file which may overrides the default ones
             if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
                 InputStream reader = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(), getPropertiesFile());
                 try {
@@ -83,17 +94,6 @@ public class VelocityEndpoint extends Re
                 }
             }
 
-            // set the class resolver as a property so we can access it from CamelVelocityClasspathResourceLoader
-            velocityEngine.addProperty("CamelClassResolver", getCamelContext().getClassResolver());
-
-            // set regular properties
-            properties.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, isLoaderCache() ? "true" : "false");
-            properties.setProperty(Velocity.RESOURCE_LOADER, "file, class");
-            properties.setProperty("class.resource.loader.description", "Camel Velocity Classpath Resource Loader");
-            properties.setProperty("class.resource.loader.class", CamelVelocityClasspathResourceLoader.class.getName());
-            properties.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class.getName());
-            properties.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, VelocityEndpoint.class.getName());
-
             log.debug("Initializing VelocityEngine with properties {}", properties);
             // help the velocityEngine to load the CamelVelocityClasspathResourceLoader 
             ClassLoader old = Thread.currentThread().getContextClassLoader();

Added: camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityOverridesPropertiesTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityOverridesPropertiesTest.java?rev=1231590&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityOverridesPropertiesTest.java (added)
+++ camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityOverridesPropertiesTest.java Sat Jan 14 22:20:15 2012
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.velocity;
+
+import java.io.FileInputStream;
+import java.util.logging.FileHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+public class VelocityOverridesPropertiesTest extends CamelTestSupport {
+    
+    @Test
+    public void testOverridingProperties() throws Exception {
+        Logger logger = Logger.getLogger("org.apache.camel.component.velocity");
+        FileHandler fh = new FileHandler("target/camel-velocity-jdk-test.log");
+        logger.addHandler(fh);
+        logger.setLevel(Level.ALL);
+        
+        Exchange exchange = template.request("direct:a", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Monday");
+                exchange.getIn().setHeader("name", "Christian");
+                exchange.setProperty("item", "7");
+            }
+        });
+
+        assertEquals("Dear Christian. You ordered item 7 on Monday.", exchange.getOut().getBody());
+        assertEquals("Christian", exchange.getOut().getHeader("name"));
+        
+        String logContent = IOUtils.toString(new FileInputStream("target/camel-velocity-jdk-test.log"), "UTF-8");
+        assertTrue(logContent.contains("JdkLogChute will use logger 'org.apache.camel.component.velocity.VelocityEndpoint' at level 'FINEST'"));
+        assertTrue(logContent.contains("Using logger class org.apache.velocity.runtime.log.JdkLogChute"));
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:a")
+                    .to("velocity:org/apache/camel/component/velocity/example.vm?propertiesFile=org/apache/camel/component/velocity/velocity-logging.properties");
+            }
+        };
+    }
+}
\ No newline at end of file

Modified: camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties?rev=1231590&r1=1231589&r2=1231590&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties (original)
+++ camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties Sat Jan 14 22:20:15 2012
@@ -18,18 +18,18 @@
 #
 # The logging properties used during tests..
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
 
 #log4j.logger.org.apache.camel.component.velocity=DEBUG
 
 # CONSOLE appender not used by default
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-
-# File appender
-log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out=org.apache.log4j.ConsoleAppender
 log4j.appender.out.layout=org.apache.log4j.PatternLayout
 log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-log4j.appender.out.file=target/camel-velocity-test.log
-log4j.appender.out.append=true
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-velocity-test.log
+log4j.appender.file.append=true

Copied: camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity-logging.properties (from r1231137, camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties)
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity-logging.properties?p2=camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity-logging.properties&p1=camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties&r1=1231137&r2=1231590&rev=1231590&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/log4j.properties (original)
+++ camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity-logging.properties Sat Jan 14 22:20:15 2012
@@ -1,35 +1,20 @@
-## ---------------------------------------------------------------------------
+## ------------------------------------------------------------------------
 ## Licensed to the Apache Software Foundation (ASF) under one or more
 ## contributor license agreements.  See the NOTICE file distributed with
 ## this work for additional information regarding copyright ownership.
 ## The ASF licenses this file to You under the Apache License, Version 2.0
 ## (the "License"); you may not use this file except in compliance with
 ## the License.  You may obtain a copy of the License at
-## 
+##
 ## http://www.apache.org/licenses/LICENSE-2.0
-## 
+##
 ## Unless required by applicable law or agreed to in writing, software
 ## distributed under the License is distributed on an "AS IS" BASIS,
 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
-## ---------------------------------------------------------------------------
+## ------------------------------------------------------------------------
 
-#
-# The logging properties used during tests..
-#
-log4j.rootLogger=INFO, out
-
-#log4j.logger.org.apache.camel.component.velocity=DEBUG
-
-# CONSOLE appender not used by default
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-
-# File appender
-log4j.appender.out=org.apache.log4j.FileAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-log4j.appender.out.file=target/camel-velocity-test.log
-log4j.appender.out.append=true
+runtime.log.logsystem.class = org.apache.velocity.runtime.log.JdkLogChute
+runtime.log.logsystem.jdk.logger = org.apache.camel.component.velocity.VelocityEndpoint
+runtime.log.logsystem.jdk.logger.level = FINEST
\ No newline at end of file