作者 crossoverJie

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

@@ -69,9 +69,13 @@ public class RouteRequestImpl implements RouteRequest { @@ -69,9 +69,13 @@ public class RouteRequestImpl implements RouteRequest {
69 .build(); 69 .build();
70 70
71 Response response = okHttpClient.newCall(request).execute() ; 71 Response response = okHttpClient.newCall(request).execute() ;
  72 + try {
72 if (!response.isSuccessful()){ 73 if (!response.isSuccessful()){
73 throw new IOException("Unexpected code " + response); 74 throw new IOException("Unexpected code " + response);
74 } 75 }
  76 + }finally {
  77 + response.body().close();
  78 + }
75 } 79 }
76 80
77 @Override 81 @Override
@@ -92,13 +96,19 @@ public class RouteRequestImpl implements RouteRequest { @@ -92,13 +96,19 @@ public class RouteRequestImpl implements RouteRequest {
92 throw new IOException("Unexpected code " + response); 96 throw new IOException("Unexpected code " + response);
93 } 97 }
94 98
95 - String json = response.body().string() ; 99 + ResponseBody body = response.body();
  100 + try {
  101 + String json = body.string() ;
96 BaseResponse baseResponse = JSON.parseObject(json, BaseResponse.class); 102 BaseResponse baseResponse = JSON.parseObject(json, BaseResponse.class);
97 103
98 //选择的账号不存在 104 //选择的账号不存在
99 if (baseResponse.getCode().equals(StatusEnum.OFF_LINE.getCode())){ 105 if (baseResponse.getCode().equals(StatusEnum.OFF_LINE.getCode())){
100 LOGGER.error(p2PReqVO.getReceiveUserId() + ":" + StatusEnum.OFF_LINE.getMessage()); 106 LOGGER.error(p2PReqVO.getReceiveUserId() + ":" + StatusEnum.OFF_LINE.getMessage());
101 } 107 }
  108 +
  109 + }finally {
  110 + body.close();
  111 + }
102 } 112 }
103 113
104 @Override 114 @Override
@@ -118,9 +128,11 @@ public class RouteRequestImpl implements RouteRequest { @@ -118,9 +128,11 @@ public class RouteRequestImpl implements RouteRequest {
118 if (!response.isSuccessful()){ 128 if (!response.isSuccessful()){
119 throw new IOException("Unexpected code " + response); 129 throw new IOException("Unexpected code " + response);
120 } 130 }
121 -  
122 - String json = response.body().string();  
123 - CIMServerResVO cimServerResVO = JSON.parseObject(json, CIMServerResVO.class); 131 + CIMServerResVO cimServerResVO ;
  132 + ResponseBody body = response.body();
  133 + try {
  134 + String json = body.string();
  135 + cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
124 136
125 //重复失败 137 //重复失败
126 if (!cimServerResVO.getCode().equals(StatusEnum.SUCCESS.getCode())){ 138 if (!cimServerResVO.getCode().equals(StatusEnum.SUCCESS.getCode())){
@@ -128,6 +140,10 @@ public class RouteRequestImpl implements RouteRequest { @@ -128,6 +140,10 @@ public class RouteRequestImpl implements RouteRequest {
128 System.exit(-1); 140 System.exit(-1);
129 } 141 }
130 142
  143 + }finally {
  144 + body.close();
  145 + }
  146 +
131 147
132 148
133 return cimServerResVO.getDataBody(); 149 return cimServerResVO.getDataBody();
@@ -150,8 +166,15 @@ public class RouteRequestImpl implements RouteRequest { @@ -150,8 +166,15 @@ public class RouteRequestImpl implements RouteRequest {
150 } 166 }
151 167
152 168
153 - String json = response.body().string() ;  
154 - OnlineUsersResVO onlineUsersResVO = JSON.parseObject(json, OnlineUsersResVO.class); 169 + ResponseBody body = response.body();
  170 + OnlineUsersResVO onlineUsersResVO ;
  171 + try {
  172 + String json = body.string() ;
  173 + onlineUsersResVO = JSON.parseObject(json, OnlineUsersResVO.class);
  174 +
  175 + }finally {
  176 + body.close();
  177 + }
155 178
156 return onlineUsersResVO.getDataBody(); 179 return onlineUsersResVO.getDataBody();
157 } 180 }
@@ -163,9 +163,13 @@ public class AccountServiceRedisImpl implements AccountService { @@ -163,9 +163,13 @@ public class AccountServiceRedisImpl implements AccountService {
163 .build(); 163 .build();
164 164
165 Response response = okHttpClient.newCall(request).execute(); 165 Response response = okHttpClient.newCall(request).execute();
  166 + try {
166 if (!response.isSuccessful()) { 167 if (!response.isSuccessful()) {
167 throw new IOException("Unexpected code " + response); 168 throw new IOException("Unexpected code " + response);
168 } 169 }
  170 + }finally {
  171 + response.body().close();
  172 + }
169 } 173 }
170 174
171 @Override 175 @Override