logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r1480885 - in /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core: config/JSONConfiguration.java config/XMLConfiguration.java net/MulticastDNSAdvertiser.java
Date Fri, 10 May 2013 05:57:09 GMT
Author: sdeboy
Date: Fri May 10 05:57:08 2013
New Revision: 1480885

URL: http://svn.apache.org/r1480885
Log:
Expose the XML or JSON configuration text via the Advertiser mechanism.

MulticastDNSAdvertiser has a limit of 255 bytes for labels and values.  If an entry is greater
than 255 bytes, the entry is now removed prior to publishing.

The log4j configuration content was exceeding this limit.  This limit is specific to Multicast
DNS.

Added a 'location' key, with the location (file path) if it is available

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java?rev=1480885&r1=1480884&r2=1480885&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
Fri May 10 05:57:08 2013
@@ -135,6 +135,10 @@ public class JSONConfiguration extends B
                             advertisedConfiguration.put("content", new String(buffer));
                             advertisedConfiguration.put("contentType", "application/json");
                             advertisedConfiguration.put("name", "configuration");
+                            if (configSource.getLocation() != null)
+                            {
+                                advertisedConfiguration.put("location", configSource.getLocation());
+                            }
                         }
                     }
                 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1480885&r1=1480884&r2=1480885&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
Fri May 10 05:57:08 2013
@@ -160,6 +160,10 @@ public class XMLConfiguration extends Ba
                                 advertisedConfiguration.put("content", new String(buffer));
                                 advertisedConfiguration.put("contentType", "text/xml");
                                 advertisedConfiguration.put("name", "configuration");
+                                if (configSource.getLocation() != null)
+                                {
+                                    advertisedConfiguration.put("location", configSource.getLocation());
+                                }
                             } catch (InstantiationException e) {
                                 System.err.println("InstantiationException attempting to
instantiate advertiser: " + advertiserString);
                             } catch (IllegalAccessException e) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java?rev=1480885&r1=1480884&r2=1480885&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java
Fri May 10 05:57:08 2013
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.ne
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 import org.apache.logging.log4j.Logger;
@@ -28,6 +29,9 @@ import org.apache.logging.log4j.status.S
 /**
  * Advertise an entity via ZeroConf/MulticastDNS and the JmDNS library.
  *
+ * The length of property names and values must be 255 bytes or less.  
+ * Entries with names or values larger than 255 bytes will be removed prior to advertisement.
+ *
  */
 @Plugin(name = "multicastdns", category = "Core", elementType = "advertiser", printObject
= false)
 public class MulticastDNSAdvertiser implements Advertiser {
@@ -48,18 +52,29 @@ public class MulticastDNSAdvertiser impl
      * Properties map provided in advertise method must include a "name" entry
      * but may also provide "protocol" (tcp/udp) as well as a "port" entry
      *
+     * The length of property names and values must be 255 bytes or less.  
+     * Entries with names or values larger than 255 bytes will be removed prior to advertisement.
+     * 
      * @param properties the properties representing the entity to advertise
      * @return the object which can be used to unadvertise, or null if advertisement was
unsuccessful
      */
     public Object advertise(Map<String, String> properties) {
         //default to tcp if "protocol" was not set
-        String protocol = properties.get("protocol");
+        Map<String, String> truncatedProperties = new HashMap<String, String>();
+        for (Map.Entry<String, String> entry:properties.entrySet())
+        {
+            if (entry.getKey().length() <= 255 && entry.getValue().length() <=
255)
+            {
+                truncatedProperties.put(entry.getKey(), entry.getValue());
+            }
+        }
+        String protocol = truncatedProperties.get("protocol");
         String zone = "._log4j._"+(protocol != null ? protocol : "tcp") + ".local.";
         //default to 4555 if "port" was not set
-        String portString = properties.get("port");
+        String portString = truncatedProperties.get("port");
         int port = (portString != null ? Integer.parseInt(portString) : 4555);
 
-        String name = properties.get("name");
+        String name = truncatedProperties.get("name");
 
         //if version 3 is available, use it to construct a serviceInfo instance, otherwise
support the version1 API
         if (jmDNS != null)
@@ -72,12 +87,11 @@ public class MulticastDNSAdvertiser impl
             } catch (NoSuchMethodException e) {
                 //no-op
             }
-            System.out.println("building: " + zone);
             Object serviceInfo;
             if (isVersion3) {
-                serviceInfo = buildServiceInfoVersion3(zone, port, name, properties);
+                serviceInfo = buildServiceInfoVersion3(zone, port, name, truncatedProperties);
             } else {
-                serviceInfo = buildServiceInfoVersion1(zone, port, name, properties);
+                serviceInfo = buildServiceInfoVersion1(zone, port, name, truncatedProperties);
             }
 
             try {



Mime
View raw message