Browse Source

fix potential resource leak

master
BinaryWang 8 years ago
parent
commit
d17f11341d
1 changed files with 2 additions and 3 deletions
  1. +2
    -3
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java

+ 2
- 3
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java View File

@@ -46,7 +46,8 @@ public class QrCodeRequestExecutor implements RequestExecutor<File, WxMpQrCodeTi
httpGet.setConfig(config); httpGet.setConfig(config);
} }


try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
try (CloseableHttpResponse response = httpclient.execute(httpGet);
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
Header[] contentTypeHeader = response.getHeaders("Content-Type"); Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0) { if (contentTypeHeader != null && contentTypeHeader.length > 0) {
// 出错 // 出错
@@ -55,8 +56,6 @@ public class QrCodeRequestExecutor implements RequestExecutor<File, WxMpQrCodeTi
throw new WxErrorException(WxError.fromJson(responseContent)); throw new WxErrorException(WxError.fromJson(responseContent));
} }
} }
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);

return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg"); return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
} finally { } finally {
httpGet.releaseConnection(); httpGet.releaseConnection();


Loading…
Cancel
Save