fix review

Signed-off-by: slievrly <slievrly@163.com>
This commit is contained in:
slievrly 2019-06-25 21:42:13 +08:00
parent e01a44702b
commit f17f40e0af
5 changed files with 45 additions and 34 deletions

View File

@ -22,6 +22,7 @@ import com.alibaba.nacos.api.config.filter.IConfigFilterChain;
import com.alibaba.nacos.api.config.filter.IConfigRequest; import com.alibaba.nacos.api.config.filter.IConfigRequest;
import com.alibaba.nacos.api.config.filter.IConfigResponse; import com.alibaba.nacos.api.config.filter.IConfigResponse;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
/** /**
@ -72,8 +73,7 @@ public class ConfigFilterChainManager implements IConfigFilterChain {
@Override @Override
public void doFilter(final IConfigRequest request, final IConfigResponse response) throws NacosException { public void doFilter(final IConfigRequest request, final IConfigResponse response) throws NacosException {
if (this.currentPosition == this.additionalFilters.size()) { if (this.currentPosition != this.additionalFilters.size()) {
} else {
this.currentPosition++; this.currentPosition++;
IConfigFilter nextFilter = this.additionalFilters.get(this.currentPosition - 1); IConfigFilter nextFilter = this.additionalFilters.get(this.currentPosition - 1);
nextFilter.doFilter(request, response, this); nextFilter.doFilter(request, response, this);

View File

@ -15,21 +15,31 @@
*/ */
package com.alibaba.nacos.client.config.impl; package com.alibaba.nacos.client.config.impl;
import java.io.IOException;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.SystemPropertyKeyConst; import com.alibaba.nacos.api.SystemPropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent; import com.alibaba.nacos.client.config.impl.EventDispatcher.ServerlistChangeEvent;
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult; import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
import com.alibaba.nacos.client.config.utils.IOUtils; import com.alibaba.nacos.client.config.utils.IOUtils;
import com.alibaba.nacos.client.utils.*; import com.alibaba.nacos.client.utils.EnvUtil;
import org.slf4j.Logger; import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.ParamUtil;
import com.alibaba.nacos.client.utils.StringUtils;
import com.alibaba.nacos.client.utils.TemplateUtils;
import java.io.IOException; import org.slf4j.Logger;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
/** /**
* Serverlist Manager * Serverlist Manager
@ -284,8 +294,7 @@ public class ServerListManager {
List<String> lines = IOUtils.readLines(new StringReader(httpResult.content)); List<String> lines = IOUtils.readLines(new StringReader(httpResult.content));
List<String> result = new ArrayList<String>(lines.size()); List<String> result = new ArrayList<String>(lines.size());
for (String serverAddr : lines) { for (String serverAddr : lines) {
if (null == serverAddr || serverAddr.trim().isEmpty()) { if (org.apache.commons.lang3.StringUtils.isNotBlank(serverAddr)) {
} else {
String[] ipPort = serverAddr.trim().split(":"); String[] ipPort = serverAddr.trim().split(":");
String ip = ipPort[0].trim(); String ip = ipPort[0].trim();
if (ipPort.length == 1) { if (ipPort.length == 1) {

View File

@ -43,9 +43,7 @@ public class ParamUtils {
int length = param.length(); int length = param.length();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
char ch = param.charAt(i); char ch = param.charAt(i);
if (Character.isLetterOrDigit(ch)) { if (!Character.isLetterOrDigit(ch) && !isValidChar(ch)) {
} else if (isValidChar(ch)) {
} else {
return false; return false;
} }
} }

View File

@ -15,6 +15,20 @@
*/ */
package com.alibaba.nacos.config.server.service; package com.alibaba.nacos.config.server.service;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.nacos.config.server.constant.Constants; import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.monitor.MetricsMonitor; import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
import com.alibaba.nacos.config.server.service.notify.NotifyService; import com.alibaba.nacos.config.server.service.notify.NotifyService;
@ -23,6 +37,7 @@ import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.PropertyUtil; import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.config.server.utils.RunningConfigUtils; import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher; import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -39,20 +54,11 @@ import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct; import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
import javax.servlet.ServletContext; import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import static com.alibaba.nacos.core.utils.SystemUtils.LOCAL_IP; import static com.alibaba.nacos.core.utils.SystemUtils.LOCAL_IP;
import static com.alibaba.nacos.core.utils.SystemUtils.STANDALONE_MODE; import static com.alibaba.nacos.core.utils.SystemUtils.STANDALONE_MODE;
import static com.alibaba.nacos.core.utils.SystemUtils.readClusterConf; import static com.alibaba.nacos.core.utils.SystemUtils.readClusterConf;
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
/** /**
* Serverlist service * Serverlist service
@ -261,8 +267,7 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
List<String> lines = IOUtils.readLines(new StringReader(result.content)); List<String> lines = IOUtils.readLines(new StringReader(result.content));
List<String> ips = new ArrayList<String>(lines.size()); List<String> ips = new ArrayList<String>(lines.size());
for (String serverAddr : lines) { for (String serverAddr : lines) {
if (null == serverAddr || serverAddr.trim().isEmpty()) { if (StringUtils.isNotBlank(serverAddr)) {
} else {
ips.add(getFormatServerAddr(serverAddr)); ips.add(getFormatServerAddr(serverAddr));
} }
} }

View File

@ -15,11 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import com.alibaba.nacos.config.server.exception.NacosException;
import org.apache.commons.lang3.StringUtils;
import java.util.Map; import java.util.Map;
import com.alibaba.nacos.config.server.exception.NacosException;
import org.apache.commons.lang3.StringUtils;
/** /**
* 参数合法性检查工具类 * 参数合法性检查工具类
* *
@ -46,9 +47,7 @@ public class ParamUtils {
int length = param.length(); int length = param.length();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
char ch = param.charAt(i); char ch = param.charAt(i);
if (Character.isLetterOrDigit(ch)) { if (!Character.isLetterOrDigit(ch) && !isValidChar(ch)) {
} else if (isValidChar(ch)) {
} else {
return false; return false;
} }
} }