Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48424
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 5 Jan 2010 19:53:38 +0000 (19:53 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 5 Jan 2010 19:53:38 +0000 (19:53 +0000)
Based on a patch by Ivan
Ensure that the ObjectNames for the Connectors are always generated using the same method

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@896193 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/Connector.java
java/org/apache/catalina/mbeans/MBeanUtils.java

index 6253e76..10ea6ee 100644 (file)
@@ -932,14 +932,21 @@ public class Connector
 
     protected ObjectName createObjectName(String domain, String type)
             throws MalformedObjectNameException {
-        String encodedAddr = null;
-        if (getProperty("address") != null) {
-            encodedAddr = URLEncoder.encode(getProperty("address").toString());
+        Object addressObj = getProperty("address");
+
+        StringBuilder sb = new StringBuilder(domain);
+        sb.append(":type=");
+        sb.append(type);
+        sb.append(",port=");
+        sb.append(getPort());
+        if (addressObj != null) {
+            String address = addressObj.toString();
+            if (address.length() > 0) {
+                sb.append(",address=");
+                sb.append(ObjectName.quote(address));
+            }
         }
-        String addSuffix = (getProperty("address") == null) ? "" : ",address="
-                + encodedAddr;
-        ObjectName _oname = new ObjectName(domain + ":type=" + type + ",port="
-                + getPort() + addSuffix);
+        ObjectName _oname = new ObjectName(sb.toString());
         return _oname;
     }
 
index a8d7289..ef1ae81 100644 (file)
@@ -461,15 +461,20 @@ public class MBeanUtils {
 
         ObjectName name = null;
         try {
-            String address = (String)
-                IntrospectionUtils.getProperty(connector, "address");
+            Object addressObj = IntrospectionUtils.getProperty(connector, "address");            
             Integer port = (Integer)
                 IntrospectionUtils.getProperty(connector, "port");
+
             StringBuilder sb = new StringBuilder(domain);
             sb.append(":type=Connector");
-            sb.append(",port=" + port);
-            if ((address != null) && (address.length()>0)) {
-                sb.append(",address=" + address);
+            sb.append(",port=");
+            sb.append(port);
+            if (addressObj != null) {
+                String address = addressObj.toString();
+                if (address.length() > 0) {
+                    sb.append(",address=");
+                    sb.append(ObjectName.quote(address));
+                }
             }
             name = new ObjectName(sb.toString());
             return (name);