File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
src/main/java/com/sendgrid Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -49,16 +49,20 @@ public class Client {
49
49
50
50
private CloseableHttpClient httpClient ;
51
51
private Boolean test ;
52
+ private boolean createdHttpClient ;
52
53
53
54
/**
54
55
* Constructor for using the default CloseableHttpClient.
55
56
*/
56
57
public Client () {
57
- this (false );
58
+ this .httpClient = HttpClients .createDefault ();
59
+ this .test = false ;
60
+ this .createdHttpClient = true ;
58
61
}
59
62
60
63
/**
61
- * Constructor for passing in an httpClient.
64
+ * Constructor for passing in an httpClient, typically for mocking. Passed-in httpClient will not be closed
65
+ * by this Client.
62
66
*
63
67
* @param httpClient
64
68
* an Apache CloseableHttpClient
@@ -88,6 +92,7 @@ public Client(Boolean test) {
88
92
public Client (CloseableHttpClient httpClient , Boolean test ) {
89
93
this .httpClient = httpClient ;
90
94
this .test = test ;
95
+ this .createdHttpClient = true ;
91
96
}
92
97
93
98
@@ -340,7 +345,9 @@ public Response api(Request request) throws IOException {
340
345
@ Override
341
346
public void finalize () throws Throwable {
342
347
try {
343
- this .httpClient .close ();
348
+ if (this .createdHttpClient ) {
349
+ this .httpClient .close ();
350
+ }
344
351
} catch (IOException e ) {
345
352
throw new Throwable (e .getMessage ());
346
353
} finally {
You can’t perform that action at this time.
0 commit comments