At 14:49 06.07.2001 -0400, you wrote:
>Ceki,
>
>Your version of the code works fine on my machine. A few comments:
>- I would take out the reference to WebLogic and make it say something like
>"...assuming custom URL", given the fact that it is perfectly legal to
>define custom URLs and associated handlers, in a running envrionment.

OK.

>- I think (but have no way to verify) your code will actually not work
>properly on a Mac, since the file separator there is ':' from what I know,
>not / or \. This is why my code did a
>'System.getProperty("file.separator");' to get the file separator and look
>for that. Thinking about it though, my code was also not correct for a Mac.
>It would look for a file separator ':', but a URL will always have a ':' as
>part of the protocol portion, so that instance would have to be ignored.

I don't think many people are running Application Servers on Macs but that's just my 
impression.

>- The reason I added the other extra code in Category.java was to not even
>consider the ref as a possible class name in the case of the URL coming back
>from a classloader. In this case we know _for sure_ the ref (if it exists at
>all) is not a classname, so we will get in less trouble if we don't even
>look at it and possibly mistake it for one. Given the fact that it is
>perfectly legal for other classloaders to return customs URLs with other
>special handling of the ref field (and our adding the classname there is
>somewhat of a hack), I thought it was a bit safer to add this extra code.

Err.. you mean in the case the url came from the system properties not from the 
classpath. If I understand correctly, one can assume that the reference part must be 
the fully qualified name of a configurator class in case the URL came from the 
environment. 

IMHO, in practice the extra defensive code does not hurt but does not really help 
either. So for the sake of simplicity I think it's better to leave it out. Regards, 
Ceki   



