Skip to content

Commit ed103df

Browse files
adding request timeout to SocketLabsClient and HttpRequest.
SocketLabsClient has set method to overide the default of 100s.
1 parent feb0f9c commit ed103df

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

injectionApi/src/main/java/com/socketLabs/injectionApi/SocketLabsClient.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class SocketLabsClient implements SocketLabsClientAPI {
1515
private String apiKey;
1616
private String endPointUrl = "https://inject.socketlabs.com/api/v1/email";
1717
private Proxy proxy;
18+
private int requestTimeout = 100;
1819

1920
/**
2021
* Set the SocketLabs Injection API endpoint Url
@@ -24,6 +25,12 @@ public void setEndPointUrl(String value) {
2425
this.endPointUrl = value;
2526
}
2627

28+
/**
29+
* Set the Timeout period used by the HttpClient (in seconds)
30+
* @param value int
31+
*/
32+
public void setRequestTimeout(int value) { this.requestTimeout = value; }
33+
2734
private final String VERSION = "1.0.0";
2835
private final String userAgent = String.format("SocketLabs-java/%s(%s)", VERSION, Package.getPackage("java.util").getImplementationVersion());
2936

@@ -36,6 +43,7 @@ public SocketLabsClient(int serverId, String apiKey) {
3643
this.serverId = serverId;
3744
this.apiKey = apiKey;
3845
}
46+
3947
/**
4048
*
4149
* Creates a new instance of the SocketLabsClient.
@@ -159,7 +167,7 @@ private SendResponse Validate(BulkMessage message) {
159167

160168
private HttpRequest buildHttpRequest(Proxy optionalProxy) {
161169

162-
HttpRequest request = new HttpRequest(HttpRequest.HttpRequestMethod.POST, this.endPointUrl);
170+
HttpRequest request = new HttpRequest(HttpRequest.HttpRequestMethod.POST, this.endPointUrl, this.requestTimeout);
163171

164172
request.setHeader("User-Agent", this.userAgent);
165173
request.setHeader("content-type", "application/json");

injectionApi/src/main/java/com/socketLabs/injectionApi/core/HttpRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ public enum HttpRequestMethod {
3535
private Proxy proxy;
3636
/** The headers to add to the HTTP Request */
3737
private Map<String, String> headers = new HashMap<>();
38+
private int timeout;
39+
3840

3941
/**
4042
* Creates a new instance of the HTTP Request class
4143
* @param method HTTpRequestMethod
4244
* @param endPointUrl String
4345
*/
44-
public HttpRequest(HttpRequestMethod method, String endPointUrl) {
46+
public HttpRequest(HttpRequestMethod method, String endPointUrl, int timeout) {
4547
this.method = method;
4648
this.endPointUrl = endPointUrl;
49+
this.timeout = timeout;
4750
}
4851

4952
/**
@@ -124,6 +127,7 @@ private Call BuildClientCall() {
124127

125128
if (this.proxy != null)
126129
client = new OkHttpClient.Builder()
130+
.callTimeout(this.timeout, TimeUnit.SECONDS)
127131
.proxy(this.proxy)
128132
.build();
129133

0 commit comments

Comments
 (0)