Skip to content

Commit bdc409e

Browse files
committed
close http client
1 parent 06f84cc commit bdc409e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

client/src/main/java/io/split/engine/common/SplitAPI.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ private SplitAPI(SplitHttpClient httpClient, CloseableHttpClient sseHttpClient,
1919
_requestDecorator = requestDecorator;
2020
}
2121

22-
public static SplitAPI build(SplitHttpClient httpClient, CloseableHttpClient sseHttpClient, RequestDecorator requestDecorator){
22+
public static SplitAPI build(SplitHttpClient httpClient, CloseableHttpClient sseHttpClient,
23+
RequestDecorator requestDecorator) {
2324
return new SplitAPI(httpClient, sseHttpClient, requestDecorator);
2425
}
2526

@@ -31,13 +32,20 @@ public CloseableHttpClient getSseHttpClient() {
3132
return _sseHttpClient;
3233
}
3334

34-
public RequestDecorator getRequestDecorator() { return _requestDecorator; }
35+
public RequestDecorator getRequestDecorator() {
36+
return _requestDecorator;
37+
}
3538

36-
public void close(){
39+
public void close() {
40+
try {
41+
_httpClient.close();
42+
} catch (Exception e) {
43+
_log.error("Error trying to close regular http client", e);
44+
}
3745
try {
3846
_sseHttpClient.close();
39-
} catch (Exception e){
47+
} catch (Exception e) {
4048
_log.error("Error trying to close sseHttpClient", e);
4149
}
4250
}
43-
}
51+
}

client/src/main/java/io/split/service/SplitHttpClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import io.split.client.dtos.SplitHttpResponse;
55

66
import org.apache.hc.core5.http.HttpEntity;
7+
8+
import java.io.Closeable;
79
import java.io.IOException;
810
import java.net.URI;
911
import java.util.List;
1012
import java.util.Map;
1113

12-
public interface SplitHttpClient {
14+
public interface SplitHttpClient extends Closeable {
1315
/**
1416
* Wrapper for HTTP get method
1517
*

client/src/main/java/io/split/service/SplitHttpClientImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,9 @@ private void setBasicHeaders(HttpRequest request) {
140140
? _apikey.substring(_apikey.length() - 4)
141141
: _apikey);
142142
}
143+
144+
@Override
145+
public void close() throws IOException {
146+
_client.close();
147+
}
143148
}

0 commit comments

Comments
 (0)