Skip to content

Commit 5d719e6

Browse files
committed
#AI_commit# 添加了针对 MalformedChunkCodingException 的特殊处理
1 parent 1fc4d4e commit 5d719e6

File tree

2 files changed

+23
-8
lines changed
  • dss-git
    • dss-git-common/src/main/java/com.webank.wedatasphere.dss.git.common/protocol/config
    • dss-git-server/src/main/java/com/webank/wedatasphere/dss/git/utils

2 files changed

+23
-8
lines changed

dss-git/dss-git-common/src/main/java/com.webank.wedatasphere.dss.git.common/protocol/config/GitServerConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ public class GitServerConfig {
2323
public static final CommonVars<String> GIT_SEARCH_EXCLUDE_FILE = CommonVars.apply("wds.dss.server.git.search.exclude.file", ".properties,.projectmeta");
2424

2525
public static final CommonVars<String> LINKIS_MYSQL_PRI_KEY = CommonVars.apply("wds.linkis.mysql.pri.key", "abc");
26+
27+
public static final CommonVars<Boolean> GIT_USE_ENTITY_UTILS_FOR_RESPONSE = CommonVars.apply("wds.dss.git.use.entity.utils", false);
2628
}

dss-git/dss-git-server/src/main/java/com/webank/wedatasphere/dss/git/utils/DSSGitUtils.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,24 +449,34 @@ public static boolean checkIfProjectExists(String gitToken, String projectPath)
449449
public static String getUserIdByUsername(String gitUrl, String gitToken, String username) throws GitErrorException, IOException {
450450
String url = gitUrl + "/api/v4/users?username=" + username;
451451
BufferedReader in = null;
452+
boolean useEntityUtils = GitServerConfig.GIT_USE_ENTITY_UTILS_FOR_RESPONSE.getValue();
453+
452454
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
453455
HttpGet request = new HttpGet(url);
454456
request.addHeader("PRIVATE-TOKEN", gitToken);
455457

456458
try (CloseableHttpResponse response = httpClient.execute(request)) {
457459
int statusCode = response.getStatusLine().getStatusCode();
458460
if (statusCode == 200) {
459-
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
460-
String inputLine;
461-
StringBuilder content = new StringBuilder();
461+
String responseBody;
462+
463+
if (useEntityUtils) {
464+
// 使用 EntityUtils.toString() 方式读取响应
465+
responseBody = EntityUtils.toString(response.getEntity());
466+
logger.info("Response Body (using EntityUtils): " + responseBody);
467+
} else {
468+
// 保留原有的手动读取流方式
469+
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
470+
String inputLine;
471+
StringBuilder content = new StringBuilder();
462472

463-
while ((inputLine = in.readLine()) != null) {
464-
content.append(inputLine);
473+
while ((inputLine = in.readLine()) != null) {
474+
content.append(inputLine);
475+
}
476+
responseBody = content.toString();
477+
logger.info("Response Body (using manual stream reading): " + responseBody);
465478
}
466479

467-
String responseBody = content.toString();
468-
logger.info("Response Body: " + responseBody);
469-
470480
JsonArray jsonArray = JsonParser.parseString(responseBody).getAsJsonArray();
471481

472482
if (jsonArray.size() > 0) {
@@ -479,6 +489,9 @@ public static String getUserIdByUsername(String gitUrl, String gitToken, String
479489
throw new GitErrorException(80109, "获取userId失败,请检查编辑用户token是否过期或git服务是否正常");
480490
}
481491
}
492+
} catch (org.apache.http.MalformedChunkCodingException e) {
493+
logger.error("HTTP chunked transfer encoding error: " + e.getMessage(), e);
494+
throw new GitErrorException(80109, "HTTP响应解析错误,服务器返回的分块数据格式不正确", e);
482495
} catch (Exception e) {
483496
throw new GitErrorException(80109, "获取该git用户Id失败,原因为", e);
484497
} finally {

0 commit comments

Comments
 (0)