作者 crossoverJie

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

... ... @@ -69,9 +69,13 @@ public class RouteRequestImpl implements RouteRequest {
.build();
Response response = okHttpClient.newCall(request).execute() ;
try {
if (!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
}
}finally {
response.body().close();
}
}
@Override
... ... @@ -92,13 +96,19 @@ public class RouteRequestImpl implements RouteRequest {
throw new IOException("Unexpected code " + response);
}
String json = response.body().string() ;
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());
}
}finally {
body.close();
}
}
@Override
... ... @@ -118,9 +128,11 @@ 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);
CIMServerResVO cimServerResVO ;
ResponseBody body = response.body();
try {
String json = body.string();
cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
//重复失败
if (!cimServerResVO.getCode().equals(StatusEnum.SUCCESS.getCode())){
... ... @@ -128,6 +140,10 @@ public class RouteRequestImpl implements RouteRequest {
System.exit(-1);
}
}finally {
body.close();
}
return cimServerResVO.getDataBody();
... ... @@ -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,9 +163,13 @@ public class AccountServiceRedisImpl implements AccountService {
.build();
Response response = okHttpClient.newCall(request).execute();
try {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
}finally {
response.body().close();
}
}
@Override
... ...