Repository: pinpoint-apm/pinpoint
Issue: Extended URL matcher function
Labels: enhancement


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/MatcherGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/MatcherGroup.java
index bc1d9841120e..be01593f4a70 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/MatcherGroup.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/MatcherGroup.java
@@ -68,6 +68,7 @@ public ServerMatcher match(String value) {
                 return serverMatcher;
             }
         }
+        
         return defaultMatcher;
     }
 
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcher.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcher.java
new file mode 100644
index 000000000000..2a2156e6287d
--- /dev/null
+++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcher.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2014 NAVER Corp.
+ *
+ * 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 com.navercorp.pinpoint.web.applicationmap.link;
+
+/**
+ * @author minwoo.jung
+ */
+public class PostfixServerMatcher implements ServerMatcher {
+
+    public final String postfix;
+    public final String url;
+    public final String linkName;
+    
+    public PostfixServerMatcher(String postfix, String url, String linkName) {
+        this.postfix = postfix;
+        this.url = url;
+        this.linkName = linkName;
+    }
+    
+    @Override
+    public boolean isMatched(String value) {
+        if (value == null) {
+            return false;
+        }
+        return value.endsWith(postfix);
+    }
+
+    @Override
+    public String getLinkName() {
+        return linkName;
+    }
+
+    @Override
+    public String getLink(String value) {
+        final int index = value.lastIndexOf(postfix);
+        
+        if (index == -1) {
+            throw new IllegalArgumentException("invalid serverName:" + value);
+        }
+        
+        String hostName = value.substring(0, index);
+        return url + hostName;
+    }
+}


Test patch:
diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcherTest.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcherTest.java
new file mode 100644
index 000000000000..e09c02f0fc7f
--- /dev/null
+++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcherTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2014 NAVER Corp.
+ *
+ * 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 com.navercorp.pinpoint.web.applicationmap.link;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ * @author minwoo.jung
+ */
+public class PostfixServerMatcherTest {
+
+    @Test
+    public void test() {
+        String url = "http://naver.com/";
+        String postfix = ".seoul.idc";
+        PostfixServerMatcher matcher = new PostfixServerMatcher(postfix, url, "NAVER");
+        
+        String serverName = "naverServer01";
+        assertTrue(matcher.isMatched(serverName + postfix));
+        assertFalse(matcher.isMatched("naverserver" + "busan.idc"));
+        
+        assertEquals(url + serverName, matcher.getLink(serverName + postfix));
+    }
+
+}