Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the abilty to set a connection timeout separate from socket timeout #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Add the abilty to set a connection timeout separate from socket timeout
  • Loading branch information
Jaie Wilson committed Mar 30, 2017
commit 36fdd452404f27f687583821ec70f9911df5e766
Original file line number Diff line number Diff line change
@@ -48,10 +48,9 @@ public static boolean getDefaultUseHttpClient() {
* @param con
* @param timeout
*/
public static void setTimeout(HttpURLConnection con, int timeout) {
int timeoutInMS = timeout * 1000;
con.setConnectTimeout(timeoutInMS);
con.setReadTimeout(timeoutInMS);
public static void setTimeout(HttpURLConnection con, int connectionTimeout, int timeout) {
con.setConnectTimeout(connectionTimeout * 1000);
con.setReadTimeout(timeout * 1000);
}

/**
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ void postDocument(Document request)
TransformerException, MalformedURLException,
ProtocolException {
HttpClient httpClient = new HttpClient();
setTimeout(httpClient, mc.getTimeout() * 1000);
setTimeout(httpClient, mc.getConnectionTimeout() * 1000, mc.getTimeout() * 1000);
setProxy(httpClient);

String serverURL = mc.getEffectiveServerURL();
@@ -126,10 +126,10 @@ InputStream getResponseErrorStream()
* @param httpClient
* @param timeoutInMs
*/
private void setTimeout(HttpClient httpClient, int timeoutInMs) {
private void setTimeout(HttpClient httpClient, int connectionTimeoutInMs, int timeoutInMs) {
HttpConnectionManagerParams params
= httpClient.getHttpConnectionManager().getParams();
params.setConnectionTimeout(timeoutInMs);
params.setConnectionTimeout(connectionTimeoutInMs);
params.setSoTimeout(timeoutInMs);
}

Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ void postDocument(Document request)
con = ConnectionHelper.openConnection(url, mc);
con.setRequestMethod("POST");
con.setDoOutput(true);
ConnectionHelper.setTimeout(con, mc.getTimeout());
ConnectionHelper.setTimeout(con, mc.getConnectionTimeout(), mc.getTimeout());

OutputStream out = con.getOutputStream();
byte[] requestBytes = documentToByteArray(request);
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ public class MerchantConfig {
private int logMaximumSize;
private boolean useHttpClient;
private int timeout;
private int connectionTimeout;
private String proxyHost;
private int proxyPort;
private String proxyUser;
@@ -157,6 +158,8 @@ public int getTimeout() {
return timeout;
}

public int getConnectionTimeout() { return connectionTimeout; }

public String getProxyHost() {
return proxyHost;
}
@@ -253,6 +256,7 @@ public MerchantConfig(Properties _props, String _merchantID)
useHttpClient = getBooleanProperty(merchantID, "useHttpClient", ConnectionHelper.getDefaultUseHttpClient());

timeout = getIntegerProperty(merchantID, "timeout", DEFAULT_TIMEOUT);
connectionTimeout = getIntegerProperty(merchantID, "connectionTimeout", timeout);
proxyHost = getProperty(merchantID, "proxyHost");
proxyPort = getIntegerProperty(merchantID, "proxyPort", DEFAULT_PROXY_PORT);
proxyUser = getProperty(merchantID, "proxyUser");
@@ -467,6 +471,7 @@ public String getLogString() {
appendPair(sb, "RetryInterval", retryInterval);
}
appendPair(sb, "timeout", timeout);
appendPair(sb, "connectionTimeout", connectionTimeout);
if (proxyHost != null) {
appendPair(sb, "proxyHost", proxyHost);
appendPair(sb, "proxyPort", proxyPort);
6 changes: 5 additions & 1 deletion java/src/main/resources/cybs.properties
Original file line number Diff line number Diff line change
@@ -28,7 +28,11 @@ retryInterval=5
# Mechanism to differentiate whether Payload is encrypted or not
useSignAndEncrypted=<-- Set it to true for MLE[MessageLevelEncryption] -->

timeout=1000
# Timeout is in seconds
timeout=20

# connection timeout if not present will default to timeout above.
connectionTimeout=5

# logging should normally be disabled in production as it would slow down the
# processing. Enable it only when troubleshooting an issue.
3 changes: 2 additions & 1 deletion java/src/test/resources/test_cybs.properties
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@ retryInterval=5
# Mechanism to differentiate whether Payload is encrypted or not
useSignAndEncrypted=false

timeout=1000
timeout=100
connectionTimeout=100

# logging should normally be disabled in production as it would slow down the
# processing. Enable it only when troubleshooting an issue.
3 changes: 2 additions & 1 deletion samples/nvp/cybs.properties
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@ retryInterval=5
# Mechanism to differentiate whether Payload is encrypted or not
useSignAndEncrypted=false

timeout=1000
timeout=100
connectionTimeout=100

# logging should normally be disabled in production as it would slow down the
# processing. Enable it only when troubleshooting an issue.
4 changes: 3 additions & 1 deletion samples/xml/cybs.properties
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ keyAlias=
keyPassword=
targetAPIVersion=1.129


# the following flags can be used to control the endpoint to which requests will be sent.
# Set sendToProduction=true to send requests to Cybersource production environment.
# Set sendToAkamai=true to send requests through Akamai to Cybersource.
@@ -28,7 +29,8 @@ retryInterval=5
# Mechanism to differentiate whether payload is encrypted or not
useSignAndEncrypted=false

timeout=1000
timeout=100
connectionTimeout=100

# logging should normally be disabled in production as it would slow down the
# processing. Enable it only when troubleshooting an issue.