NIFI-3633 This closes #1705. Adding a try with resources so the OkHttp response is properly closed

Signed-off-by: joewitt <joewitt@apache.org>
This commit is contained in:
Joe Percivall 2017-04-26 22:23:30 -04:00 committed by joewitt
parent 726d15d1f7
commit 49a9bc88c6
1 changed files with 6 additions and 5 deletions

View File

@ -226,12 +226,13 @@ public class HttpNotificationService extends AbstractNotificationService {
final OkHttpClient httpClient = httpClientReference.get(); final OkHttpClient httpClient = httpClientReference.get();
final Call call = httpClient.newCall(request); final Call call = httpClient.newCall(request);
final Response response = call.execute(); try (final Response response = call.execute()) {
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
throw new NotificationFailedException("Failed to send Http Notification. Received an unsuccessful status code response '" + response.code() +"'. The message was '" + throw new NotificationFailedException("Failed to send Http Notification. Received an unsuccessful status code response '" + response.code() + "'. The message was '" +
response.message() + "'"); response.message() + "'");
} }
}
} catch (NotificationFailedException e){ } catch (NotificationFailedException e){
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {