Commit 6c52269d by saga Committed by Ryan Baxter

Associated with this PR # 2466 (#2470)

Use StringBuffer for String concatenation
parent 736a3e46
......@@ -49,6 +49,7 @@ import com.netflix.eureka.util.StatusInfo;
/**
* @author Spencer Gibb
* @author Gang Li
*/
@Controller
@RequestMapping("${eureka.dashboard.path:/}")
......@@ -287,12 +288,12 @@ public class EurekaController {
private String scrubBasicAuth(String urlList){
String[] urls=urlList.split(",");
String filteredUrls="";
StringBuilder filteredUrls = new StringBuilder();
for(String u : urls){
if(u.contains("@")){
filteredUrls+=u.substring(0,u.indexOf("//")+2)+u.substring(u.indexOf("@")+1,u.length())+",";
filteredUrls.append(u.substring(0,u.indexOf("//")+2)).append(u.substring(u.indexOf("@")+1,u.length())).append(",");
}else{
filteredUrls+=u+",";
filteredUrls.append(u).append(",");
}
}
return filteredUrls.substring(0,filteredUrls.length()-1);
......
......@@ -23,6 +23,15 @@ public class EurekaControllerReplicasTests {
String authList1 = "http://user:pwd@test1.com";
String authList2 = authList1 + ",http://user2:pwd2@test2.com";
String combinationAuthList1 = "http://test1.com,http://user2:pwd2@test2.com";
String combinationAuthList2 = "http://test3.com,http://user4:pwd4@test4.com";
String combinationNoAuthList1 = "http://test1.com,http://test2.com";
String combinationNoAuthList2 = "http://test3.com,http://test4.com";
String totalAutoList = combinationAuthList1 + "," + combinationAuthList2;
String totalNoAutoList = combinationNoAuthList1 + "," + combinationNoAuthList2;
String empty = new String();
private ApplicationInfoManager original;
......@@ -81,4 +90,24 @@ public class EurekaControllerReplicasTests {
}
@Test
public void testFilterReplicasAuthWithCombinationList() throws Exception {
Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
.add("registered-replicas", totalAutoList)
.add("available-replicas", combinationAuthList1)
.add("unavailable-replicas", combinationAuthList2)
.withInstanceInfo(instanceInfo).build();
EurekaController controller = new EurekaController(null);
controller.filterReplicas(model, statusInfo);
@SuppressWarnings("unchecked")
Map<String, String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(totalNoAutoList, results.get("registered-replicas"));
assertEquals(combinationNoAuthList1, results.get("available-replicas"));
assertEquals(combinationNoAuthList2, results.get("unavailable-replicas"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment