@@ -158,14 +158,15 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
158
158
RequestConfig config = RequestConfig .custom ().setProxy (httpProxy ).build ();
159
159
httpGet .setConfig (config );
160
160
}
161
- CloseableHttpResponse response = getHttpclient ().execute (httpGet );
162
- String resultContent = new BasicResponseHandler ().handleResponse (response );
163
- WxError error = WxError .fromJson (resultContent );
164
- if (error .getErrorCode () != 0 ) {
165
- throw new WxErrorException (error );
161
+ try (CloseableHttpResponse response = getHttpclient ().execute (httpGet )) {
162
+ String resultContent = new BasicResponseHandler ().handleResponse (response );
163
+ WxError error = WxError .fromJson (resultContent );
164
+ if (error .getErrorCode () != 0 ) {
165
+ throw new WxErrorException (error );
166
+ }
167
+ WxAccessToken accessToken = WxAccessToken .fromJson (resultContent );
168
+ wxMpConfigStorage .updateAccessToken (accessToken .getAccessToken (), accessToken .getExpiresIn ());
166
169
}
167
- WxAccessToken accessToken = WxAccessToken .fromJson (resultContent );
168
- wxMpConfigStorage .updateAccessToken (accessToken .getAccessToken (), accessToken .getExpiresIn ());
169
170
} catch (ClientProtocolException e ) {
170
171
throw new RuntimeException (e );
171
172
} catch (IOException e ) {
@@ -851,8 +852,7 @@ public WxMpPrepayIdResult getPrepayId(final Map<String, String> parameters) {
851
852
852
853
StringEntity entity = new StringEntity (request .toString (), Consts .UTF_8 );
853
854
httpPost .setEntity (entity );
854
- try {
855
- CloseableHttpResponse response = getHttpclient ().execute (httpPost );
855
+ try (CloseableHttpResponse response = getHttpclient ().execute (httpPost )) {
856
856
String responseContent = Utf8ResponseHandler .INSTANCE .handleResponse (response );
857
857
XStream xstream = XStreamInitializer .getInstance ();
858
858
xstream .alias ("xml" , WxMpPrepayIdResult .class );
@@ -944,8 +944,7 @@ else if (outTradeNo != null && !"".equals(outTradeNo.trim()))
944
944
945
945
StringEntity entity = new StringEntity (request .toString (), Consts .UTF_8 );
946
946
httpPost .setEntity (entity );
947
- try {
948
- CloseableHttpResponse response = httpClient .execute (httpPost );
947
+ try (CloseableHttpResponse response = httpClient .execute (httpPost )) {
949
948
String responseContent = Utf8ResponseHandler .INSTANCE .handleResponse (response );
950
949
XStream xstream = XStreamInitializer .getInstance ();
951
950
xstream .alias ("xml" , WxMpPayResult .class );
@@ -1000,8 +999,7 @@ public WxRedpackResult sendRedpack(Map<String, String> parameters) throws WxErro
1000
999
1001
1000
StringEntity entity = new StringEntity (request .toString (), Consts .UTF_8 );
1002
1001
httpPost .setEntity (entity );
1003
- try {
1004
- CloseableHttpResponse response = getHttpclient ().execute (httpPost );
1002
+ try (CloseableHttpResponse response = getHttpclient ().execute (httpPost )) {
1005
1003
String responseContent = Utf8ResponseHandler .INSTANCE .handleResponse (response );
1006
1004
XStream xstream = XStreamInitializer .getInstance ();
1007
1005
xstream .processAnnotations (WxRedpackResult .class );
0 commit comments