healchow commented on code in PR #8273:
URL: https://github.com/apache/inlong/pull/8273#discussion_r1233706066
##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/http/InternalHttpSender.java:
##########
@@ -186,39 +166,33 @@ private SendResult sendByHttp(List<String> bodies, String
groupId, String stream
httpClient = constructHttpClient(timeout, timeUnit);
}
- String url = "http://" + hostInfo.getHostName() + ":" +
hostInfo.getPortNumber()
- + "/dataproxy/message";
-
+ String url = "http://" + hostInfo.getHostName() + ":" +
hostInfo.getPortNumber() + "/dataproxy/message";
httpPost = new HttpPost(url);
httpPost.setHeader(HttpHeaders.CONNECTION, "close");
httpPost.setHeader(HttpHeaders.CONTENT_TYPE,
"application/x-www-form-urlencoded");
ArrayList<BasicNameValuePair> contents = getHeaders(bodies,
groupId, streamId, dt);
- String s = URLEncodedUtils.format(contents,
StandardCharsets.UTF_8);
- logger.info("encode string is {}", s);
- httpPost.setEntity(new StringEntity(s));
+ String encodedContents = URLEncodedUtils.format(contents,
StandardCharsets.UTF_8);
+ httpPost.setEntity(new StringEntity(encodedContents));
+ logger.info("begin to post request to {}, encoded content is: {}",
url, encodedContents);
response = httpClient.execute(httpPost);
- String returnStr = EntityUtils.toString(response.getEntity());
- if (Utils.isNotBlank(returnStr) &&
response.getStatusLine().getStatusCode() == 200) {
- logger.debug("Get configure from manager is " + returnStr);
- JsonObject jsonRes =
jsonParser.parse(returnStr).getAsJsonObject();
+ String returnStr = EntityUtils.toString(response.getEntity());
+ int returnCode = response.getStatusLine().getStatusCode();
+ if (Utils.isBlank(returnStr) || HttpStatus.SC_OK != returnCode) {
Review Comment:
Use guard statements to reduce the cyclomatic complexity of the code and
improve readability.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]