backport #732 FilterWizard bug fix. incorrect agent mapping 
backport #732

web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilder.java web/src/main/java/com/navercorp/pinpoint/web/applicationmap/Node.java web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceList.java web/src/main/java/com/navercorp/pinpoint/web/controller/BusinessTransactionController.java web/src/main/java/com/navercorp/pinpoint/web/view/LinkSerializer.java
web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilder.java web/src/main/java/com/navercorp/pinpoint/web/applicationmap/Node.java web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceList.java web/src/main/java/com/navercorp/pinpoint/web/controller/BusinessTransactionController.java web/src/main/java/com/navercorp/pinpoint/web/view/LinkSerializer.java
web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilder.java
index aaa0dd4b4faa..8b81b41fb3d1 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilder.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilder.java
@@ -384,6 +384,9 @@ private void appendServerInfo(Node node, LinkDataDuplexMap linkDataDuplexMap, Ag
         } else if (nodeServiceType.isWas()) {
             Set<AgentInfoBo> agentList = agentInfoService.selectAgent(node.getApplication().getName(), range);
             if (agentList.isEmpty()) {
+                logger.warn("agentInfo not found. applicationName:{}", node.getApplication());
+                // avoid NPE
+                node.setServerInstanceList(new ServerInstanceList());
                 return;
             }
             logger.debug("add agentInfo. {}, {}", node.getApplication(), agentList);
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/Node.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/Node.java
index 5d9fa0780bb1..f22b0b645668 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/Node.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/Node.java
@@ -43,8 +43,8 @@ public class Node {
     public static final String NODE_DELIMITER = "^";
 
     private final Application application;
-
-    private ServerInstanceList serverInstanceList;
+    // avoid NPE
+    private ServerInstanceList serverInstanceList = new ServerInstanceList();
 
     private NodeHistogram nodeHistogram;
 
@@ -74,8 +74,11 @@ public String getApplicationTextName() {
         }
     }
 
-
+    // TODO remove setter
     public void setServerInstanceList(ServerInstanceList serverInstanceList) {
+        if (serverInstanceList == null) {
+            throw new NullPointerException("serverInstanceList must not be null");
+        }
         this.serverInstanceList = serverInstanceList;
     }
 
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java
index 5ac29c4824df..bade9a8a2288 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java
@@ -37,11 +37,17 @@ public class ServerBuilder {
 
     private final AgentHistogramList agentHistogramList;
     private final Set<AgentInfoBo> agentSet;
-    private MatcherGroup matcherGroup = null;
+    private final MatcherGroup matcherGroup;
+
+    public ServerBuilder() {
+        // TODO FIX
+        this(null);
+    }
 
     public ServerBuilder(MatcherGroup matcherGroup) {
         this.agentHistogramList = new AgentHistogramList();
         this.agentSet = new HashSet<AgentInfoBo>();
+        // TODO avoid null
         this.matcherGroup = matcherGroup;
     }
 
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceList.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceList.java
index c90bcc6bdfd1..eb337295f007 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceList.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceList.java
@@ -16,12 +16,9 @@
 
 package com.navercorp.pinpoint.web.applicationmap;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
+import java.util.*;
 
+import com.navercorp.pinpoint.common.bo.AgentInfoBo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,6 +55,19 @@ public Map<String, List<ServerInstance>> getServerInstanceList() {
         return serverInstanceList;
     }
 
+    public List<String> getAgentIdList() {
+        final Collection<List<ServerInstance>> serverInstanceValueList = this.serverInstanceList.values();
+
+        final List<String> agentList = new ArrayList<String>();
+        for (List<ServerInstance> serverInstanceList : serverInstanceValueList) {
+            for (ServerInstance serverInstance : serverInstanceList) {
+                AgentInfoBo agentInfo = serverInstance.getAgentInfo();
+                agentList.add(agentInfo.getAgentId());
+            }
+        }
+        return agentList;
+    }
+
     public int getInstanceCount() {
         int count = 0;
         for (List<ServerInstance> entry : serverInstanceList.values()) {
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/BusinessTransactionController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/BusinessTransactionController.java
index 015af8204c1a..bf7973ec164e 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/controller/BusinessTransactionController.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/BusinessTransactionController.java
@@ -178,6 +178,7 @@ public ModelAndView transactionInfo(@RequestParam("traceId") String traceIdParam
 
 
         if (viewVersion == 2) {
+            // TODO remove hashformat
             mv.setViewName("transactionInfoJsonHash");
         } else {
             mv.setViewName("transactionInfoJson");
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/LinkSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/LinkSerializer.java
index df10cb70ef6e..622e02ca656d 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/view/LinkSerializer.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/view/LinkSerializer.java
@@ -18,6 +18,7 @@
 
 import com.navercorp.pinpoint.web.applicationmap.Link;
 import com.navercorp.pinpoint.web.applicationmap.Node;
+import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList;
 import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
 import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogram;
 import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogramList;
@@ -45,6 +46,9 @@ public void serialize(Link link, JsonGenerator jgen, SerializerProvider provider
         jgen.writeStringField("from", link.getFrom().getNodeName());  // necessary for go.js
         jgen.writeStringField("to", link.getTo().getNodeName()); // necessary for go.js
 
+        // for FilterWizard. from, to agent mapping data
+        writeAgentId("fromAgent", link.getFrom(), jgen);
+        writeAgentId("toAgent", link.getTo(), jgen);
 
         writeSimpleNode("sourceInfo", link.getFrom(), jgen);
         writeSimpleNode("targetInfo", link.getTo(), jgen);
@@ -79,6 +83,20 @@ public void serialize(Link link, JsonGenerator jgen, SerializerProvider provider
         jgen.writeEndObject();
     }
 
+    private void writeAgentId(String fieldName, Node node, JsonGenerator jgen) throws IOException {
+        if (node.getServiceType().isWas()) {
+            jgen.writeFieldName(fieldName);
+            jgen.writeStartArray();
+            ServerInstanceList serverInstanceList = node.getServerInstanceList();
+            if (serverInstanceList!= null) {
+                for (String agentId : serverInstanceList.getAgentIdList()) {
+                    jgen.writeObject(agentId);
+                }
+            }
+            jgen.writeEndArray();
+        }
+    }
+
     private void writeWasToWasTargetRpcList(Link link, JsonGenerator jgen) throws IOException {
         // write additional information to be used for filtering failed WAS -> WAS call events.
         jgen.writeFieldName("filterTargetRpcList");

diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java
new file mode 100644
index 000000000000..fad0981ab419
--- /dev/null
+++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import com.navercorp.pinpoint.common.bo.AgentInfoBo;
+import com.navercorp.pinpoint.common.ServiceType;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author emeroad
+ */
+public class ServerInstanceListTest {
+
+    @Test
+    public void testGetAgentIdList() throws Exception {
+
+        AgentInfoBo agentInfoBo1 = createAgentInfo("agentId1", "testHost");
+        AgentInfoBo agentInfoBo2 = createAgentInfo("agentId2", "testHost");
+
+        Set<AgentInfoBo> agentInfoBoSet = new HashSet<AgentInfoBo>();
+        agentInfoBoSet.add(agentInfoBo1);
+        agentInfoBoSet.add(agentInfoBo2);
+
+        ServerBuilder builder = new ServerBuilder();
+        builder.addAgentInfo(agentInfoBoSet);
+        ServerInstanceList serverInstanceList = builder.build();
+        List<String> agentIdList = serverInstanceList.getAgentIdList();
+
+        Assert.assertEquals(agentIdList.size(), 2);
+        Assert.assertEquals(agentIdList.get(0), "agentId1");
+        Assert.assertEquals(agentIdList.get(1), "agentId2");
+    }
+
+    public static AgentInfoBo createAgentInfo(String agentId, String hostName) {
+        AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder();
+        agentInfoBuilder.agentId(agentId);
+
+        ServiceType serviceType = ServiceType.TEST_STAND_ALONE;
+        agentInfoBuilder.serviceType(serviceType);
+
+        agentInfoBuilder.hostName(hostName);
+
+        return agentInfoBuilder.build();
+    }
+}
\ No newline at end of file
diff --git a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java
index d4e630242d36..c8f23b77e289 100644
--- a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java
+++ b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java
@@ -16,18 +16,18 @@
 
 package com.navercorp.pinpoint.web.view;
 
-import com.navercorp.pinpoint.common.ServiceType;
-import com.navercorp.pinpoint.common.bo.AgentInfoBo;
-import com.navercorp.pinpoint.web.applicationmap.ServerBuilder;
-import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList;
+import java.util.HashSet;
 
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.ObjectWriter;
+import com.navercorp.pinpoint.web.applicationmap.ServerInstanceListTest;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.HashSet;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.navercorp.pinpoint.common.bo.AgentInfoBo;
+import com.navercorp.pinpoint.web.applicationmap.ServerBuilder;
+import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList;
 
 /**
  * @author emeroad
@@ -39,18 +39,15 @@ public class ServerInstanceListSerializerTest {
 
     @Test
     public void testSerialize() throws Exception {
-        AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder();
-        agentInfoBuilder.agentId("agentId");
-        agentInfoBuilder.serviceType(ServiceType.TOMCAT);
-        agentInfoBuilder.hostName("testcomputer");
+        AgentInfoBo agentInfoBo = ServerInstanceListTest.createAgentInfo("agentId1", "testHost");
 
-        AgentInfoBo agentInfoBo = agentInfoBuilder.build();
+        HashSet<AgentInfoBo> agentInfoBoSet = new HashSet<AgentInfoBo>();
+        agentInfoBoSet.add(agentInfoBo);
 
-        HashSet<AgentInfoBo> set = new HashSet<AgentInfoBo>();
-        set.add(agentInfoBo);
 
         ServerBuilder builder = new ServerBuilder(null);
-        builder.addAgentInfo(set);
+        builder.addAgentInfo(agentInfoBoSet);
+        
         ServerInstanceList serverInstanceList = builder.build();
         ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter();
         String json = objectWriter.writeValueAsString(serverInstanceList);
