Skip to content

Commit

Permalink
supdev GiKIgqnO - Allow http read timeout to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Feb 29, 2016
1 parent b5adc6d commit 4f11cdb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/main/java/com/braintreegateway/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

public class Configuration {
private Environment environment;
private int readTimeout;
private Proxy proxy;
private String accessToken;
private String clientId;
private String clientSecret;
private String merchantId;
private String privateKey;
private String publicKey;
private String clientId;
private String clientSecret;
private String accessToken;
private Proxy proxy;
private static Logger logger;

static {
Expand Down Expand Up @@ -118,4 +119,12 @@ public Logger getLogger() {
public void setLogger(Logger log) {
logger = log;
}

public int getReadTimeout() {
return (readTimeout == 0) ? 60000 : readTimeout;
}

public void setReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/braintreegateway/util/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private HttpURLConnection buildConnection(RequestMethod requestMethod, String ur
connection.addRequestProperty("Accept-Encoding", "gzip");
connection.addRequestProperty("Content-Type", "application/xml");
connection.setDoOutput(true);
connection.setReadTimeout(60000);
connection.setReadTimeout(configuration.getReadTimeout());
return connection;
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/braintreegateway/unittest/ConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ public void testConfigurationIsUsingProxy() {

assertTrue(configuration.usesProxy());
}

@Test
public void testReadtimeoutDefaultsToSixtySeconds() {
Configuration configuration = new Configuration(Environment.DEVELOPMENT, "merchant_id", "integration_public_key", "integration_private_key");
assertEquals(configuration.getReadTimeout(), 60000);
}

@Test
public void testSettingReadTimeout() {
Configuration configuration = new Configuration(Environment.DEVELOPMENT, "merchant_id", "integration_public_key", "integration_private_key");
configuration.setReadTimeout(30000);
assertEquals(configuration.getReadTimeout(), 30000);
}
}

0 comments on commit 4f11cdb

Please sign in to comment.