-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE #3224]nacos-client module http client replace #3348
Merged
KomachiSion
merged 10 commits into
alibaba:develop
from
Maijh97:refactor_config_http_client
Jul 18, 2020
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7144c74
nacos-client module http client replace
Maijh97 c3557a7
fix code style problem
Maijh97 2e60fd0
Merge remote-tracking branch 'origin/refactor_config_http_client' int…
Maijh97 45c19b1
add HashMap initialCapacity
Maijh97 08e6754
fix code style problem
Maijh97 f1f2af0
Modify the header object, keep the original response header to avoid …
Maijh97 bed8561
fix code style problem
Maijh97 2c841f6
naming http client request exception messages output change
Maijh97 7907b98
Merge branch 'develop-upstrem' into refactor_config_http_client
Maijh97 7efc800
Merge code
Maijh97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,21 +28,20 @@ | |
import com.alibaba.nacos.client.config.http.MetricsHttpAgent; | ||
import com.alibaba.nacos.client.config.http.ServerHttpAgent; | ||
import com.alibaba.nacos.client.config.impl.ClientWorker; | ||
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult; | ||
import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor; | ||
import com.alibaba.nacos.client.config.utils.ContentUtils; | ||
import com.alibaba.nacos.client.config.utils.ParamUtils; | ||
import com.alibaba.nacos.client.utils.LogUtils; | ||
import com.alibaba.nacos.client.utils.ParamUtil; | ||
import com.alibaba.nacos.client.utils.ValidatorUtils; | ||
import com.alibaba.nacos.common.http.HttpRestResult; | ||
import com.alibaba.nacos.common.utils.StringUtils; | ||
import org.slf4j.Logger; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
|
@@ -179,37 +178,34 @@ private boolean removeConfigInner(String tenant, String dataId, String group, St | |
group = null2defaultGroup(group); | ||
ParamUtils.checkKeyParam(dataId, group); | ||
String url = Constants.CONFIG_CONTROLLER_PATH; | ||
List<String> params = new ArrayList<String>(); | ||
params.add("dataId"); | ||
params.add(dataId); | ||
params.add("group"); | ||
params.add(group); | ||
Map<String, String> params = new HashMap<String, String>(4); | ||
params.put("dataId", dataId); | ||
params.put("group", group); | ||
|
||
if (StringUtils.isNotEmpty(tenant)) { | ||
params.add("tenant"); | ||
params.add(tenant); | ||
params.put("tenant", tenant); | ||
} | ||
if (StringUtils.isNotEmpty(tag)) { | ||
params.add("tag"); | ||
params.add(tag); | ||
params.put("tag", tag); | ||
} | ||
HttpResult result = null; | ||
HttpRestResult<String> result = null; | ||
try { | ||
result = agent.httpDelete(url, null, params, encode, POST_TIMEOUT); | ||
} catch (IOException ioe) { | ||
LOGGER.warn("[remove] error, " + dataId + ", " + group + ", " + tenant + ", msg: " + ioe.toString()); | ||
} catch (Exception ex) { | ||
LOGGER.warn("[remove] error, " + dataId + ", " + group + ", " + tenant + ", msg: " + ex.toString()); | ||
return false; | ||
} | ||
if (HttpURLConnection.HTTP_OK == result.code) { | ||
|
||
if (result.ok()) { | ||
LOGGER.info("[{}] [remove] ok, dataId={}, group={}, tenant={}", agent.getName(), dataId, group, tenant); | ||
return true; | ||
} else if (HttpURLConnection.HTTP_FORBIDDEN == result.code) { | ||
} else if (HttpURLConnection.HTTP_FORBIDDEN == result.getCode()) { | ||
LOGGER.warn("[{}] [remove] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(), dataId, | ||
group, tenant, result.code, result.content); | ||
throw new NacosException(result.code, result.content); | ||
group, tenant, result.getCode(), result.getMessage()); | ||
throw new NacosException(result.getCode(), result.getMessage()); | ||
} else { | ||
LOGGER.warn("[{}] [remove] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(), dataId, | ||
group, tenant, result.code, result.content); | ||
group, tenant, result.getCode(), result.getMessage()); | ||
return false; | ||
} | ||
} | ||
|
@@ -226,54 +222,46 @@ private boolean publishConfigInner(String tenant, String dataId, String group, S | |
cr.setContent(content); | ||
configFilterChainManager.doFilter(cr, null); | ||
content = cr.getContent(); | ||
|
||
String url = Constants.CONFIG_CONTROLLER_PATH; | ||
List<String> params = new ArrayList<String>(); | ||
params.add("dataId"); | ||
params.add(dataId); | ||
params.add("group"); | ||
params.add(group); | ||
params.add("content"); | ||
params.add(content); | ||
Map<String, String> params = new HashMap<String, String>(6); | ||
params.put("dataId", dataId); | ||
params.put("group", group); | ||
params.put("content", content); | ||
if (StringUtils.isNotEmpty(tenant)) { | ||
params.add("tenant"); | ||
params.add(tenant); | ||
params.put("tenant", tenant); | ||
} | ||
if (StringUtils.isNotEmpty(appName)) { | ||
params.add("appName"); | ||
params.add(appName); | ||
params.put("appName", appName); | ||
} | ||
if (StringUtils.isNotEmpty(tag)) { | ||
params.add("tag"); | ||
params.add(tag); | ||
params.put("tag", tag); | ||
} | ||
|
||
List<String> headers = new ArrayList<String>(); | ||
Map<String, String> headers = new HashMap<String, String>(1); | ||
if (StringUtils.isNotEmpty(betaIps)) { | ||
headers.add("betaIps"); | ||
headers.add(betaIps); | ||
headers.put("betaIps", betaIps); | ||
} | ||
HttpResult result = null; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not change intend please |
||
HttpRestResult<String> result = null; | ||
try { | ||
result = agent.httpPost(url, headers, params, encode, POST_TIMEOUT); | ||
} catch (IOException ioe) { | ||
LOGGER.warn("[{}] [publish-single] exception, dataId={}, group={}, msg={}", agent.getName(), dataId, group, | ||
ioe.toString()); | ||
} catch (Exception ex) { | ||
LOGGER.warn("[{}] [publish-single] exception, dataId={}, group={}, msg={}", agent.getName(), dataId, | ||
group, ex.toString()); | ||
return false; | ||
} | ||
if (HttpURLConnection.HTTP_OK == result.code) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not change intend please |
||
if (result.ok()) { | ||
LOGGER.info("[{}] [publish-single] ok, dataId={}, group={}, tenant={}, config={}", agent.getName(), dataId, | ||
group, tenant, ContentUtils.truncateContent(content)); | ||
group, tenant, ContentUtils.truncateContent(content)); | ||
return true; | ||
} else if (HttpURLConnection.HTTP_FORBIDDEN == result.code) { | ||
} else if (HttpURLConnection.HTTP_FORBIDDEN == result.getCode()) { | ||
LOGGER.warn("[{}] [publish-single] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(), | ||
dataId, group, tenant, result.code, result.content); | ||
throw new NacosException(result.code, result.content); | ||
dataId, group, tenant, result.getCode(), result.getMessage()); | ||
throw new NacosException(result.getCode(), result.getMessage()); | ||
} else { | ||
LOGGER.warn("[{}] [publish-single] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(), | ||
dataId, group, tenant, result.code, result.content); | ||
dataId, group, tenant, result.getCode(), result.getMessage()); | ||
return false; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not change intend please