ceki 2004/05/20 04:49:08 Modified: tests/input/db read-with-pooled-datasource1.xml read-with-datasource1.xml src/java/org/apache/joran ExecutionContext.java tests build.xml build.properties.sample src/java/org/apache/log4j/db JNDIConnectionSource.java Added: tests/input/db append-with-jndi1.xml read-with-jndi1.xml tests/src/java/org/apache/log4j/db BindDataSourceToJNDIAction.java Removed: tests/input/db appendPooled1.xml Log: Testing JNDIConnectionSource with actual JNDI context.
This test requires the existence of a JNDI provider, for example the "File System Service Provider 1.2 Beta 3". Revision Changes Path 1.2 +1 -4 logging-log4j/tests/input/db/read-with-pooled-datasource1.xml Index: read-with-pooled-datasource1.xml =================================================================== RCS file: /home/cvs/logging-log4j/tests/input/db/read-with-pooled-datasource1.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- read-with-pooled-datasource1.xml 19 May 2004 17:58:09 -0000 1.1 +++ read-with-pooled-datasource1.xml 20 May 2004 11:49:07 -0000 1.2 @@ -4,10 +4,7 @@ <log4j:configuration debug="true"> <substitutionProperty file="input/db/db.properties"/> - - <substitutionProperty file="input/db/db.properties"/> - - + <plugin name="DBPlugin" class="org.apache.log4j.db.DBReceiver"> <connectionSource class="org.apache.log4j.db.DataSourceConnectionSource"> 1.2 +6 -2 logging-log4j/tests/input/db/read-with-datasource1.xml Index: read-with-datasource1.xml =================================================================== RCS file: /home/cvs/logging-log4j/tests/input/db/read-with-datasource1.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- read-with-datasource1.xml 18 May 2004 16:50:43 -0000 1.1 +++ read-with-datasource1.xml 20 May 2004 11:49:07 -0000 1.2 @@ -5,8 +5,12 @@ <substitutionProperty file="input/db/db.properties"/> - <substitutionProperty file="input/db/db.properties"/> - + <!-- We create a joran rule that will instance and bind the appropriate + data source instance to JNDI. --> + <newRule pattern="log4j:configuration/bindDataSourceToJNDI" + actionClass="org.apache.log4j.db.BindDataSourceToJNDIAction"/> + + <bindDataSourceToJNDI /> <plugin name="DBPlugin" class="org.apache.log4j.db.DBReceiver"> <connectionSource class="org.apache.log4j.db.DataSourceConnectionSource"> 1.1 logging-log4j/tests/input/db/append-with-jndi1.xml Index: append-with-jndi1.xml =================================================================== <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration> <log4j:configuration debug="true"> <substitutionProperty file="input/db/db.properties"/> <!-- We create a joran rule that will instance and bind the appropriate data source instance to JNDI. --> <newRule pattern="log4j:configuration/bindDataSourceToJNDI" actionClass="org.apache.log4j.db.BindDataSourceToJNDIAction"/> <bindDataSourceToJNDI /> <appender name="DB" class="org.apache.log4j.db.DBAppender"> <connectionSource class="org.apache.log4j.db.DataSourceConnectionSource"> <dataSource class="${dataSourceClass}"> <param name="url" value="${url}"/> <param name="serverName" value="${serverName}"/> <param name="databaseName" value="${databaseName}"/> </dataSource> <param name="user" value="${user}"/> <param name="password" value="${password}"/> </connectionSource> </appender> <appender name="VECTOR" class="org.apache.log4j.VectorAppender"> </appender> <root> <level value ="debug"/> <appender-ref ref="DB" /> <appender-ref ref="VECTOR" /> </root> </log4j:configuration> 1.1 logging-log4j/tests/input/db/read-with-jndi1.xml Index: read-with-jndi1.xml =================================================================== <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration> <log4j:configuration debug="true"> <substitutionProperty file="input/db/db.properties"/> <plugin name="DBPlugin" class="org.apache.log4j.db.DBReceiver"> <connectionSource class="org.apache.log4j.db.DataSourceConnectionSource"> <dataSource class="${dataSourceClass}"> <param name="url" value="${url}"/> <param name="serverName" value="${serverName}"/> <param name="databaseName" value="${databaseName}"/> </dataSource> <param name="user" value="${user}"/> <param name="password" value="${password}"/> </connectionSource> </plugin> <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="READING %relative %level %logger - %message%n"/> </layout> </appender> <appender name="VECTOR" class="org.apache.log4j.VectorAppender"> </appender> <root> <level value="debug"/> <appender-ref ref="VECTOR" /> <appender-ref ref="CONSOLE" /> </root> </log4j:configuration> 1.10 +4 -0 logging-log4j/src/java/org/apache/joran/ExecutionContext.java Index: ExecutionContext.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/joran/ExecutionContext.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ExecutionContext.java 18 May 2004 16:50:43 -0000 1.9 +++ ExecutionContext.java 20 May 2004 11:49:07 -0000 1.10 @@ -139,6 +139,10 @@ addProperty(key, props.getProperty(key)); } } + + public String getSubstitutionProperty(String key) { + return substitutionProperties.getProperty(key); + } public String subst(String value) { if(value == null) { 1.56 +9 -3 logging-log4j/tests/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/logging-log4j/tests/build.xml,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- build.xml 19 May 2004 17:58:09 -0000 1.55 +++ build.xml 20 May 2004 11:49:07 -0000 1.56 @@ -31,7 +31,7 @@ <pathelement location="./classes"/> <pathelement location="./resources"/> <pathelement location="${jakarta.oro.jar}"/> - <fileset dir="./lib/"> + <fileset dir="./lib/"> <include name="*.jar"/> </fileset> </path> @@ -535,7 +535,7 @@ <echo message="MySQL available"/> <copy file="./input/db/mysql.properties" tofile="./input/db/db.properties"/> - <echo message="Running test case with DriverManager config file"/> +<!-- <echo message="Running test case with DriverManager config file"/> <antcall target="DB"> <param name="appendConfigFile" value="./input/db/append-with-drivermanager1.xml"/> <param name="readConfigFile" value="./input/db/read-with-drivermanager1.xml"/> @@ -547,10 +547,16 @@ <param name="readConfigFile" value="./input/db/read-with-datasource1.xml"/> </antcall> - <echo message="Running test case with *pooled* DataSource"/> + <echo message="Running test case with a native *pooled* DataSource"/> <antcall target="DB"> <param name="appendConfigFile" value="./input/db/append-with-pooled-datasource1.xml"/> <param name="readConfigFile" value="./input/db/read-with-pooled-datasource1.xml"/> + </antcall> +--> + <echo message="Running test case with a DataSource with JNDI"/> + <antcall target="DB"> + <param name="appendConfigFile" value="./input/db/append-with-jndi1.xml"/> + <param name="readConfigFile" value="./input/db/read-with-jndi1.xml"/> </antcall> </target> 1.4 +22 -2 logging-log4j/tests/build.properties.sample Index: build.properties.sample =================================================================== RCS file: /home/cvs/logging-log4j/tests/build.properties.sample,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- build.properties.sample 12 Apr 2002 15:11:49 -0000 1.3 +++ build.properties.sample 20 May 2004 11:49:07 -0000 1.4 @@ -1,4 +1,24 @@ -jakarta.oro.jar=../../jakarta-oro-2.0.5/jakarta-oro-2.0.5.jar deprecation=on -# junit must be on the classpath! It can't be handled as a property. +jakarta.oro.jar=../../jakarta-oro-2.0.5/jakarta-oro-2.0.5.jar + + +# junit must be on the classpath or in ANT_HOME/lib. It can't be +# handled as a property. + + +# Database testing +# ================ +# +# For the various DB tests you need to place the appropriate +# JDBC drivers in ./tests/lib/ directory. +# +# Testing JNDIConnectionSource requires JNDI File System Service +# Provider, 1.2 Beta 3, which can be downloaded from: +# +# http://java.sun.com/products/jndi/downloads/index.html +# +# Click on "Download JNDI 1.2.1 & More" +# +# Once you obtained the JNDI File System Service Provider place +# the file fscontext.jar in the ./tests/lib/ directory. \ No newline at end of file 1.4 +5 -5 logging-log4j/src/java/org/apache/log4j/db/JNDIConnectionSource.java Index: JNDIConnectionSource.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/JNDIConnectionSource.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JNDIConnectionSource.java 19 May 2004 17:58:09 -0000 1.3 +++ JNDIConnectionSource.java 20 May 2004 11:49:07 -0000 1.4 @@ -155,11 +155,11 @@ DataSource ds; Hashtable env = new Hashtable(11); - env.put(Context.INITIAL_CONTEXT_FACTORY, - "com.sun.jndi.fscontext.RefFSContextFactory"); - env.put(Context.PROVIDER_URL, - "file:///home/jndi"); - Context ctx = new InitialContext(env); +// env.put(Context.INITIAL_CONTEXT_FACTORY, +// "com.sun.jndi.fscontext.RefFSContextFactory"); +// env.put(Context.PROVIDER_URL, +// "file:///home/jndi"); + Context ctx = new InitialContext(); //Context ctx = new InitialContext(); Object obj = ctx.lookup(jndiLocation); 1.1 logging-log4j/tests/src/java/org/apache/log4j/db/BindDataSourceToJNDIAction.java Index: BindDataSourceToJNDIAction.java =================================================================== /* * Copyright 1999,2004 The Apache Software Foundation. * * Licensed 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.log4j.db; import org.apache.joran.ErrorItem; import org.apache.joran.ExecutionContext; import org.apache.joran.action.Action; import org.apache.joran.helper.Option; import org.apache.log4j.Logger; import org.apache.log4j.config.PropertySetter; import org.apache.log4j.helpers.LogLog; import org.apache.log4j.helpers.OptionConverter; import org.xml.sax.Attributes; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; public class BindDataSourceToJNDIAction extends Action { static final Logger logger = Logger.getLogger(BindDataSourceToJNDIAction.class); static final String DATA_SOURCE_CLASS = "dataSourceClass"; static final String URL = "url"; static final String USER = "user"; static final String PASSWORD = "password"; private boolean inError = false; /** * Instantiates an a data source and bind it to JNDI * Most of the required parameters are placed in the ec.substitutionProperties */ public void begin( ExecutionContext ec, String localName, Attributes attributes) { String dsClassName = ec.getSubstitutionProperty(DATA_SOURCE_CLASS); LogLog.info("==============************************"); if (Option.isEmpty(dsClassName)) { LogLog.warn("dsClassName is a required parameter"); ec.addError(new ErrorItem("dsClassName is a required parameter")); return; } String urlStr = ec.getSubstitutionProperty(URL); String userStr = ec.getSubstitutionProperty(USER); String passwordStr = ec.getSubstitutionProperty(PASSWORD); try { DataSource ds = (DataSource) OptionConverter.instantiateByClassName( dsClassName, DataSource.class, null); PropertySetter setter = new PropertySetter(ds); if (!Option.isEmpty(urlStr)) { setter.setProperty("url", urlStr); } if (!Option.isEmpty(userStr)) { setter.setProperty("user", userStr); } if (!Option.isEmpty(passwordStr)) { setter.setProperty("password", passwordStr); } Context ctx = new InitialContext(); ctx.rebind("dataSource", ds); } catch (Exception oops) { inError = true; logger.error( "Could not bind datasource. Reported error follows.", oops); ec.addError( new ErrorItem( "Could not not bind datasource of type [" + dsClassName + "].")); } } public void end(ExecutionContext ec, String name) { } public void finish(ExecutionContext ec) { } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]