Index: admin/monitor/src/main/java/org/glassfish/flashlight/datatree/impl/AbstractTreeNode.java =================================================================== --- admin/monitor/src/main/java/org/glassfish/flashlight/datatree/impl/AbstractTreeNode.java (revision 43960) +++ admin/monitor/src/main/java/org/glassfish/flashlight/datatree/impl/AbstractTreeNode.java (working copy) @@ -45,6 +45,7 @@ package org.glassfish.flashlight.datatree.impl; import com.sun.enterprise.util.ObjectAnalyzer; +import static com.sun.enterprise.util.SystemPropertyConstants.MONDOT; import static com.sun.enterprise.util.SystemPropertyConstants.SLASH; import org.glassfish.flashlight.datatree.TreeNode; import java.util.*; @@ -55,6 +56,10 @@ /** * * @author Harpreet Singh + * @author Byron Nevins + * 12/18/2010 -- Added encode/decode. Note that the encoded form for a dot is + * NOT something like "\\." -- there is too much code around making assumptions + * about dots, splitting strings, etc. So we replace with ___MONDOT___ */ public abstract class AbstractTreeNode implements TreeNode, Comparable { @@ -77,16 +82,17 @@ @Override public String getName() { - return this.name; + + return decodeName(); } @Override - public void setName(String name) { - if (name == null) { + public void setName(String aname) { + + if (aname == null) throw new RuntimeException("Flashlight-utils: Tree Node needs a" + " non-null name"); - } - this.name = name; + name = encodeNodeName(aname); } // should be implemented at the sub-class level @@ -217,27 +223,37 @@ @Override public TreeNode getNode(String completeName) { - if (completeName == null) { return null; } + completeName = encodePath(completeName); Pattern pattern = Pattern.compile(AbstractTreeNode.REGEX); String[] tokens = pattern.split(completeName); TreeNode n = findNodeInTree(tokens); return n; } + // confused? That's expected! This should be refactored/re-done for 3.2 + // we store dots and slashes encoded. THe tokens coming in to this method + // are encoded. That's because there is lots of other code scattered around + // that looks for these special meta-characters. To be safe I'm storing them + // in the node encoded. + // But the "children" object has keys that come from the getName() of the node + // which is the value. private TreeNode findNodeInTree(String[] tokens) { if (tokens == null) { return null; } TreeNode child = getChild(tokens[0]); - if (child == null) { + + if (child == null) + child = getChild(decodeName(tokens[0])); + + if (child == null) return null; - } - if (tokens.length > 1) { + + if (tokens.length > 1) child = ((AbstractTreeNode) child).findNodeInTree(dropFirstStringToken(tokens)); - } return child; @@ -375,4 +391,26 @@ return node; } + + private String encodeNodeName(String nodeName) { + return nodeName.replace(".", MONDOT).replace("/", SLASH).replace("\\/", SLASH).replace("\\.", MONDOT); + } + + private String encodePath(String thePath) { + // REST encodes (1) to (2) + // aaa bbb.x cccc + // aaa.bbb\\x.cccc + // we want aaa.bbb___MONDOT___x.cccc + + return thePath.replace("\\/", SLASH).replace("\\.", MONDOT); + } + + // todo replace with \\. ??? + private String decodeName() { + return decodeName(name); + } + + private static String decodeName(String s) { + return s.replace(SLASH, "/").replace(MONDOT, "."); + } } Index: admin/rest/src/main/java/org/glassfish/admin/rest/resources/MonitoringResource.java =================================================================== --- admin/rest/src/main/java/org/glassfish/admin/rest/resources/MonitoringResource.java (revision 43921) +++ admin/rest/src/main/java/org/glassfish/admin/rest/resources/MonitoringResource.java (working copy) @@ -173,8 +173,8 @@ String root; int index = dottedName.indexOf('.'); if (index != -1) { - root = dottedName.substring(0, dottedName.indexOf('.')); - dottedName = dottedName.substring(dottedName.indexOf('.') + 1 ); + root = dottedName.substring(0, index); + dottedName = dottedName.substring(index + 1 ); } else { root = dottedName; dottedName = ""; @@ -261,7 +261,9 @@ // Monitoring code escapes "." with "\.". Thus name "order.jar" will be given as "order\.jar". // This would result in URL of form monitoring/domain/server/applications/orderapp/order\.jar for the child resource. This URL is rejected by Grizzly. // Unescape here. Please note that we again introduce the escape before doing a get on monitoringregistry - name = name.replaceAll("\\\\.", "\\."); + + // bnevins 12/18/2010 -- no it does not! The dot comes back as a plain dot. + name = name.replaceAll("\\\\.", "\\.").replace(".", "\\."); links.put(name, getElementLink(uriInfo, name)); }