>----- Original Message -----
>From: "Ceki Gülcü" <[EMAIL PROTECTED]>
>To: "LOG4J Developers Mailing List" <[EMAIL PROTECTED]>
>Sent: Thursday, July 05, 2001 12:54 PM
>Subject: Re: PATCH: modify config file loading to allow custom URL types
>
>
>Colin,
>
>I modified OptionConverter.java as follows:
>
>  static
>  public
>  void selectAndConfigure(URL url, Hierarchy hierarchy) {
>    String clazz = url.getRef();
>
>    if (clazz.indexOf('.') == -1 || clazz.indexOf('/') != -1 ||
>clazz.indexOf('\\') != -1) {
>      LogLog.warn("Suspicious reference part in URL ["+url+
>                  "] will ignore refence part assuming BEA Weblogic
>environment.");
>      clazz = null;
>    }
>
>
>    Configurator configurator = null;
>
>    if(clazz != null) {
>      LogLog.debug("Preferred configurator class: " + clazz);
>    ....
>
>  }
>
>Category.java remains unchanged. Can you please double check that my
>simplified patch works.
>You can get the latest code from our CVS repository. Best regards, Ceki
>
>At 14:20 29.06.2001 +0000, you wrote:
>>(same patch as before, but diffed using -u option...)
>>
>>>As per my previous email with Ceki, this patch modifies the configuration
>file loading code so that while still allowing a 'ref' or anchor portion of
>a URL to specify a class name for a custom configurator, it can also work
>with custom URL schemes such as used in WebLogic to specify a file within an
>archive, e.g.
>>>zip:/part1/part2/whatever.war#WEB-INF/classes/log4j.properties
>>>With the new code, for the ref portion of a URL to be considered a
>classname, it must consist of at least one package element and one classname
>element (e.g. mypackage.Myclass), and must not have the file separator
>character in it. Also, when the URL comes from a classloader as opposed to a
>system properly, the code will never consider the ref to be a classname,
>since that wouldn't make sense (e.g. in this case the ref will always be
>part of a custom URL).
>>
>>Index: Category.java
>>===================================================================
>>RCS file:
>/home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/Category.java,v
>>retrieving revision 1.35
>>diff -w -u -r1.35 Category.java
>>--- Category.java       2001/06/26 19:40:05     1.35
>>+++ Category.java       2001/06/29 14:12:44
>>@@ -131,12 +131,16 @@
>>
>>DEFAULT_CONFIGURATION_KEY,
>>
>DEFAULT_CONFIGURATION_FILE);
>>     URL url = null;
>>+      boolean urlRefMayBeConfigurator = true;
>>     try {
>>-       // so, resource is not a URL:
>>-       // attempt to get the resource from the class path
>>        url = new URL(resource);
>>     } catch (MalformedURLException ex) {
>>+       // if resource is not a URL then
>>+       // attempt to get the resource from the class path
>>        url = Loader.getResource(resource, Category.class);
>>+        // any ref portion in URL returned by classload is specific to
>that URL,
>>+        // not a Configurator class name
>>+        urlRefMayBeConfigurator = false;
>>     }
>>
>>     // If we have a non-null url, then delegate the rest of the
>>@@ -144,7 +148,7 @@
>>     // method.
>>     if(url != null) {
>>        LogLog.debug("Using URL ["+url+"] for automatic log4j
>configuration.");
>>-       OptionConverter.selectAndConfigure(url, defaultHierarchy);
>>+       OptionConverter.selectAndConfigure(url, urlRefMayBeConfigurator,
>defaultHierarchy);
>>     } else {
>>        LogLog.debug("Could not find resource: ["+resource+"].");
>>     }
>>Index: helpers/OptionConverter.java
>>===================================================================
>>RCS file:
>/home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConver
>ter.java,v
>>retrieving revision 1.17
>>diff -w -u -r1.17 OptionConverter.java
>>--- helpers/OptionConverter.java        2001/06/20 07:59:46     1.17
>>+++ helpers/OptionConverter.java        2001/06/29 14:12:45
>>@@ -399,9 +399,16 @@
>> /**
>>    Configure log4j given a URL.
>>-     <p>The URL format is important. Its <em>reference</em> part is
>>-     taken as the class name of the configurator. For example, if you
>>-     invoke your application using the command line
>>+     <p>The URL format is important. If the
><em>urlRefMayBeConfigurator</em>
>>+     param is true, then its <em>reference</em> part (if any) is
>potentially
>>+     considered to be the class name of the configurator. Since the ref
>part
>>+     may also be used by some custom URL types (e.g. to qualify a specific
>file
>>+     within another archive file), for the ref string to be considered a
>class
>>+     name, it must be a fully qualified class name including at least one
>>+     package, and must not contain any file separator characters such as
>'/' or
>>+     '\' since those would never be part of a valid class name, and are a
>strong
>>+     indication of a custom URL type. For example, if you invoke your
>>+     application using the command line
>>    <pre>
>java -Dlog4j.configuration=file:/temp/myconfig.xyz#com.myCompany.myConfigura
>tor
>>    </pre>
>>@@ -412,8 +419,8 @@
>>    configurator you specify <em>must</em> implement the {@link
>>    Configurator} interface.
>>-     <p>If the URL has no reference part, then the {@link
>>-     PropertyConfigurator} will parse the URL. However, if the URL
>>+     <p>If no configurator is specified via a URL reference part, then the
>>+     {@link PropertyConfigurator} will parse the URL. However, if the URL
>>    ends with a ".xml" extension, then the {@link DOMConfigurator}
>>    will be used to parse the URL.
>>@@ -425,12 +432,29 @@
>>    @since 1.0 */
>> static
>> public
>>-  void selectAndConfigure(URL url, Hierarchy hierarchy) {
>>-    String clazz = url.getRef();
>>+  void selectAndConfigure(URL url, boolean urlRefMayBeConfigurator,
>>+                          Hierarchy hierarchy) {
>>+
>>+    // assume a 'ref' portion of a URL may be Configurator class
>>+    String clazz = null;
>>+    if (urlRefMayBeConfigurator) {
>>+      clazz = url.getRef();
>>+      if (clazz != null) {
>>+        String fileSep = "/";
>>+        try { fileSep = System.getProperty("file.separator"); }
>catch(Exception e) {}
>>+        // it's only a class name if it has a period somewhere in it, and
>it's
>>+        // not a class name if it has a file separator (explicitly check
>both
>>+        // unix and windows versions since Java itself will always allow
>them
>>+        // regardless of actual platform)
>>+        if (clazz.indexOf('.') == -1 || clazz.indexOf(fileSep) != -1 ||
>>+            clazz.indexOf('/') != -1 || clazz.indexOf('\\') != -1)
>>+          clazz = null;
>>+      }
>>+    }
>>   Configurator configurator = null;
>>-    if(clazz != null) {
>>+    if (clazz != null && clazz.length() > 0) {
>>     LogLog.debug("Preferred configurator class: " + clazz);
>>     configurator = (Configurator) instantiateByClassName(clazz,
>>
>Configurator.class,
>>@@ -440,6 +464,11 @@
>>        return;
>>     }
>>   } else {
>>+      // hmm, this test is actually no longer valid if we have a custom
>URL type
>>+      // such as:
>>+      // 'zip:/a/b/c/d.war#e/f/log4j.properties'
>>+      // which is what a custom classloader like WebLogic's may return as
>a URL
>>+      // reference to a file inside of an archive
>>     String filename = url.getFile();
>>     if(filename != null && filename.endsWith(".xml")) {
>>        try {
>>@@ -455,4 +484,16 @@
>>   configurator.doConfigure(url, hierarchy);
>> }
>>+
>>+
>>+  /**
>>+     Configure log4j given a URL.
>>+     This method signature maintained for compatibility
>>+   */
>>+  static
>>+  public
>>+  void selectAndConfigure(URL url, Hierarchy hierarchy) {
>>+    selectAndConfigure(url, true, hierarchy);
>>+  }
>>+
>>}
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
>--
>Ceki Gülcü
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

--
Ceki Gülcü


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to