作者 crossoverJie

:bug: Fixing a bug.修复 okhttp 没关闭body

... ... @@ -69,8 +69,12 @@ public class RouteRequestImpl implements RouteRequest {
.build();
Response response = okHttpClient.newCall(request).execute() ;
if (!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
try {
if (!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
}
}finally {
response.body().close();
}
}
... ... @@ -92,12 +96,18 @@ public class RouteRequestImpl implements RouteRequest {
throw new IOException("Unexpected code " + response);
}
String json = response.body().string() ;
BaseResponse baseResponse = JSON.parseObject(json, BaseResponse.class);
ResponseBody body = response.body();
try {
String json = body.string() ;
BaseResponse baseResponse = JSON.parseObject(json, BaseResponse.class);
//选择的账号不存在
if (baseResponse.getCode().equals(StatusEnum.OFF_LINE.getCode())){
LOGGER.error(p2PReqVO.getReceiveUserId() + ":" + StatusEnum.OFF_LINE.getMessage());
//选择的账号不存在
if (baseResponse.getCode().equals(StatusEnum.OFF_LINE.getCode())){
LOGGER.error(p2PReqVO.getReceiveUserId() + ":" + StatusEnum.OFF_LINE.getMessage());
}
}finally {
body.close();
}
}
... ... @@ -118,14 +128,20 @@ public class RouteRequestImpl implements RouteRequest {
if (!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
}
String json = response.body().string();
CIMServerResVO cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
//重复失败
if (!cimServerResVO.getCode().equals(StatusEnum.SUCCESS.getCode())){
LOGGER.error(appConfiguration.getUserName() + ":" + cimServerResVO.getMessage());
System.exit(-1);
CIMServerResVO cimServerResVO ;
ResponseBody body = response.body();
try {
String json = body.string();
cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
//重复失败
if (!cimServerResVO.getCode().equals(StatusEnum.SUCCESS.getCode())){
LOGGER.error(appConfiguration.getUserName() + ":" + cimServerResVO.getMessage());
System.exit(-1);
}
}finally {
body.close();
}
... ... @@ -150,8 +166,15 @@ public class RouteRequestImpl implements RouteRequest {
}
String json = response.body().string() ;
OnlineUsersResVO onlineUsersResVO = JSON.parseObject(json, OnlineUsersResVO.class);
ResponseBody body = response.body();
OnlineUsersResVO onlineUsersResVO ;
try {
String json = body.string() ;
onlineUsersResVO = JSON.parseObject(json, OnlineUsersResVO.class);
}finally {
body.close();
}
return onlineUsersResVO.getDataBody();
}
... ...
... ... @@ -163,8 +163,12 @@ public class AccountServiceRedisImpl implements AccountService {
.build();
Response response = okHttpClient.newCall(request).execute();
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
try {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
}finally {
response.body().close();
}
}
... ...