Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.fasterxml.jackson.core:jackson-core:2.11.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.11.0'
compile group: 'com.socketlabs', name: 'injectionApi', version: '1.1.0'
compile group: 'com.socketlabs', name: 'injectionApi', version: '1.1.1'
}
2 changes: 1 addition & 1 deletion injectionApi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
def baseGroupId = "com.socketlabs"
def baseArtifactId = 'injectionApi'
def computeVersion() {
def baseVersion = "1.1.0"
def baseVersion = "1.1.1"
def release = true
if (release)
return "${baseVersion}"
Expand Down
2 changes: 1 addition & 1 deletion injectionApi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.socketlabs</groupId>
<artifactId>injectionApi</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<name>socketlabs-java</name>
<description>SocketLabs Email Delivery Java library</description>
<url>https://github.com/socketlabs/socketlabs-java/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class SocketLabsClient implements SocketLabsClientAPI {
private String apiKey;
private String endPointUrl = "https://inject.socketlabs.com/api/v1/email";
private Proxy proxy;
private int requestTimeout = 100;

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

/**
* Set the Timeout period used by the HttpClient (in seconds)
* @param value int
*/
public void setRequestTimeout(int value) { this.requestTimeout = value; }

private final String VERSION = "1.0.0";
private final String userAgent = String.format("SocketLabs-java/%s(%s)", VERSION, Package.getPackage("java.util").getImplementationVersion());

Expand All @@ -36,6 +43,7 @@ public SocketLabsClient(int serverId, String apiKey) {
this.serverId = serverId;
this.apiKey = apiKey;
}

/**
*
* Creates a new instance of the SocketLabsClient.
Expand Down Expand Up @@ -159,7 +167,7 @@ private SendResponse Validate(BulkMessage message) {

private HttpRequest buildHttpRequest(Proxy optionalProxy) {

HttpRequest request = new HttpRequest(HttpRequest.HttpRequestMethod.POST, this.endPointUrl);
HttpRequest request = new HttpRequest(HttpRequest.HttpRequestMethod.POST, this.endPointUrl, this.requestTimeout);

request.setHeader("User-Agent", this.userAgent);
request.setHeader("content-type", "application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import okhttp3.*;
import okhttp3.Request.Builder;


import java.io.*;
import java.net.Proxy;
import java.util.concurrent.TimeUnit;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -35,15 +37,18 @@ public enum HttpRequestMethod {
private Proxy proxy;
/** The headers to add to the HTTP Request */
private Map<String, String> headers = new HashMap<>();
private int timeout;


/**
* Creates a new instance of the HTTP Request class
* @param method HTTpRequestMethod
* @param endPointUrl String
*/
public HttpRequest(HttpRequestMethod method, String endPointUrl) {
public HttpRequest(HttpRequestMethod method, String endPointUrl, int timeout) {
this.method = method;
this.endPointUrl = endPointUrl;
this.timeout = timeout;
}

/**
Expand Down Expand Up @@ -114,16 +119,23 @@ public void onFailure(Call call, IOException ex) {

}


/**
* Build the HTTP Client call
* @return Call
*/
private Call BuildClientCall() {

OkHttpClient client = new OkHttpClient();
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
.connectTimeout(this.timeout, TimeUnit.SECONDS)
.writeTimeout(this.timeout, TimeUnit.SECONDS)
.readTimeout(this.timeout, TimeUnit.SECONDS)
.callTimeout(this.timeout, TimeUnit.SECONDS);

OkHttpClient client = clientBuilder.build();

if (this.proxy != null)
client = new OkHttpClient.Builder()
client = clientBuilder
.proxy(this.proxy)
.build();

Expand Down