gosonzhang commented on code in PR #8273:
URL: https://github.com/apache/inlong/pull/8273#discussion_r1234677627


##########
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) {
+                throw new Exception("get config from manager failed, result: " 
+ returnStr + ", code: " + returnCode);
+            }
 
-                if (jsonRes.has("code")) {
-                    int code = jsonRes.get("code").getAsInt();
-                    if (code == 1) {
-                        return SendResult.OK;
-                    } else {
-                        logger.debug("get error response {}", returnStr);
-                        return SendResult.INVALID_DATA;
-                    }
+            logger.debug("success to get config from manager, result str: " + 
returnStr);
+            JsonObject jsonResponse = 
JsonParser.parseString(returnStr).getAsJsonObject();
+            JsonElement codeElement = jsonResponse.get("code");
+            if (codeElement != null) {
+                if (ConfigConstants.HTTP_RESPONSE_CODE_SUCCESS == 
codeElement.getAsInt()) {
+                    return SendResult.OK;
+                } else {
+                    return SendResult.INVALID_DATA;

Review Comment:
   There is a problem here. The error information converges to INVALID_DATA. 
How can the user obtain the specific cause of the error and how to solve this 
problem?



-- 
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]

Reply via email to